You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2013/01/06 10:11:58 UTC
[1/4] git commit: cli: Remove unused method, fix welcome msg, prompt
cli: Remove unused method, fix welcome msg, prompt
Signed-off-by: Rohit Yadav <bh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/f1c15f0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/f1c15f0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/f1c15f0c
Branch: refs/heads/api_refactoring
Commit: f1c15f0c2eaf11999ce2945ad1b4c7dc8a539a9b
Parents: 3d9dc36
Author: Rohit Yadav <bh...@apache.org>
Authored: Sat Jan 5 02:11:45 2013 -0800
Committer: Rohit Yadav <bh...@apache.org>
Committed: Sat Jan 5 02:11:45 2013 -0800
----------------------------------------------------------------------
tools/cli/cloudmonkey/cloudmonkey.py | 41 ++++------------------------
1 files changed, 6 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f1c15f0c/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index 3bc8716..a573972 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -84,6 +84,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
config = self.write_config()
print "Welcome! Using `set` configure the necessary settings:"
print " ".join(sorted(self.config_fields.keys()))
+ print "Config file:", self.config_file
print "For debugging, tail -f", self.log_file, "\n"
for key in self.config_fields.keys():
@@ -204,7 +205,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
def print_result_as_dict(result, result_filter=None):
for key in sorted(result.keys(),
- key=lambda x: x!='id' and x!='count' and x):
+ key=lambda x: x != 'id' and x != 'count' and x):
if not (isinstance(result[key], list) or
isinstance(result[key], dict)):
self.print_shell("%s = %s" % (key, result[key]))
@@ -267,8 +268,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
requests = {'jobid': jobId}
timeout = int(self.timeout)
pollperiod = 3
+ progress = 1
while timeout > 0:
- progress = int((int(self.timeout) - timeout) / pollperiod ) + 1
print '\r' + '.' * progress,
sys.stdout.flush()
response = process_json(conn.make_request_with_auth(command,
@@ -290,6 +291,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
return response
time.sleep(pollperiod)
timeout = timeout - pollperiod
+ progress += 1
logger.debug("job: %s to timeout in %ds" % (jobId, timeout))
self.print_shell("Error:", "Async query timeout for jobid=", jobId)
@@ -363,30 +365,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
except Exception as e:
self.print_shell("🙈 Error on parsing and printing", e)
- def cache_verb_miss(self, verb):
- self.print_shell("Oops: Verb %s should have been precached" % verb)
- completions_found = filter(lambda x: x.startswith(verb), completions)
- self.cache_verbs[verb] = {}
- for api_name in completions_found:
- api_cmd_str = "%sCmd" % api_name
- api_mod = self.get_api_module(api_name, [api_cmd_str])
- if api_mod is None:
- continue
- try:
- api_cmd = getattr(api_mod, api_cmd_str)()
- required = api_cmd.required
- doc = api_mod.__doc__
- except AttributeError, e:
- self.print_shell("Error: API attribute %s not found!" % e)
- params = filter(lambda x: '__' not in x and 'required' not in x,
- dir(api_cmd))
- if len(required) > 0:
- doc += "\nRequired args: %s" % " ".join(required)
- doc += "\nArgs: %s" % " ".join(params)
- api_name_lower = api_name.replace(verb, '').lower()
- self.cache_verbs[verb][api_name_lower] = [api_name, params, doc,
- required]
-
def completedefault(self, text, line, begidx, endidx):
partitions = line.partition(" ")
verb = partitions[0]
@@ -401,9 +379,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
autocompletions = []
search_string = ""
- if verb not in self.cache_verbs:
- self.cache_verb_miss(verb)
-
if separator != " ": # Complete verb subjects
autocompletions = self.cache_verbs[verb].keys()
search_string = subject
@@ -445,8 +420,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
"""
args = args.strip().partition(" ")
key, value = (args[0], args[2])
- # Note: keys and class attributes should have same names
- setattr(self, key, value)
+ setattr(self, key, value) # keys and attributes should have same names
+ self.prompt += " " # prompt fix
self.write_config()
def complete_set(self, text, line, begidx, endidx):
@@ -484,8 +459,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
else:
verb = fields[0]
subject = fields[2].partition(" ")[0]
- if verb not in self.cache_verbs:
- self.cache_verb_miss(verb)
if subject in self.cache_verbs[verb]:
self.print_shell(self.cache_verbs[verb][subject][2])
@@ -537,8 +510,6 @@ def main():
prog_name = "python " + prog_name
self.do_shell("%s %s %s" % (prog_name, rule, args))
return
- if not rule in self.cache_verbs:
- self.cache_verb_miss(rule)
try:
args_partition = args.partition(" ")
res = self.cache_verbs[rule][args_partition[0]]