# HG changeset patch # User Goffi # Date 1493247492 -7200 # Node ID bf998d8626d94910d93489b0b2b2722e01805a0f # Parent 4f389486667d688eb49d56547d3bbd8f953edd99 jp (output): added LIST_DICT output, to handle list of dictionaries diff -r 4f389486667d -r bf998d8626d9 frontends/src/jp/constants.py --- a/frontends/src/jp/constants.py Thu Apr 27 00:57:04 2017 +0200 +++ b/frontends/src/jp/constants.py Thu Apr 27 00:58:12 2017 +0200 @@ -29,10 +29,11 @@ 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 diff -r 4f389486667d -r bf998d8626d9 frontends/src/jp/output_std.py --- a/frontends/src/jp/output_std.py Thu Apr 27 00:57:04 2017 +0200 +++ b/frontends/src/jp/output_std.py Thu Apr 27 00:58:12 2017 +0200 @@ -37,6 +37,7 @@ 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 @@ 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 @@ 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)