Skip to content

Commit ff74cbb

Browse files
committed
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>
1 parent 9fbae85 commit ff74cbb

3 files changed

Lines changed: 14 additions & 33 deletions

File tree

tools/cli/cloudmonkey/cloudmonkey.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ def printer_helper(printer, toprow):
163163
self.monkeyprint(printer)
164164
return PrettyTable(toprow)
165165

166-
# method: print_result_json( result, result_filter )
167-
# parameters: result - raw results from the API call
168-
# result_filter - filterset
169-
# description: prints result as a json object
170166
def print_result_json(result, result_filter=None):
171167
tfilter = {} # temp var to hold a dict of the filters
172168
tresult = copy.deepcopy(result) # dupe the result to filter
@@ -222,9 +218,7 @@ def print_result_tabular(result, result_filter=None):
222218
self.monkeyprint(printer)
223219

224220
def print_result_as_dict(result, result_filter=None):
225-
226-
# tabularize overrides self.display
227-
if self.display == "json" and not self.tabularize == "true":
221+
if self.display == "json":
228222
print_result_json(result, result_filter)
229223
return
230224

@@ -239,9 +233,7 @@ def print_result_as_dict(result, result_filter=None):
239233

240234
def print_result_as_list(result, result_filter=None):
241235
for node in result:
242-
# Tabular print if it's a list of dict and tabularize is true
243-
if isinstance(node, dict) and (self.display == 'tabularize' or
244-
self.tabularize == 'true'):
236+
if isinstance(node, dict) and self.display == 'table':
245237
print_result_tabular(result, result_filter)
246238
break
247239
self.print_result(node)
@@ -364,9 +356,8 @@ def completedefault(self, text, line, begidx, endidx):
364356
autocompletions = uuids
365357
search_string = value
366358

367-
if subject != "" and (self.display == "tabularize" or
368-
self.display == "json" or
369-
self.tabularize == "true"):
359+
if subject != "" and (self.display == "table" or
360+
self.display == "json"):
370361
autocompletions.append("filter=")
371362
return [s for s in autocompletions if s.startswith(search_string)]
372363

tools/cli/cloudmonkey/config.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
# ui
5757
config_fields['ui']['color'] = 'true'
5858
config_fields['ui']['prompt'] = '> '
59-
config_fields['ui']['tabularize'] = 'false' # deprecate - REMOVE
60-
config_fields['ui']['display'] = 'default' # default display mechanism
59+
config_fields['ui']['display'] = 'default'
6160

6261
# server
6362
config_fields['server']['host'] = 'localhost'
@@ -112,19 +111,9 @@ def read_config(get_attr, set_attr, config_file):
112111
for section in config_fields.keys():
113112
for key in config_fields[section].keys():
114113
try:
115-
if( key == "tabularize" ): # this key is deprecated
116-
print "\ntabularize config parameter is deprecated:",
117-
print "please switch to display =",
118-
print "[default,json,tabularize]\n"
119114
set_attr(key, config.get(section, key))
120115
except Exception:
121-
if( key == "tabularize" ): # this key is deprecated
122-
set_attr( key, "false" ) # set default
123-
elif( key == "display" ): # this key is deprecated
124-
config = write_config(get_attr, config_file, True)
125-
set_attr( key, "default" ) # set default
126-
else:
127-
missing_keys.append(key)
116+
missing_keys.append(key)
128117

129118
if len(missing_keys) > 0:
130119
print "Please fix `%s` in %s" % (', '.join(missing_keys), config_file)

tools/cli/cloudmonkey/requester.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def process_json(response):
138138
time.sleep(pollperiod)
139139
else:
140140
response, error = monkeyrequest(command, request, isasync,
141-
asyncblock, logger,
142-
host, port, apikey, secretkey,
143-
timeout, protocol, path)
141+
asyncblock, logger,
142+
host, port, apikey, secretkey,
143+
timeout, protocol, path)
144144

145145
responsekeys = filter(lambda x: 'response' in x, response.keys())
146146

@@ -161,15 +161,16 @@ def process_json(response):
161161
sys.stdout.flush()
162162

163163
if jobresultcode != 0:
164-
error = "Error: resultcode %d for jobid %s" % (jobresultcode, jobid)
164+
error = "Error: resultcode %d for jobid %s" % (jobresultcode,
165+
jobid)
165166
logger_debug(logger, "%s" % (error))
166167
return response, error
167168
else:
168169
# if we get a valid respons resultcode give back results
169170
response, error = monkeyrequest(command, request, isasync,
170-
asyncblock, logger,
171-
host, port, apikey, secretkey,
172-
timeout, protocol, path)
171+
asyncblock, logger,
172+
host, port, apikey, secretkey,
173+
timeout, protocol, path)
173174
logger_debug(logger, "Ok: %s" % (jobid))
174175
return response, error
175176

0 commit comments

Comments
 (0)