cli: Remove tabularize, fix display types, make code pep8 compliant

- Remove tabularize field
- Now display types are: default, json and table
- Make requester pep8 compliant
- Remove unnecessary comments, if we want them we should put them on each method

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2013-04-05 23:06:44 +05:30
parent 9fbae85799
commit ff74cbbeea
3 changed files with 14 additions and 33 deletions

View File

@ -163,10 +163,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
self.monkeyprint(printer)
return PrettyTable(toprow)
# method: print_result_json( result, result_filter )
# parameters: result - raw results from the API call
# result_filter - filterset
# description: prints result as a json object
def print_result_json(result, result_filter=None):
tfilter = {} # temp var to hold a dict of the filters
tresult = copy.deepcopy(result) # dupe the result to filter
@ -222,9 +218,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
self.monkeyprint(printer)
def print_result_as_dict(result, result_filter=None):
# tabularize overrides self.display
if self.display == "json" and not self.tabularize == "true":
if self.display == "json":
print_result_json(result, result_filter)
return
@ -239,9 +233,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
def print_result_as_list(result, result_filter=None):
for node in result:
# Tabular print if it's a list of dict and tabularize is true
if isinstance(node, dict) and (self.display == 'tabularize' or
self.tabularize == 'true'):
if isinstance(node, dict) and self.display == 'table':
print_result_tabular(result, result_filter)
break
self.print_result(node)
@ -364,9 +356,8 @@ class CloudMonkeyShell(cmd.Cmd, object):
autocompletions = uuids
search_string = value
if subject != "" and (self.display == "tabularize" or
self.display == "json" or
self.tabularize == "true"):
if subject != "" and (self.display == "table" or
self.display == "json"):
autocompletions.append("filter=")
return [s for s in autocompletions if s.startswith(search_string)]

View File

@ -56,8 +56,7 @@ config_fields['core']['log_file'] = expanduser(config_dir + '/log')
# ui
config_fields['ui']['color'] = 'true'
config_fields['ui']['prompt'] = '> '
config_fields['ui']['tabularize'] = 'false' # deprecate - REMOVE
config_fields['ui']['display'] = 'default' # default display mechanism
config_fields['ui']['display'] = 'default'
# server
config_fields['server']['host'] = 'localhost'
@ -112,19 +111,9 @@ def read_config(get_attr, set_attr, config_file):
for section in config_fields.keys():
for key in config_fields[section].keys():
try:
if( key == "tabularize" ): # this key is deprecated
print "\ntabularize config parameter is deprecated:",
print "please switch to display =",
print "[default,json,tabularize]\n"
set_attr(key, config.get(section, key))
except Exception:
if( key == "tabularize" ): # this key is deprecated
set_attr( key, "false" ) # set default
elif( key == "display" ): # this key is deprecated
config = write_config(get_attr, config_file, True)
set_attr( key, "default" ) # set default
else:
missing_keys.append(key)
missing_keys.append(key)
if len(missing_keys) > 0:
print "Please fix `%s` in %s" % (', '.join(missing_keys), config_file)

View File

@ -138,9 +138,9 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
time.sleep(pollperiod)
else:
response, error = monkeyrequest(command, request, isasync,
asyncblock, logger,
host, port, apikey, secretkey,
timeout, protocol, path)
asyncblock, logger,
host, port, apikey, secretkey,
timeout, protocol, path)
responsekeys = filter(lambda x: 'response' in x, response.keys())
@ -161,15 +161,16 @@ def monkeyrequest(command, args, isasync, asyncblock, logger, host, port,
sys.stdout.flush()
if jobresultcode != 0:
error = "Error: resultcode %d for jobid %s" % (jobresultcode, jobid)
error = "Error: resultcode %d for jobid %s" % (jobresultcode,
jobid)
logger_debug(logger, "%s" % (error))
return response, error
else:
# if we get a valid respons resultcode give back results
response, error = monkeyrequest(command, request, isasync,
asyncblock, logger,
host, port, apikey, secretkey,
timeout, protocol, path)
asyncblock, logger,
host, port, apikey, secretkey,
timeout, protocol, path)
logger_debug(logger, "Ok: %s" % (jobid))
return response, error