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

Guilhem Bonnefille guilhem.bonnefille at gmail.com
Mon Nov 3 22:32:12 CET 2014


Hi,

Any comment on the preceding patch? I'm trying to integrate weboob
inside come other desktop application, and it would be really
appreciated if all commands can have a machine-friendly output (JSON)
with a maximum of informations.

So, please, review this patch and apply it.

2014-06-18 21:30 GMT+02:00 Guilhem Bonnefille <guilhem.bonnefille at gmail.com>:
> 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
>



-- 
Guilhem BONNEFILLE
-=- JID: guyou at im.apinc.org MSN: guilhem_bonnefille at hotmail.com
-=- mailto:guilhem.bonnefille at gmail.com
-=- http://nathguil.free.fr/


More information about the weboob mailing list