commit ef64989bdd86d71e5ea309ec9cbf770e7df4eb49 Author: Pierre-Yves Chibon pingou@pingoured.fr Date: Fri Oct 10 12:44:52 2014 +0200
Create the action2msg method converting an action's JSON into a human-readable string
pkgdb2client/admin.py | 101 ++++++++++++++++++++++++++---------------------- 1 files changed, 55 insertions(+), 46 deletions(-) --- diff --git a/pkgdb2client/admin.py b/pkgdb2client/admin.py index 3e675ca..aa16a39 100644 --- a/pkgdb2client/admin.py +++ b/pkgdb2client/admin.py @@ -106,6 +106,60 @@ def setup_parser(): return parser
+def _action2msg(action): + ''' Convert a given action dictionnary into a human-readable sentence. + + ''' + if action['action'] == 'request.package': + msg = '#%(id)s (%(status)s) - %(user)s requested the new package '\ + '"%(pkg)s" on "%(clt)s"' % ( + { + 'id': action['id'], + 'status': action['status'], + 'user': action['user'], + 'pkg': action['info']['pkg_name'], + 'clt': action['info']['pkg_collection'], + } + ) + + elif action['action'] == 'request.branch': + msg = '#%(id)s (%(status)s) - %(user)s requested a new branch '\ + '"%(clt)s" for "%(pkg)s"' % ( + { + 'id': action['id'], + 'status': action['status'], + 'user': action['user'], + 'pkg': action['package']['name'], + 'clt': action['collection']['branchname'], + } + ) + + elif action['action'] == 'request.unretire': + msg = '#%(id)s (%(status)s) - %(user)s requested the ' \ + 'unretirement of "%(pkg)s" on "%(clt)s"' % ( + { + 'id': action['id'], + 'status': action['status'], + 'user': action['user'], + 'pkg': action['package']['name'], + 'clt': action['collection']['branchname'], + } + ) + + else: + msg = '#%(id)s (%(status)s) - %(action)s by %(user)s is not '\ + 'handled by pkgdb-admin' % ( + { + 'id': action['id'], + 'status': action['status'], + 'action': action['action'], + 'user': action['user'], + } + ) + + return msg + + def do_list(args): ''' Retrieve the list of admin actions pending in pkgdb.
@@ -128,52 +182,7 @@ def do_list(args): data = pkgdbclient.handle_api_call('/admin/actions/', params=data)
for cnt, action in enumerate(data['actions']): - if action['action'] == 'request.package': - print '#%(id)s (%(status)s) - %(user)s requested the new package '\ - '"%(pkg)s" on "%(clt)s"' % ( - { - 'id': action['id'], - 'status': action['status'], - 'user': action['user'], - 'pkg': action['info']['pkg_name'], - 'clt': action['info']['pkg_collection'], - } - ) - - elif action['action'] == 'request.branch': - print '#%(id)s (%(status)s) - %(user)s requested a new branch '\ - '"%(clt)s" for "%(pkg)s"' % ( - { - 'id': action['id'], - 'status': action['status'], - 'user': action['user'], - 'pkg': action['package']['name'], - 'clt': action['collection']['branchname'], - } - ) - - elif action['action'] == 'request.unretire': - print '#%(id)s (%(status)s) - %(user)s requested the ' \ - 'unretirement of "%(pkg)s" on "%(clt)s"' % ( - { - 'id': action['id'], - 'status': action['status'], - 'user': action['user'], - 'pkg': action['package']['name'], - 'clt': action['collection']['branchname'], - } - ) - - else: - print '#%(id)s (%(status)s) - %(action)s by %(user)s is not '\ - 'handled by pkgdb-admin' % ( - { - 'id': action['id'], - 'status': action['status'], - 'action': action['action'], - 'user': action['user'], - } - ) + print _action2msg(action)
print 'Total: {0} actions'.format(cnt + 1)
packagedb-cli-commits@lists.stg.fedorahosted.org