implement mandatory fields for custom formatters

This commit is contained in:
Christophe Benz 2010-11-23 14:46:32 +01:00
commit 560798bf7d
6 changed files with 37 additions and 1 deletions

View file

@ -26,13 +26,17 @@ from weboob.tools.application.formatters.iformatter import IFormatter
__all__ = ['Weboorrents']
def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%-4.1f%s" % (num, x)
num /= 1024.0
class TorrentInfoFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'name', 'size', 'seeders', 'leechers', 'url', 'files', 'description')
def flush(self):
pass
@ -50,7 +54,10 @@ class TorrentInfoFormatter(IFormatter):
result += item['description']
return result
class TorrentListFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'name', 'size', 'seeders', 'leechers')
count = 0
def flush(self):
@ -68,6 +75,7 @@ class TorrentListFormatter(IFormatter):
result += ' %10s (Seed: %2d / Leech: %2d)' % (size, item['seeders'], item['leechers'])
return result
class Weboorrents(ReplApplication):
APPNAME = 'weboorrents'
VERSION = '0.4'