From bafbf3644a75f3b7a4983b2f09b46e240dd663de Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Wed, 9 Mar 2011 09:26:55 +0100 Subject: [PATCH] use IFormatter.(BOLD|NC) on every formatters --- weboob/applications/boobank/boobank.py | 4 ++-- weboob/applications/boobmsg/boobmsg.py | 18 +++++++++--------- weboob/applications/videoob/videoob.py | 6 +++--- weboob/applications/weboorrents/weboorrents.py | 12 ++++++------ weboob/applications/wetboobs/wetboobs.py | 10 +++++----- .../tools/application/formatters/iformatter.py | 4 +--- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 7aa1a7ae..2243efd7 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2009-2010 Romain Bignon, Christophe Benz +# Copyright(C) 2009-2011 Romain Bignon, Christophe Benz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -71,7 +71,7 @@ class AccountListFormatter(IFormatter): result += ' %s Account Balance Coming \n' % ((' ' * 15) if not self.interactive else '') result += '------------------------------------------%s+----------+----------\n' % (('-' * 15) if not self.interactive else '') result += (u' %s%-' + (u'15' if self.interactive else '30') + u's%s %-25s %8s %8s') % \ - (ReplApplication.BOLD, id, ReplApplication.NC, + (self.BOLD, id, self.NC, item['label'], '%.2f' % item['balance'], '%.2f' % (item['coming'] or 0.0)) self.tot_balance += item['balance'] diff --git a/weboob/applications/boobmsg/boobmsg.py b/weboob/applications/boobmsg/boobmsg.py index 914fffaa..b6ce0d9f 100644 --- a/weboob/applications/boobmsg/boobmsg.py +++ b/weboob/applications/boobmsg/boobmsg.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Christophe Benz +# Copyright(C) 2010-2011 Christophe Benz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -77,14 +77,14 @@ class MessagesListFormatter(IFormatter): unread = ' ' if self.interactive: backend = item['id'].split('@', 1)[1] - result = u'%s* (%d) %s %s (%s)%s' % (ReplApplication.BOLD, + result = u'%s* (%d) %s %s (%s)%s' % (self.BOLD, self.count, unread, item['title'], backend, - ReplApplication.NC) + self.NC) else: - result = u'%s* (%s) %s %s%s' % (ReplApplication.BOLD, item['id'], + result = u'%s* (%s) %s %s%s' % (self.BOLD, item['id'], unread, item['title'], - ReplApplication.NC) + self.NC) if item['date']: result += u'\n %s' % item['date'] return result @@ -119,21 +119,21 @@ class MessagesListFormatter(IFormatter): if self.interactive: result = u'%s%s* (%d)%s %s <%s> %s (%s)\n' % (depth * ' ', - ReplApplication.BOLD, + self.BOLD, self.count, - ReplApplication.NC, + self.NC, flags, message.sender, message.title, backend) else: result = u'%s%s* (%s.%s@%s)%s %s <%s> %s\n' % (depth * ' ', - ReplApplication.BOLD, + self.BOLD, message.thread.id, message.id, backend, flags, - ReplApplication.NC, + self.NC, message.sender, message.title) if message.children: diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index eff679d2..5730e38b 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Christophe Benz, Romain Bignon, John Obbele +# Copyright(C) 2010-2011 Christophe Benz, Romain Bignon, John Obbele # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -41,9 +41,9 @@ class VideoListFormatter(IFormatter): self.count += 1 if self.interactive: backend = item['id'].split('@', 1)[1] - result = u'%s* (%d) %s (%s)%s\n' % (ReplApplication.BOLD, self.count, item['title'], backend, ReplApplication.NC) + result = u'%s* (%d) %s (%s)%s\n' % (self.BOLD, self.count, item['title'], backend, self.NC) else: - result = u'%s* (%s) %s%s\n' % (ReplApplication.BOLD, item['id'], item['title'], ReplApplication.NC) + result = u'%s* (%s) %s%s\n' % (self.BOLD, item['id'], item['title'], self.NC) result += ' %s' % (item['duration'] if item['duration'] else item['date']) if item['author'] is not NotLoaded: result += ' - %s' % item['author'] diff --git a/weboob/applications/weboorrents/weboorrents.py b/weboob/applications/weboorrents/weboorrents.py index 5a2ee067..23ff7602 100644 --- a/weboob/applications/weboorrents/weboorrents.py +++ b/weboob/applications/weboorrents/weboorrents.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Romain Bignon +# Copyright(C) 2010-2011 Romain Bignon # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -41,16 +41,16 @@ class TorrentInfoFormatter(IFormatter): pass def format_dict(self, item): - result = u'%s%s%s\n' % (ReplApplication.BOLD, item['name'], ReplApplication.NC) + result = u'%s%s%s\n' % (self.BOLD, item['name'], self.NC) result += 'ID: %s\n' % item['id'] result += 'Size: %s\n' % sizeof_fmt(item['size']) result += 'Seeders: %s\n' % item['seeders'] result += 'Leechers: %s\n' % item['leechers'] result += 'URL: %s\n' % item['url'] - result += '\n%sFiles%s\n' % (ReplApplication.BOLD, ReplApplication.NC) + result += '\n%sFiles%s\n' % (self.BOLD, self.NC) for f in item['files']: result += ' * %s\n' % f - result += '\n%sDescription%s\n' % (ReplApplication.BOLD, ReplApplication.NC) + result += '\n%sDescription%s\n' % (self.BOLD, self.NC) result += item['description'] return result @@ -68,9 +68,9 @@ class TorrentListFormatter(IFormatter): self.count += 1 if self.interactive: backend = item['id'].split('@', 1)[1] - result = u'%s* (%d) %s (%s)%s\n' % (ReplApplication.BOLD, self.count, item['name'], backend, ReplApplication.NC) + result = u'%s* (%d) %s (%s)%s\n' % (self.BOLD, self.count, item['name'], backend, self.NC) else: - result = u'%s* (%s) %s%s\n' % (ReplApplication.BOLD, item['id'], item['name'], ReplApplication.NC) + result = u'%s* (%s) %s%s\n' % (self.BOLD, item['id'], item['name'], self.NC) size = sizeof_fmt(item['size']) result += ' %10s (Seed: %2d / Leech: %2d)' % (size, item['seeders'], item['leechers']) return result diff --git a/weboob/applications/wetboobs/wetboobs.py b/weboob/applications/wetboobs/wetboobs.py index 3ca955f1..004127c9 100644 --- a/weboob/applications/wetboobs/wetboobs.py +++ b/weboob/applications/wetboobs/wetboobs.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Romain Bignon +# Copyright(C) 2010-2011 Romain Bignon # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ class ForecastsFormatter(IFormatter): pass def format_dict(self, item): - result = u'%s* %-15s%s (%s°%s - %s°%s)' % (ReplApplication.BOLD, '%s:' % item['date'], ReplApplication.NC, item['low'], item['unit'], item['high'], item['unit']) + result = u'%s* %-15s%s (%s°%s - %s°%s)' % (self.BOLD, '%s:' % item['date'], self.NC, item['low'], item['unit'], item['high'], item['unit']) if 'text' in item and item['text']: result += ' %s' % item['text'] return result @@ -48,7 +48,7 @@ class CurrentFormatter(IFormatter): else: date = item['date'] - result = u'%s%s%s: %s' % (ReplApplication.BOLD, date, ReplApplication.NC, item['temp']) + result = u'%s%s%s: %s' % (self.BOLD, date, self.NC, item['temp']) if 'unit' in item and item['unit']: result += u'°%s' % item['unit'] if 'text' in item and item['text']: @@ -66,9 +66,9 @@ class CitiesFormatter(IFormatter): self.count += 1 if self.interactive: backend = item['id'].split('@', 1)[1] - result = u'%s* (%d) %s (%s)%s' % (ReplApplication.BOLD, self.count, item['name'], backend, ReplApplication.NC) + result = u'%s* (%d) %s (%s)%s' % (self.BOLD, self.count, item['name'], backend, self.NC) else: - result = u'%s* (%s) %s%s' % (ReplApplication.BOLD, item['id'], item['name'], ReplApplication.NC) + result = u'%s* (%s) %s%s' % (self.BOLD, item['id'], item['name'], self.NC) return result class WetBoobs(ReplApplication): diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index f1c73ed6..9cb7fca6 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Christophe Benz +# Copyright(C) 2010-2011 Christophe Benz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,7 +55,6 @@ class MandatoryFieldsNotFound(Exception): class IFormatter(object): - MANDATORY_FIELDS = None def get_bold(self): @@ -86,7 +85,6 @@ class IFormatter(object): if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()): self.termrows = int(os.popen('stty size', 'r').read().split()[0]) - def after_format(self, formatted): if self.outfile != sys.stdout: with open(self.outfile, "a+") as outfile: