From patchwork Fri Aug 29 12:02:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 384195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EB166140107 for ; Fri, 29 Aug 2014 22:02:20 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id D39AA1A012A for ; Fri, 29 Aug 2014 22:02:20 +1000 (EST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from grace.univie.ac.at (grace.univie.ac.at [IPv6:2001:62a:4:25::25:115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id D62AE1A007F for ; Fri, 29 Aug 2014 22:02:17 +1000 (EST) Received: from jarvis.univie.ac.at ([131.130.3.112] helo=jarvis.univie.ac.at) by grace.univie.ac.at with esmtp (Exim 4.84) (envelope-from ) id 1XNKse-0004Qw-0T; Fri, 29 Aug 2014 14:02:12 +0200 Received: from [2001:62a:4:203:2e59:e5ff:feb9:72ed] (helo=nbbrfq.loc) by jarvis.univie.ac.at with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.82) (envelope-from ) id 1XNKsd-000474-Ul; Fri, 29 Aug 2014 14:02:11 +0200 Received: from b by nbbrfq.loc with local (Exim 4.84_RC2) (envelope-from ) id 1XNKsd-0005Db-MD; Fri, 29 Aug 2014 14:02:11 +0200 From: Bernhard Reutner-Fischer To: jk@ozlabs.org Subject: [PATCH 6/n] pwclient: diagnose hash_parser errors gracefully Date: Fri, 29 Aug 2014 14:02:08 +0200 Message-Id: <1409313728-20022-1-git-send-email-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.1.0.rc1 In-Reply-To: <1408388871-2372-1-git-send-email-rep.dot.nop@gmail.com> References: <1408388871-2372-1-git-send-email-rep.dot.nop@gmail.com> X-Univie-Virus-Scan: scanned by ClamAV on jarvis.univie.ac.at Cc: Bernhard Reutner-Fischer , patchwork@lists.ozlabs.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.18 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" a386e636cc0adaa760a66b6ab042178027fc45c7 removed argparse mutual exclusive group, so manually diagnose: 1) missing required hash_str / IDs 2) if both hash_str as well as IDs are seen Signed-off-by: Bernhard Reutner-Fischer --- apps/patchwork/bin/pwclient | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient index bd79b3a..86feef0 100755 --- a/apps/patchwork/bin/pwclient +++ b/apps/patchwork/bin/pwclient @@ -332,7 +332,7 @@ class _RecursiveHelpAction(argparse._HelpAction): def main(): hash_parser = argparse.ArgumentParser(add_help=False, version=False) hash_parser.add_argument( - '-h', metavar='HASH', dest='hash', action='store', required=False, + '-h', metavar='HASH', dest='hash', action='store', help='''Lookup by patch hash''' ) hash_parser.add_argument( @@ -474,11 +474,13 @@ def main(): args = action_parser.parse_args() args=dict(vars(args)) + action = args.get('subcmd') if args.get('hash') and len(args.get('id')): # mimic mutual exclusive group - sys.stderr.write("[-h HASH] and [ID [ID ...]] are mutually exlusive!\n") - action_parser.print_help() + sys.stderr.write("Error: [-h HASH] and [ID [ID ...]] " + + "are mutually exlusive\n") + locals()[action + '_parser'].print_help() sys.exit(1) # set defaults @@ -493,8 +495,6 @@ def main(): patch_ids = None url = DEFAULT_URL - action = args.get('subcmd') - if args.get('s'): state_str = args.get('s') if args.get('p'): @@ -510,7 +510,9 @@ def main(): if args.get('c'): # update multiple IDs with a single commit-hash does not make sense if action == 'update' and patch_ids and len(patch_ids) > 1: - sys.stderr.write("Declining update with COMMIT-REF on multiple IDs\n") + sys.stderr.write( + "Declining update with COMMIT-REF on multiple IDs\n" + ) update_parser.print_help() sys.exit(1) commit_str = args.get('c') @@ -618,6 +620,23 @@ def main(): if hash_str != None: patch_ids = [patch_id_from_hash(rpc, project_str, hash_str)] + # helper for non_empty() to print correct helptext + h = None + try: + h = locals()[action + '_parser'] + except: + pass # never happens + # Require either hash_str or IDs for + def non_empty(h, patch_ids): + """Error out if no patch IDs were specified""" + if patch_ids == None or len(patch_ids) < 1: + sys.stderr.write("Error: Missing Argument! " + + "Either [-h HASH] or [ID [ID ...]] are required\n") + if h: + h.print_help() + sys.exit(1) + return patch_ids + if action == 'list' or action == 'search': if args.get('patch_name') != None: filt.add("name__icontains", args.get('patch_name')) @@ -630,29 +649,31 @@ def main(): action_states(rpc) elif action == 'view': - for patch_id in patch_ids: + for patch_id in non_empty(h, patch_ids): s = rpc.patch_get_mbox(patch_id) if len(s) > 0: print unicode(s).encode("utf-8") elif action in ('get', 'save', 'info'): if action == 'info': - [action_info(rpc, patch_id) for patch_id in patch_ids] + [action_info(rpc, patch_id) for patch_id in non_empty(h, patch_ids)] else: - [action_get(rpc, patch_id) for patch_id in patch_ids] + [action_get(rpc, patch_id) for patch_id in non_empty(h, patch_ids)] elif action == 'apply': - [action_apply(rpc, patch_id) for patch_id in patch_ids] + [action_apply(rpc, patch_id) for patch_id in non_empty(h, patch_ids)] elif action == 'git-am': cmd = ['git', 'am'] if do_signoff: cmd.append('-s') - [action_apply(rpc, patch_id, cmd) for patch_id in patch_ids] + [action_apply(rpc, patch_id, cmd) for patch_id in + non_empty(h, patch_ids)] elif action == 'update': [action_update_patch(rpc, patch_id, state = state_str, - commit = commit_str) for patch_id in patch_ids] + commit = commit_str + ) for patch_id in non_empty(h, patch_ids)] else: sys.stderr.write("Unknown action '%s'\n" % action)