changeset 2233:bf998d8626d9

jp (output): added LIST_DICT output, to handle list of dictionaries
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 00:58:12 +0200
parents 4f389486667d
children a41a4729c2d8
files frontends/src/jp/constants.py frontends/src/jp/output_std.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)