jp (standard output): added simple, json and json_raw for OUTPUT_DICT_DICT
This commit is contained in:
parent
178a8311ca
commit
09c40742d1
1 changed files with 14 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ class Simple(object):
|
|||
host.register_output(C.OUTPUT_LIST, SIMPLE, self.list)
|
||||
host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, SIMPLE, self.list_dict)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, SIMPLE, self.dict_dict)
|
||||
host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print)
|
||||
|
||||
def simple_print(self, data):
|
||||
|
|
@ -46,17 +47,20 @@ class Simple(object):
|
|||
def list(self, data):
|
||||
self.host.disp(u'\n'.join(data))
|
||||
|
||||
def dict(self, data):
|
||||
def dict(self, data, indent=0, header_color=C.A_HEADER):
|
||||
options = self.host.parse_output_options()
|
||||
self.host.check_output_options({u'no-header'}, options)
|
||||
show_header = not u'no-header' in options
|
||||
for k, v in data.iteritems():
|
||||
if show_header:
|
||||
header = A.color(A.BOLD, A.FG_YELLOW, k) + u': '
|
||||
header = A.color(header_color, k) + u': '
|
||||
else:
|
||||
header = u''
|
||||
|
||||
self.host.disp((u'{header}{value}'.format(header=header, value=v)))
|
||||
self.host.disp((u'{indent}{header}{value}'.format(
|
||||
indent=indent*u' ',
|
||||
header=header,
|
||||
value=v)))
|
||||
|
||||
def list_dict(self, data):
|
||||
for idx, datum in enumerate(data):
|
||||
|
|
@ -64,6 +68,11 @@ class Simple(object):
|
|||
self.host.disp(u'\n')
|
||||
self.dict(datum)
|
||||
|
||||
def dict_dict(self, data):
|
||||
for key, sub_dict in data.iteritems():
|
||||
self.host.disp(A.color(C.A_HEADER, key))
|
||||
self.dict(sub_dict, indent=4, header_color=C.A_SUBHEADER)
|
||||
|
||||
|
||||
class Json(object):
|
||||
"""outputs in json format"""
|
||||
|
|
@ -77,6 +86,8 @@ class Json(object):
|
|||
host.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue