From patchwork Wed Feb 19 11:04:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnout Vandecappelle X-Patchwork-Id: 321833 X-Patchwork-Delegate: stephen.finucane@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 012E02C00E8 for ; Wed, 19 Feb 2014 22:05:43 +1100 (EST) Received: from viper.mind.be (132.79-246-81.adsl-static.isp.belgacom.be [81.246.79.132]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C9E9F2C00C4 for ; Wed, 19 Feb 2014 22:05:37 +1100 (EST) Received: from [172.16.2.6] (helo=vandecaa-laptop) by viper.mind.be with esmtp (Exim 4.69) (envelope-from ) id 1WG52R-0007Yc-Cc; Wed, 19 Feb 2014 12:10:03 +0100 Received: from arnout by vandecaa-laptop with local (Exim 4.82) (envelope-from ) id 1WG4xN-0005qS-Uw; Wed, 19 Feb 2014 12:04:50 +0100 From: "Arnout Vandecappelle (Essensium/Mind)" To: patchwork@lists.ozlabs.org Subject: [PATCH] pwclient: add option to print statistics, similar to 'list' or 'search'. Date: Wed, 19 Feb 2014 12:04:36 +0100 Message-Id: <1392807876-22430-1-git-send-email-arnout@mind.be> X-Mailer: git-send-email 1.9.rc1 In-Reply-To: <1392753779-2823-1-git-send-email-arnout@mind.be> References: <1392753779-2823-1-git-send-email-arnout@mind.be> Cc: Thomas Petazzoni X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This option makes it possible to gather statistics about pending, accepted, etc. patches. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) --- 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 : View a patch update [-s state] [-c commit-ref] : 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)