Table and Json formatters can write output to a file now.

Signed-off-by: Oleg Plakhotniuk <olegus8@gmail.com>

closes #1412
This commit is contained in:
Oleg Plakhotniuk 2014-06-20 15:31:44 -05:00 committed by Laurent Bachelier
commit 8875fad439
4 changed files with 39 additions and 8 deletions

View file

@ -18,8 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from prettytable import PrettyTable
from weboob.capabilities.base import empty
@ -42,7 +40,7 @@ class TableFormatter(IFormatter):
def flush(self):
s = self.get_formatted_table()
if s is not None:
print(s.encode('utf-8'))
self.output(s.encode('utf-8'))
def get_formatted_table(self):
if len(self.queue) == 0:
@ -101,3 +99,12 @@ class TableFormatter(IFormatter):
class HTMLTableFormatter(TableFormatter):
HTML = True
def test():
from .iformatter import formatter_test_output as fmt
assert fmt(TableFormatter, {'foo': 'bar'}) == \
'+-----+\n' \
'| Foo |\n' \
'+-----+\n' \
'| bar |\n' \
'+-----+\n'