From 3bf7975ad1f9db5a4443c5de3f78354beee0e2f9 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 12 Aug 2010 18:15:43 +0200 Subject: [PATCH] display a 'Total' line on command 'list' --- weboob/applications/boobank/boobank.py | 9 +++++++++ weboob/tools/application/formatters/iformatter.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 5cfbc0c3..c2ac78dd 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -40,15 +40,24 @@ class Boobank(ConsoleApplication): @ConsoleApplication.command('List every available accounts') def command_list(self): self.load_configured_backends(ICapBank) + tot_balance = 0.0 + tot_coming = 0.0 try: for backend, account in self.do('iter_accounts'): self.format(account) + tot_balance += account.balance + tot_coming += account.coming except weboob.core.CallErrors, errors: for backend, error, backtrace in errors: if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword): logging.error(u'Error: Incorrect password for backend %s' % backend.name) else: logging.error(u'Error[%s]: %s\n%s' % (backend.name, error, backtrace)) + else: + self.format((('id', ''), + ('label', 'Total'), + ('balance', tot_balance), + ('coming', tot_coming))) @ConsoleApplication.command('Display old operations') def command_history(self, id): diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index fda76a82..245d7466 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -57,10 +57,12 @@ class IFormatter(object): @param condition [Condition] condition to objects to display @return a string of the formatted object """ - assert isinstance(obj, (dict, CapBaseObject)) + assert isinstance(obj, (dict, CapBaseObject, tuple)) if isinstance(obj, dict): item = obj + elif isinstance(obj, tuple): + item = OrderedDict([(k, v) for k, v in obj]) else: item = self.to_dict(obj, condition, selected_fields)