[PATCH] pwclient: add option to print statistics, similar to 'list' or 'search'.

Arnout Vandecappelle (Essensium/Mind) arnout at mind.be
Wed Feb 19 22:04:36 EST 2014


This option makes it possible to gather statistics about pending, accepted,
etc. patches.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout at mind.be>
---
v2: missing () in the format arguments
---
 apps/patchwork/bin/pwclient | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient
index 0c0ccaf..2d1fbf6 100755
--- a/apps/patchwork/bin/pwclient
+++ b/apps/patchwork/bin/pwclient
@@ -120,6 +120,7 @@ def usage():
                         below and an optional substring to search for patches
                         by name
         search [str]  : Same as 'list'
+        stats [str]   : Like 'list', but only print number of patches per state
         view <ID>     : View a patch
         update [-s state] [-c commit-ref] <ID>
                       : Update patch\n""")
@@ -170,7 +171,16 @@ def list_patches(patches):
     for patch in patches:
         print("%-7d %-12s %s" % (patch['id'], patch['state'], patch['name']))
 
-def action_list(rpc, filter, submitter_str, delegate_str):
+def stats_patches(patches):
+    """Summarize a list of patches to stdout."""
+    statemap = {}
+    for patch in patches:
+        statecnt = statemap.get(patch['state'], 0)
+        statemap[patch['state']] = statecnt + 1
+    for state, statecnt in statemap.items():
+        print("%-12s: %d" % (state, statecnt))
+
+def action_list(rpc, filter, submitter_str, delegate_str, print_cb):
     filter.resolve_ids(rpc)
 
     if submitter_str != "":
@@ -187,7 +197,7 @@ def action_list(rpc, filter, submitter_str, delegate_str):
                 f = filter
                 f.add("submitter_id", id)
                 patches = rpc.patch_list(f.d)
-                list_patches(patches)
+                print_cb(patches)
         return
 
     if delegate_str != "":
@@ -203,11 +213,11 @@ def action_list(rpc, filter, submitter_str, delegate_str):
                 f = filter
                 f.add("delegate_id", id)
                 patches = rpc.patch_list(f.d)
-                list_patches(patches)
+                print_cb(patches)
         return
 
     patches = rpc.patch_list(filter.d)
-    list_patches(patches)
+    print_cb(patches)
 
 def action_projects(rpc):
     projects = rpc.project_list("", 0)
@@ -430,10 +440,14 @@ def main():
             sys.exit(1)
 
 
-    if action == 'list' or action == 'search':
+    if action in ('list', 'search', 'stats'):
         if len(args) > 0:
             filt.add("name__icontains", args[0])
-        action_list(rpc, filt, submitter_str, delegate_str)
+        if action == 'stats':
+            print_cb = stats_patches
+        else:
+            print_cb = list_patches
+        action_list(rpc, filt, submitter_str, delegate_str, print_cb)
 
     elif action.startswith('project'):
         action_projects(rpc)
-- 
1.9.rc1



More information about the Patchwork mailing list