diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index 6f5becadae24284d202c7d23365a27d10d9bf05f..bc44eec60a33c29c5ff995219c5d0d7cda09afc0 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -203,6 +203,16 @@ def format_dict(self, obj): """ return NotImplementedError() + def format_collection(self, collection, only): + """ + Format a collection to be human-readable. + + :param collection: collection to format + :type collection: BaseCollection + :rtype: str + """ + return NotImplementedError() + class PrettyFormatter(IFormatter): def format_obj(self, obj, alias): @@ -230,6 +240,16 @@ def get_title(self, obj): def get_description(self, obj): return None + def format_collection(self, collection, only): + if only is False or collection.basename in only: + if collection.basename and collection.title: + self.output(u'%s~ (%s) %s (%s)%s' % + (self.BOLD, collection.basename, collection.title, collection.backend, self.NC)) + else: + self.output(u'%s~ (%s) (%s)%s' % + (self.BOLD, collection.basename, collection.backend, self.NC)) + + def formatter_test_output(Formatter, obj): """ Formats an object and returns output as a string. diff --git a/weboob/tools/application/repl.py b/weboob/tools/application/repl.py index e435b3c405e469612703007fa11d2469b8043cb4..9c8751ea79fa056acbfe2012320a0fec953caa86 100644 --- a/weboob/tools/application/repl.py +++ b/weboob/tools/application/repl.py @@ -1038,7 +1038,7 @@ def do_ls(self, line): if isinstance(res, Collection): collections.append(res) if sort is False: - self._format_collection(res, only) + self.formatter.format_collection(res, only) else: if sort: objects.append(res) @@ -1050,7 +1050,7 @@ def do_ls(self, line): collections = self._merge_collections_with_same_path(collections) collections.sort(cmp=self.comp_object) for collection in collections: - self._format_collection(collection, only) + self.formatter.format_collection(collection, only) for obj in objects: self._format_obj(obj, only) @@ -1077,17 +1077,6 @@ def _merge_collections_with_same_path(self, collections): to_return.append(collection) return to_return - - def _format_collection(self, collection, only): - if only is False or collection.basename in only: - if collection.basename and collection.title: - print(u'%s~ (%s) %s (%s)%s' % \ - (self.BOLD, collection.basename, collection.title, collection.backend, self.NC)) - else: - print(u'%s~ (%s) (%s)%s' % \ - (self.BOLD, collection.basename, collection.backend, self.NC)) - - def _format_obj(self, obj, only): if only is False or not hasattr(obj, 'id') or obj.id in only: self.cached_format(obj)