Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E410FE45F for ; Thu, 24 Jan 2013 22:48:08 +0000 (UTC) Received: (qmail 6648 invoked by uid 500); 24 Jan 2013 22:48:08 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 6613 invoked by uid 500); 24 Jan 2013 22:48:08 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 6470 invoked by uid 99); 24 Jan 2013 22:48:08 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2013 22:48:08 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 59DCA824F83; Thu, 24 Jan 2013 22:48:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: cli: fix cloudmonkey's pipe-ability Message-Id: <20130124224808.59DCA824F83@tyr.zones.apache.org> Date: Thu, 24 Jan 2013 22:48:08 +0000 (UTC) Updated Branches: refs/heads/master 531c2f030 -> 6f90a86b1 cli: fix cloudmonkey's pipe-ability Signed-off-by: Rohit Yadav Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/6f90a86b Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/6f90a86b Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/6f90a86b Branch: refs/heads/master Commit: 6f90a86b13ae91441870a008e1e2ff0adc3c26a3 Parents: 71257d6 Author: Rohit Yadav Authored: Thu Jan 24 14:47:45 2013 -0800 Committer: Rohit Yadav Committed: Thu Jan 24 14:47:45 2013 -0800 ---------------------------------------------------------------------- tools/cli/cloudmonkey/cloudmonkey.py | 30 ++++++++++++++++++++-------- 1 files changed, 21 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6f90a86b/tools/cli/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index ace6a8b..eadf23f 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -75,7 +75,8 @@ class CloudMonkeyShell(cmd.Cmd, object): # datastructure {'verb': {cmd': ['api', [params], doc, required=[]]}} cache_verbs = precached_verbs - def __init__(self): + def __init__(self, pname): + self.program_name = pname if os.path.exists(self.config_file): config = self.read_config() else: @@ -307,7 +308,19 @@ class CloudMonkeyShell(cmd.Cmd, object): return None return api_mod + def pipe_runner(self, args): + if args.find(' |') > -1: + pname = self.program_name + if '.py' in pname: + pname = "python " + pname + self.do_shell("%s %s" % (pname, args)) + return True + return False + def default(self, args): + if self.pipe_runner(args): + return + lexp = shlex.shlex(args.strip()) lexp.whitespace = " " lexp.whitespace_split = True @@ -506,22 +519,21 @@ def main(): for rule in grammar: def add_grammar(rule): def grammar_closure(self, args): - if '|' in args: # FIXME: Consider parsing issues - prog_name = sys.argv[0] - if '.py' in prog_name: - prog_name = "python " + prog_name - self.do_shell("%s %s %s" % (prog_name, rule, args)) + if self.pipe_runner("%s %s" % (rule, args)): return try: args_partition = args.partition(" ") res = self.cache_verbs[rule][args_partition[0]] + cmd = res[0] + helpdoc = res[2] + args = args_partition[2] except KeyError, e: self.print_shell("Error: invalid %s api arg" % rule, e) return if ' --help' in args or ' -h' in args: - self.print_shell(res[2]) + self.print_shell(helpdoc) return - self.default(res[0] + " " + args_partition[2]) + self.default("%s %s" % (cmd, args)) return grammar_closure grammar_handler = add_grammar(rule) @@ -529,7 +541,7 @@ def main(): grammar_handler.__name__ = 'do_' + rule setattr(self, grammar_handler.__name__, grammar_handler) - shell = CloudMonkeyShell() + shell = CloudMonkeyShell(sys.argv[0]) if len(sys.argv) > 1: shell.onecmd(' '.join(sys.argv[1:])) else: