weboobcfg: Format capabilities as JSON array
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.
This commit is contained in:
parent
656440b5ee
commit
c81b622c29
1 changed files with 14 additions and 1 deletions
|
|
@ -31,6 +31,19 @@ from weboob.tools.application.formatters.iformatter import IFormatter
|
|||
__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 ModuleInfoFormatter(IFormatter):
|
||||
def format_dict(self, minfo):
|
||||
result = '.------------------------------------------------------------------------------.\n'
|
||||
|
|
@ -221,7 +234,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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue