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