[weboob] [PATCH] [config] Format capabilities as JSON array

Guilhem Bonnefille guilhem.bonnefille at gmail.com
Wed Jun 18 21:30:37 CEST 2014


Capabilities was always displayed as a single list of entries
separated by comma. This is not really efficient as the reader has to parse
this string to retrieve atomic informations, even in JSON.

This patch allows to display the capabilities as an array, allowing standard JSON parsers
to immediatly returns a valuable information.
---
 weboob/applications/weboobcfg/weboobcfg.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/weboob/applications/weboobcfg/weboobcfg.py b/weboob/applications/weboobcfg/weboobcfg.py
index 4ef6182..9853260 100644
--- a/weboob/applications/weboobcfg/weboobcfg.py
+++ b/weboob/applications/weboobcfg/weboobcfg.py
@@ -30,6 +30,17 @@ from weboob.tools.ordereddict import OrderedDict
 
 __all__ = ['WeboobCfg']
 
+class CapabilitiesWrapper(list):
+    """
+    A wrapper class to keep the list nature of capabilities,
+    but provide a comma separated list representation for
+    formaters unable to display a list by themselves.
+
+    Useful for having an array representation in JSON and
+    comma separated list for simple format.
+    """
+    def __repr__(self):
+        return ', '.join(self)
 
 class WeboobCfg(ReplApplication):
     APPNAME = 'weboob-config'
@@ -190,7 +201,7 @@ class WeboobCfg(ReplApplication):
         caps = line.split()
         for name, info in sorted(self.weboob.repositories.get_all_modules_info(caps).iteritems()):
             row = OrderedDict([('Name', name),
-                               ('Capabilities', ', '.join(info.capabilities)),
+                               ('Capabilities', CapabilitiesWrapper(info.capabilities)),
                                ('Description', info.description),
                                ])
             self.format(row)
-- 
2.0.0




More information about the weboob mailing list