Get all available subscriptions for details command
Add a new method get_object_list to ReplApplication Should close #846.
This commit is contained in:
parent
c9616639af
commit
92d5e9ea0f
2 changed files with 43 additions and 23 deletions
|
|
@ -35,6 +35,7 @@ class SubscriptionsFormatter(PrettyFormatter):
|
||||||
def get_title(self, obj):
|
def get_title(self, obj):
|
||||||
return obj.label
|
return obj.label
|
||||||
|
|
||||||
|
|
||||||
class Boobill(ReplApplication):
|
class Boobill(ReplApplication):
|
||||||
APPNAME = 'boobill'
|
APPNAME = 'boobill'
|
||||||
VERSION = '0.c'
|
VERSION = '0.c'
|
||||||
|
|
@ -49,7 +50,6 @@ class Boobill(ReplApplication):
|
||||||
'ls': 'subscriptions',
|
'ls': 'subscriptions',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def main(self, argv):
|
def main(self, argv):
|
||||||
self.load_config()
|
self.load_config()
|
||||||
return ReplApplication.main(self, argv)
|
return ReplApplication.main(self, argv)
|
||||||
|
|
@ -61,37 +61,42 @@ class Boobill(ReplApplication):
|
||||||
List subscriptions
|
List subscriptions
|
||||||
"""
|
"""
|
||||||
self.start_format()
|
self.start_format()
|
||||||
for backend, subscription in self.do('iter_subscription'):
|
for subscription in self.get_object_list('iter_subscription'):
|
||||||
self.cached_format(subscription)
|
self.cached_format(subscription)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def do_details(self, id):
|
def do_details(self, id):
|
||||||
"""
|
"""
|
||||||
details Id
|
details [ID]
|
||||||
|
|
||||||
Get details of a subscription.
|
Get details of subscriptions.
|
||||||
|
If no ID given, display all details of all backends
|
||||||
"""
|
"""
|
||||||
|
l = []
|
||||||
id, backend_name = self.parse_id(id)
|
id, backend_name = self.parse_id(id)
|
||||||
|
|
||||||
if not id:
|
if not id:
|
||||||
print >>sys.stderr, 'Error: please give a subscription ID (hint: use subscriptions command)'
|
for subscrib in self.get_object_list('iter_subscription'):
|
||||||
return 2
|
l.append((subscrib.id, subscrib.backend))
|
||||||
names = (backend_name,) if backend_name is not None else None
|
else:
|
||||||
|
l.append((id, backend_name))
|
||||||
|
|
||||||
# XXX: should be generated by backend? -Flo
|
for id, backend in l:
|
||||||
# XXX: no, but you should do it in a specific formatter -romain
|
names = (backend,) if backend is not None else None
|
||||||
mysum = Detail()
|
# XXX: should be generated by backend? -Flo
|
||||||
mysum.label = u"Sum"
|
# XXX: no, but you should do it in a specific formatter -romain
|
||||||
mysum.infos = u"Generated by boobill"
|
mysum = Detail()
|
||||||
mysum.price = Decimal("0.")
|
mysum.label = u"Sum"
|
||||||
|
mysum.infos = u"Generated by boobill"
|
||||||
|
mysum.price = Decimal("0.")
|
||||||
|
|
||||||
self.start_format()
|
self.start_format()
|
||||||
for backend, detail in self.do('get_details', id, backends=names):
|
for backend, detail in self.do('get_details', id, backends=names):
|
||||||
self.format(detail)
|
self.format(detail)
|
||||||
mysum.price = detail.price + mysum.price
|
mysum.price = detail.price + mysum.price
|
||||||
|
|
||||||
self.format(mysum)
|
self.format(mysum)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def do_history(self, id):
|
def do_history(self, id):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ __all__ = ['NotEnoughArguments', 'ReplApplication']
|
||||||
class NotEnoughArguments(Exception):
|
class NotEnoughArguments(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ReplOptionParser(OptionParser):
|
class ReplOptionParser(OptionParser):
|
||||||
def format_option_help(self, formatter=None):
|
def format_option_help(self, formatter=None):
|
||||||
if not formatter:
|
if not formatter:
|
||||||
|
|
@ -53,6 +54,7 @@ class ReplOptionParser(OptionParser):
|
||||||
return '%s\n%s' % (formatter.format_commands(self.commands),
|
return '%s\n%s' % (formatter.format_commands(self.commands),
|
||||||
OptionParser.format_option_help(self, formatter))
|
OptionParser.format_option_help(self, formatter))
|
||||||
|
|
||||||
|
|
||||||
class ReplOptionFormatter(IndentedHelpFormatter):
|
class ReplOptionFormatter(IndentedHelpFormatter):
|
||||||
def format_commands(self, commands):
|
def format_commands(self, commands):
|
||||||
s = u''
|
s = u''
|
||||||
|
|
@ -67,6 +69,7 @@ class ReplOptionFormatter(IndentedHelpFormatter):
|
||||||
s += ' %s\n' % c
|
s += ' %s\n' % c
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
class ReplApplication(Cmd, ConsoleApplication):
|
class ReplApplication(Cmd, ConsoleApplication):
|
||||||
"""
|
"""
|
||||||
Base application class for Repl applications.
|
Base application class for Repl applications.
|
||||||
|
|
@ -211,6 +214,18 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
backend.fillobj(obj, fields)
|
backend.fillobj(obj, fields)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
def get_object_list(self, method=None):
|
||||||
|
# return cache if not empty
|
||||||
|
if len(self.objects) > 0:
|
||||||
|
return self.objects
|
||||||
|
elif method is not None:
|
||||||
|
for backend, object in self.do(method):
|
||||||
|
self.add_object(object)
|
||||||
|
return self.objects
|
||||||
|
# XXX: what can we do without method?
|
||||||
|
else:
|
||||||
|
return tuple()
|
||||||
|
|
||||||
def unload_backends(self, *args, **kwargs):
|
def unload_backends(self, *args, **kwargs):
|
||||||
self.objects = []
|
self.objects = []
|
||||||
self.collections = []
|
self.collections = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue