--- a/hggravatar.py Thu Dec 20 00:03:27 2018 -0600
+++ b/hggravatar.py Thu Dec 20 01:21:31 2018 -0600
@@ -9,6 +9,7 @@
from mercurial.i18n import _
@@ -16,6 +17,7 @@
from mercurial.utils import stringutil
+urlencode = urlreq.urlencode command = registrar.command(cmdtable)
@@ -61,14 +63,37 @@
+ rating = opts.get('rating') + size = opts.get('size') + theme = opts.get('theme') for author, key in authors.items():
ui.write('downloading image for %s ... ' % author)
filename = '%s.png' % key
uri = os.path.join(url, filename)
img = urlreq.urlopen(uri)
+ if img.getcode() != 200: with open(os.path.join(opts.get('output'), filename), 'w') as ofp:
@@ -76,16 +101,42 @@
+def validate_arguments(**opts): + rating = opts.get('rating') + valid = ['g', 'pg', 'r', 'x'] + if rating != '' and not rating in valid: + raise error.Abort(_('invalid rating %s, accepted values are %s' % (rating, ', '.join(valid)))) + size = opts.get('size') + if sz < 1 or sz > 2048: + raise error.Abort(_('invalid size %d, it much be between 1 and 2048' % sz)) + 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'] + if theme != '' and not theme in valid: + raise error.Abort(_('invalid theme %s, accepted values are %s' % (theme, ', '.join(valid)))) ('o', 'output', '.hg/cache/gravatar/', _('output directory'), _('DIR')),
+ ('r', 'rating', '', _('rating'), _('RATING')), + ('s', 'size', '', _('size'), _('SIZE')), + ('t', 'theme', '', _('theme'), _('THEME')), ('u', 'url', 'https://www.gravatar.com/avatar', _('gravatar url'), _('URL')),
_("hg gravatar [-u URL] [-o DIR]"),
def gravatar(ui, repo, *pats, **opts):
+ validate_arguments(**opts) authors = find_authors(ui, repo, *pats, **opts)
save_avatars(ui, repo, authors, *pats, **opts)