Set comp_object as class method

This commit is contained in:
Florent 2014-05-07 23:22:28 +02:00
commit 236b9087a2
2 changed files with 29 additions and 40 deletions

View file

@ -24,31 +24,8 @@ from weboob.tools.date import parse_date
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
from weboob.capabilities.base import empty
from weboob.capabilities.calendar import ICapCalendarEvent, Query, CATEGORIES, BaseCalendarEvent
from weboob.tools.application import repl
from weboob.tools.application.repl import ReplApplication, defaultcount
def _comp_object(obj1, obj2):
if isinstance(obj1, BaseCalendarEvent) and isinstance(obj2, BaseCalendarEvent):
if obj1.start_date == obj2.start_date:
return 0
if obj1.start_date > obj2.start_date:
return 1
return -1
else:
if obj1.backend == obj2.backend:
if obj1.id == obj2.id:
return 0
elif obj1.id > obj2.id:
return 1
else:
return -1
elif obj1.backend > obj2.backend:
return 1
else:
return -1
repl.comp_object = _comp_object
__all__ = ['Boobcoming']
@ -179,6 +156,17 @@ class Boobcoming(ReplApplication):
'export': 'ical_formatter'
}
def comp_object(self, obj1, obj2):
if isinstance(obj1, BaseCalendarEvent) and isinstance(obj2, BaseCalendarEvent):
if obj1.start_date == obj2.start_date:
return 0
if obj1.start_date > obj2.start_date:
return 1
return -1
else:
return super(Boobcoming, self).comp_object(obj1, obj2)
@defaultcount(10)
def do_search(self, line):
"""

View file

@ -90,21 +90,6 @@ def defaultcount(default_count=10):
return inner
return deco
# First sort in alphabetical of backend
# Second, first with ID
def comp_object(obj1, obj2):
if obj1.backend == obj2.backend:
if obj1.id == obj2.id:
return 0
elif obj1.id > obj2.id:
return 1
else:
return -1
elif obj1.backend > obj2.backend:
return 1
else:
return -1
class ReplApplication(Cmd, ConsoleApplication):
"""
@ -979,6 +964,22 @@ class ReplApplication(Cmd, ConsoleApplication):
page = Page(core=browser, data=data, uri=browser._response.geturl())
browser = Browser(view=page.view)
# First sort in alphabetical of backend
# Second, sort with ID
def comp_object(self, obj1, obj2):
if obj1.backend == obj2.backend:
if obj1.id == obj2.id:
return 0
elif obj1.id > obj2.id:
return 1
else:
return -1
elif obj1.backend > obj2.backend:
return 1
else:
return -1
@defaultcount(40)
def do_ls(self, line):
"""
@ -1028,9 +1029,9 @@ class ReplApplication(Cmd, ConsoleApplication):
self._format_obj(res, only)
if sort:
objects.sort(cmp=comp_object)
objects.sort(cmp=self.comp_object)
collections = self._merge_collections_with_same_path(collections)
collections.sort(cmp=comp_object)
collections.sort(cmp=self.comp_object)
for collection in collections:
self._format_collection(collection, only)
for obj in objects: