jp (output): added LIST_DICT output, to handle list of dictionaries
This commit is contained in:
parent
6e70992c6c
commit
e255b969e0
2 changed files with 11 additions and 1 deletions
|
|
@ -29,10 +29,11 @@ class Const(constants.Const):
|
|||
OUTPUT_TEXT = u'text' # blob of unicode text
|
||||
OUTPUT_DICT = u'dict' # simple key/value dictionary
|
||||
OUTPUT_LIST = u'list'
|
||||
OUTPUT_LIST_DICT = u'list_dict' # list of dictionaries
|
||||
OUTPUT_COMPLEX = u'complex' # complex data (e.g. multi-level dictionary)
|
||||
OUTPUT_XML = u'xml' # XML node (as unicode string)
|
||||
OUTPUT_LIST_XML = u'list_xml' # list of XML nodes (as unicode strings)
|
||||
OUTPUT_TYPES = (OUTPUT_TEXT, OUTPUT_DICT, OUTPUT_LIST, OUTPUT_COMPLEX, OUTPUT_XML, OUTPUT_LIST_XML)
|
||||
OUTPUT_TYPES = (OUTPUT_TEXT, OUTPUT_DICT, OUTPUT_LIST, OUTPUT_LIST_DICT, OUTPUT_COMPLEX, OUTPUT_XML, OUTPUT_LIST_XML)
|
||||
|
||||
# ANSI
|
||||
A_HEADER = A.BOLD + A.FG_YELLOW
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class Simple(object):
|
|||
host.register_output(C.OUTPUT_TEXT, SIMPLE, self.simple_print)
|
||||
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_COMPLEX, SIMPLE, self.simple_print)
|
||||
|
||||
def simple_print(self, data):
|
||||
|
|
@ -57,6 +58,12 @@ class Simple(object):
|
|||
|
||||
self.host.disp((u'{header}{value}'.format(header=header, value=v)))
|
||||
|
||||
def list_dict(self, data):
|
||||
for idx, datum in enumerate(data):
|
||||
if idx:
|
||||
self.host.disp(u'\n')
|
||||
self.dict(datum)
|
||||
|
||||
|
||||
class Json(object):
|
||||
"""outputs in json format"""
|
||||
|
|
@ -68,6 +75,8 @@ class Json(object):
|
|||
host.register_output(C.OUTPUT_LIST, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT, JSON, self.dump_pretty)
|
||||
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_COMPLEX, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue