[repl] move format_collection from repl to ifromatter
This commit is contained in:
parent
b725101e47
commit
7b5ab26d0f
2 changed files with 22 additions and 13 deletions
|
|
@ -203,6 +203,16 @@ class IFormatter(object):
|
|||
"""
|
||||
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 @@ class PrettyFormatter(IFormatter):
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -1038,7 +1038,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
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 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
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 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue