use Value* classes instead of ConfigField
This commit is contained in:
parent
f995d86023
commit
2d2a942494
12 changed files with 59 additions and 72 deletions
|
|
@ -20,6 +20,7 @@ from __future__ import with_statement
|
|||
|
||||
from weboob.capabilities.video import ICapVideo
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import ArteBrowser
|
||||
from .video import ArteVideo
|
||||
|
|
@ -35,9 +36,8 @@ class ArteBackend(BaseBackend, ICapVideo):
|
|||
VERSION = '0.3'
|
||||
DESCRIPTION = 'Arte french TV'
|
||||
LICENSE = 'GPLv3'
|
||||
CONFIG = {'lang': BaseBackend.ConfigField(default='fr', description='Lang of videos', choices=['fr', 'de', 'en']),
|
||||
'quality': BaseBackend.ConfigField(default='hd', description='Quality of video', choices=['hd', 'sd']),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('lang', label='Lang of videos', choices={'fr': 'French', 'de': 'Deutsch', 'en': 'English'}, default='fr'),
|
||||
Value('quality', label='Quality of videos', choices=['hd', 'sd'], default='hd'))
|
||||
BROWSER = ArteBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import BNPorc
|
||||
|
||||
|
|
@ -32,13 +33,12 @@ class BNPorcBackend(BaseBackend, ICapBank):
|
|||
VERSION = '0.3'
|
||||
LICENSE = 'GPLv3'
|
||||
DESCRIPTION = 'BNP Paribas french bank\' website'
|
||||
CONFIG = {'login': BaseBackend.ConfigField(description='Account ID'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||
'rotating_password': BaseBackend.ConfigField(
|
||||
description='Password to set when the allowed uses are exhausted (6 digits)',
|
||||
default='',
|
||||
regexp='^(\d{6}|)$'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('login', label='Account ID'),
|
||||
Value('password', label='Password', masked=True),
|
||||
Value('rotating_password',
|
||||
label='Password to set when the allowed uses are exhausted (6 digits)',
|
||||
default='',
|
||||
regexp='^(\d{6}|)$'))
|
||||
BROWSER = BNPorc
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import BPbrowser
|
||||
|
||||
|
|
@ -29,9 +30,8 @@ class BPBackend(BaseBackend, ICapBank):
|
|||
VERSION = '0.3'
|
||||
LICENSE = 'GPLv3'
|
||||
DESCRIPTION = u'La banque postale, French bank'
|
||||
CONFIG = {'login': BaseBackend.ConfigField(description='Account ID'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True)
|
||||
}
|
||||
CONFIG = ValuesDict(Value('login', label='Account ID'),
|
||||
Value('password', label='Password', masked=True))
|
||||
BROWSER = BPbrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@
|
|||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import Cragr
|
||||
|
||||
|
||||
__all__ = ['CragrBackend']
|
||||
|
||||
|
||||
class CragrBackend(BaseBackend, ICapBank):
|
||||
NAME = 'cragr'
|
||||
MAINTAINER = 'Laurent Bachelier'
|
||||
|
|
@ -29,10 +33,9 @@ class CragrBackend(BaseBackend, ICapBank):
|
|||
VERSION = '0.3'
|
||||
DESCRIPTION = 'Credit Agricole french bank\'s website'
|
||||
LICENSE = 'GPLv3'
|
||||
CONFIG = {'login': BaseBackend.ConfigField(description='Account ID'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||
'website': BaseBackend.ConfigField(description='What website to use', default='m.lefil.com'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('website', label='Website to use', default='m.lefil.com'),
|
||||
Value('login', label='Account ID'),
|
||||
Value('password', label='Password', masked=True))
|
||||
BROWSER = Cragr
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from __future__ import with_statement
|
|||
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from weboob.tools.value import Value, ValueBool, ValuesDict
|
||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message, Thread, CantSendMessage
|
||||
|
||||
from .browser import DLFP
|
||||
|
|
@ -35,11 +36,10 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost):
|
|||
VERSION = '0.3'
|
||||
LICENSE = 'GPLv3'
|
||||
DESCRIPTION = "Da Linux French Page"
|
||||
CONFIG = {'username': BaseBackend.ConfigField(description='Username on website', regexp='.+'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', regexp='.+', is_masked=True),
|
||||
'get_news': BaseBackend.ConfigField(default=True, description='Get newspapers'),
|
||||
'get_telegrams': BaseBackend.ConfigField(default=False, description='Get telegrams'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('username', label='Username', regexp='.+'),
|
||||
Value('password', label='Password', regexp='.+', masked=True),
|
||||
ValueBool('get_news', label='Get newspapers', default=True),
|
||||
ValueBool('get_telegrams', label='Get telegrams', default=False))
|
||||
STORAGE = {'seen': {}}
|
||||
BROWSER = DLFP
|
||||
RSS_TELEGRAMS= "https://linuxfr.org/backend/journaux/rss20.rss"
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from logging import warning
|
|||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import Value, ValuesDict
|
||||
|
||||
from .browser import FourChan
|
||||
|
||||
|
|
@ -36,8 +37,7 @@ class FourChanBackend(BaseBackend, ICapMessages):
|
|||
VERSION = '0.3'
|
||||
LICENSE = 'GPLv3'
|
||||
DESCRIPTION = "4chan website"
|
||||
CONFIG = {'boards': BaseBackend.ConfigField(description='Boards'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('boards', label='Boards to fetch'))
|
||||
STORAGE = {'boards': {}}
|
||||
BROWSER = FourChan
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
from weboob.capabilities.torrent import ICapTorrent
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import GazelleBrowser
|
||||
|
||||
|
|
@ -31,11 +32,10 @@ class GazelleBackend(BaseBackend, ICapTorrent):
|
|||
VERSION = '0.3'
|
||||
DESCRIPTION = 'gazelle bittorrent tracker'
|
||||
LICENSE = 'GPLv3'
|
||||
CONFIG = {'username': BaseBackend.ConfigField(description='Username on website'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||
'protocol': BaseBackend.ConfigField(description='Protocol to use', choices=('http', 'https')),
|
||||
'domain': BaseBackend.ConfigField(description='Domain (example "ssl.what.cd")'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('domain', label='Domain (example "ssl.what.cd")'),
|
||||
Value('protocol', label='Protocol to use', choices=('http', 'https')),
|
||||
Value('username', label='Username'),
|
||||
Value('password', label='Password', masked=True))
|
||||
BROWSER = GazelleBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from weboob.capabilities.geolocip import ICapGeolocIp, IpLocation
|
|||
from weboob.capabilities.base import NotAvailable
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
|
||||
__all__ = ['GeolocIpBackend']
|
||||
|
|
@ -33,9 +34,8 @@ class GeolocIpBackend(BaseBackend, ICapGeolocIp):
|
|||
VERSION = '0.3'
|
||||
LICENSE = 'GPLv3'
|
||||
DESCRIPTION = u"IP Adresses geolocalisation"
|
||||
CONFIG = {'email': BaseBackend.ConfigField(description='Username on website'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('email', label='Username'),
|
||||
Value('password',label='Password', masked=True))
|
||||
BROWSER = BaseBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import LCLBrowser
|
||||
|
||||
|
|
@ -32,10 +33,9 @@ class LCLBackend(BaseBackend, ICapBank):
|
|||
VERSION = '0.3'
|
||||
DESCRIPTION = 'Le Credit Lyonnais crappy french bank'
|
||||
LICENSE = 'GPLv3'
|
||||
CONFIG = {'login': BaseBackend.ConfigField(description='Account ID'),
|
||||
'password': BaseBackend.ConfigField(description='Password of account', is_masked=True),
|
||||
'agency': BaseBackend.ConfigField(description='Agency code', regexp='^\d{1,3}$'),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('login', label='Account ID'),
|
||||
Value('password', label='Password of account', masked=True),
|
||||
Value('agency', label='Agency code', regexp='^\d{1,3}$'))
|
||||
BROWSER = LCLBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@
|
|||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from weboob.tools.value import Value, ValuesDict
|
||||
|
||||
|
||||
__all__ = ['NewsfeedBackend']
|
||||
|
||||
|
||||
class NewsfeedBackend(BaseBackend, ICapMessages):
|
||||
|
|
@ -30,7 +32,7 @@ class NewsfeedBackend(BaseBackend, ICapMessages):
|
|||
VERSION = "0.3"
|
||||
DESCRIPTION = "Loads RSS and Atom feeds from any websites"
|
||||
LICENSE = "GPLv3"
|
||||
CONFIG = {'url': BaseBackend.ConfigField(description="Atom/RSS feed's url"),}
|
||||
CONFIG = ValuesDict(Value('url', label="Atom/RSS feed's url"))
|
||||
STORAGE = {'seen': []}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from __future__ import with_statement
|
|||
|
||||
from weboob.capabilities.content import ICapContent, Content
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.value import ValuesDict, Value
|
||||
|
||||
from .browser import RedmineBrowser
|
||||
|
||||
|
|
@ -34,10 +35,9 @@ class RedmineBackend(BaseBackend, ICapContent):
|
|||
VERSION = '0.3'
|
||||
DESCRIPTION = 'The Redmine project management web application'
|
||||
LICENSE = 'GPLv3'
|
||||
CONFIG = {'url': BaseBackend.ConfigField(description='URL of the Redmine'),
|
||||
'username': BaseBackend.ConfigField(description='Login'),
|
||||
'password': BaseBackend.ConfigField(description='Password', is_masked=True),
|
||||
}
|
||||
CONFIG = ValuesDict(Value('url', label='URL of the Redmine website'),
|
||||
Value('username', label='Login'),
|
||||
Value('password', label='Password', masked=True))
|
||||
BROWSER = RedmineBrowser
|
||||
|
||||
def create_default_browser(self):
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
import re
|
||||
import os
|
||||
from threading import RLock
|
||||
from logging import debug
|
||||
|
|
@ -72,7 +71,7 @@ class BaseBackend(object):
|
|||
# Icon file path
|
||||
ICON = None
|
||||
# Configuration required for this backend.
|
||||
# Values must be ConfigField objects.
|
||||
# Values must be weboob.tools.value.Value objects.
|
||||
CONFIG = {}
|
||||
# Storage
|
||||
STORAGE = {}
|
||||
|
|
@ -85,14 +84,6 @@ class BaseBackend(object):
|
|||
# NOT yet filled.
|
||||
OBJECTS = {}
|
||||
|
||||
class ConfigField(object):
|
||||
def __init__(self, default=None, is_masked=False, regexp=None, description=None, choices=None):
|
||||
self.default = default
|
||||
self.is_masked = is_masked
|
||||
self.regexp = regexp
|
||||
self.description = description
|
||||
self.choices = choices
|
||||
|
||||
class ConfigError(Exception): pass
|
||||
|
||||
def __enter__(self):
|
||||
|
|
@ -115,29 +106,20 @@ class BaseBackend(object):
|
|||
# Configuration of backend
|
||||
self.config = {}
|
||||
for name, field in self.CONFIG.iteritems():
|
||||
value = config.get(name, field.default)
|
||||
value = config.get(name, None)
|
||||
|
||||
if value is None:
|
||||
raise BaseBackend.ConfigError('Missing parameter "%s" (%s)' % (name, field.description))
|
||||
if field.required:
|
||||
raise BaseBackend.ConfigError('Backend(%s): Configuration error: Missing parameter "%s" (%s)' % (self.name, name, field.description))
|
||||
value = field.default
|
||||
|
||||
if field.regexp and not re.match(field.regexp, str(value)):
|
||||
raise BaseBackend.ConfigError('Value of "%s" does not match regexp "%s"' % (name, field.regexp))
|
||||
try:
|
||||
field.set_value(value)
|
||||
except ValueError, v:
|
||||
raise BaseBackend.ConfigError('Backend(%s): Configuration error for field "%s": %s' % (self.name, name, v))
|
||||
|
||||
if not field.default is None:
|
||||
if isinstance(field.default, bool) and not isinstance(value, bool):
|
||||
value = value.lower() in ('1', 'true', 'on', 'yes')
|
||||
elif isinstance(field.default, int) and not isinstance(value, int):
|
||||
value = int(value)
|
||||
elif isinstance(field.default, float) and not isinstance(value, float):
|
||||
value = float(value)
|
||||
|
||||
if field.choices:
|
||||
if (isinstance(field.choices, (tuple,list)) and not value in field.choices) or \
|
||||
(isinstance(field.choices, dict) and not value in field.choices.iterkeys()):
|
||||
raise BaseBackend.ConfigError('Value of "%s" might be in this list: %s' % (name,
|
||||
', '.join([s for s in (field.choices.iterkeys() if isinstance(field.choices, dict)
|
||||
else field.choices)])))
|
||||
self.config[name] = value
|
||||
# field.value is a property which converts string to right type (bool/int/float)
|
||||
self.config[name] = field.value
|
||||
self.storage = BackendStorage(self.name, storage)
|
||||
self.storage.load(self.STORAGE)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue