--- a/hggravatar.py Thu Dec 20 01:44:41 2018 -0600
+++ b/hggravatar.py Wed Oct 07 03:15:45 2020 -0500
@@ -7,6 +7,8 @@
+from collections import namedtuple from mercurial.i18n import _
@@ -17,7 +19,7 @@
from mercurial.utils import stringutil
-_CACHE_DIR = '.hg/cache/gravatar'
+_CACHE_DIR = b'.hg/cache/gravatar' urlencode = urlreq.urlencode
@@ -25,25 +27,29 @@
command = registrar.command(cmdtable)
def find_authors(ui, repo, *pats, **opts):
- ui.write('caching authors ... ')
+ ui.write(b'caching authors ... ') m = scmutil.match(repo[None], pats, opts)
- """callback for cmdutil.walkchangerevs that just adds unique email
- address to the authors dict."""
- email = stringutil.email(ctx.user())
- normalized = email.lower().strip()
- if not email in authors:
- authors[email] = hashlib.md5(normalized).hexdigest()
+ """callback for cmdutil.walkchangerevs that just adds unique email + address to the authors dict.""" + email = stringutil.email(ctx.user()).lower().strip() + if not email in authors: + c = namedtuple('Contributor', 'username email gravatar_id') + c.username = stringutil.person(ctx.user()) + c.gravatar_id = hashlib.md5(email).hexdigest().encode('UTF-8') for ctx in cmdutil.walkchangerevs(repo, m, opts, prep):
- # we handle everything in the callback closure so nothing to do here
+ # we handle everything in the callback closure so nothing to do here path = os.path.join(repo.root, _CACHE_DIR)
@@ -53,11 +59,11 @@
if err.errno != errno.EEXIST:
- map_file = os.path.join(path, 'author_map')
- with open(map_file, 'w') as ofp:
- json.dump(authors, ofp, indent=2)
+# map_file = os.path.join(path, 'author_map') +# with open(map_file, 'w') as ofp: +# json.dump(authors, ofp, indent=2)
@@ -84,36 +90,36 @@
- for author, key in authors.items():
- ui.write('downloading image for %s ... ' % author)
+ for _, author in authors.items(): + ui.write(b'downloading image for %s ... ' % author.username) - filename = '%s.png' % key
+ filename = b'%s.png' % author.username - uri = os.path.join(url, filename)
+ uri = os.path.join(url, b'%s.png' % author.gravatar_id) - img = urlreq.urlopen(uri)
+ img = urlreq.urlopen(uri.decode('UTF-8'))
- with open(os.path.join(repo.root, _CACHE_DIR, filename), 'w') as ofp:
+ with open(os.path.join(repo.root, _CACHE_DIR, filename), 'wb') as ofp:
def validate_arguments(**opts):
rating = opts.get('rating')
- valid = ['g', 'pg', 'r', 'x']
+ valid = [b'g', b'pg', b'r', b'x'] if rating != '' and not rating in valid:
raise error.Abort(_('invalid rating %s, accepted values are %s' % (rating, ', '.join(valid))))
@@ -122,18 +128,18 @@
raise error.Abort(_('invalid size %s, it is not an integer between 1 and 2048' % size))
theme = opts.get('theme')
- valid = ['404', 'mp', 'identicon', 'monsterid', 'wavatar', 'retro', 'robohash', 'blank']
+ valid = [b'404', b'mp', b'identicon', b'monsterid', b'wavatar', b'retro', b'robohash', b'blank'] if theme != '' and not theme in valid:
raise error.Abort(_('invalid theme %s, accepted values are %s' % (theme, ', '.join(valid))))
- ('r', 'rating', '', _('rating'), _('RATING')),
- ('s', 'size', '', _('size'), _('SIZE')),
- ('t', 'theme', '', _('theme'), _('THEME')),
- ('u', 'url', 'https://www.gravatar.com/avatar', _('gravatar url'), _('URL')),
+ (b'c', b'clean', b'', _('clean the cache'), None), + (b'r', b'rating', b'pg', _('minimum rating'), _('RATING')), + (b's', b'size', b'128', _('size of the images'), _('SIZE')), + (b't', b'theme', b'identicon', _('the theme to use'), _('THEME')), + (b'u', b'url', b'https://www.gravatar.com/avatar', _('the gravatar url'), _('URL')), _("hg gravatar [-u URL] [-o DIR]"),