Patchwork pwclient: add option to print statistics, similar to 'list' or 'search'.

login
register
mail settings
Submitter Arnout Vandecappelle
Date Feb. 18, 2014, 8:02 p.m.
Message ID <1392753779-2823-1-git-send-email-arnout@mind.be>
Download mbox | patch
Permalink /patch/321630/
State New
Headers show

Comments

Arnout Vandecappelle - Feb. 18, 2014, 8:02 p.m.
This option makes it possible to gather statistics about pending, accepted,
etc. patches.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
 apps/patchwork/bin/pwclient | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
Thomas Petazzoni - Feb. 18, 2014, 11:02 p.m.
Dear Arnout Vandecappelle,

On Tue, 18 Feb 2014 21:02:59 +0100, Arnout Vandecappelle
(Essensium/Mind) wrote:

> +    for state, statecnt in statemap.items():
> +        print("%-12s: %d" % state, statecnt)

This line doesn't work here. It should be:

	print("%-12s: %d" % (state, statecnt))

Thomas

Patch

diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient
index 0c0ccaf..c6ea637 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)