diff --git a/weboob/frontends/http/scripts/http b/weboob/frontends/http/scripts/http index f135b1e5fa8aeedd0216945864df8366e787a270..db524b09019baa20a243a3873085a7dc852c50e5 100755 --- a/weboob/frontends/http/scripts/http +++ b/weboob/frontends/http/scripts/http @@ -35,7 +35,7 @@ class Application(BaseApplication): APPNAME = 'http' def main(self, argv): - self.weboob.load_modules() + self.weboob.load_backends() template_lookup = TemplateLookup(directories=['%s/../templates' % os.path.dirname(__file__)], output_encoding='utf-8', encoding_errors='replace') diff --git a/weboob/frontends/monboob/scripts/monboob b/weboob/frontends/monboob/scripts/monboob index a7c3a318d1151f7fe09e7182a4d8ca5bbd77525f..985232773a8ec173a4e6f71a06c51acf710426a6 100755 --- a/weboob/frontends/monboob/scripts/monboob +++ b/weboob/frontends/monboob/scripts/monboob @@ -40,14 +40,14 @@ class Monboob(BaseApplication): def main(self, argv): self.load_config() - if not self.myconfig: + if not self.config: print >>sys.stderr, "Error: %s is not configured yet. Please call 'monboob -c'" % argv[0] print >>sys.stderr, "Also, you need to use 'weboobcfg' to set backend configs" return -1 - self.weboob.load_modules(ICapMessages, backends=self.config.getbackends()) + self.weboob.load_modules(ICapMessages) - self.weboob.schedule(self.myconfig['interval'], self.process) + self.weboob.schedule(self.config.get('interval'), self.process) self.weboob.loop() def process(self): @@ -56,8 +56,8 @@ class Monboob(BaseApplication): self.send_email(name, message) def send_email(self, backend_name, mail): - domain = self.myconfig['domain'] - recipient = self.myconfig['recipient'] + domain = self.config.get('domain') + recipient = self.config.get('recipient') reply_id = '' if mail.get_reply_id(): @@ -111,7 +111,7 @@ class Monboob(BaseApplication): msg['In-Reply-To'] = reply_id # Send the message via SMTP to localhost:25 - smtp = SMTP(self.myconfig['smtp']) + smtp = SMTP(self.config.get('smtp')) smtp.sendmail(sender, recipient, msg.as_string()) smtp.quit() diff --git a/weboob/tools/application.py b/weboob/tools/application.py index 137c05e510a6f461efdca47675d9bfa8cb17e58b..ec07398c37c9cc6eb2e47b7d2876699c056a3f63 100644 --- a/weboob/tools/application.py +++ b/weboob/tools/application.py @@ -28,7 +28,7 @@ class BaseApplication(object): APPNAME = '' CONFIG = {} - CONFDIR = '%s/.weboob/' % os.path.expanduser("~") + CONFDIR = os.path.join(os.path.expanduser('~'), '.weboob') def __init__(self): self.weboob = Weboob(self.APPNAME) @@ -45,18 +45,16 @@ def load_config(self, path=None, klass=None): if klass is None: # load Config only here because some applications don't want # to depend on yaml and do not use this function - from weboob.tools.config import Config - klass = Config + from weboob.tools.config.yaml import YamlConfig + klass = YamlConfig if path is None: - path = self.CONFDIR + 'weboobrc' + path = os.path.join(self.CONFDIR, self.APPNAME) elif not path.startswith('/'): - path = self.CONFDIR + path + path = os.path.join(self.CONFDIR, path) self.config = klass(path) - self.config.load() - self.myconfig = self.CONFIG - self.myconfig.update(self.config.getfrontend(self.APPNAME)) + self.config.load(self.CONFIG) def main(self, argv): """ Main function """ diff --git a/weboob/tools/config/__init__.py b/weboob/tools/config/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/weboob/iconfig.py b/weboob/tools/config/iconfig.py similarity index 76% rename from weboob/iconfig.py rename to weboob/tools/config/iconfig.py index 5d4522c4982f445eb278a95dde4b4605d308dd17..f0f5bfe293e86c589f71337bf81a95b3a2bb0098 100644 --- a/weboob/iconfig.py +++ b/weboob/tools/config/iconfig.py @@ -20,14 +20,8 @@ class ConfigError(Exception): pass -class BackendConfig(object): - def __init__(self, name, _type, config): - self.name = name - self.type = _type - self.config = config - class IConfig: - def load(self): + def load(self, default={}): raise NotImplementedError() def save(self): @@ -38,9 +32,3 @@ def set(self, *args): def get(self, *args, **kwargs): raise NotImplementedError() - - def getfrontend(self, name): - raise NotImplementedError() - - def getbackends(self): - raise NotImplementedError() diff --git a/weboob/tools/config.py b/weboob/tools/config/yaml.py similarity index 78% rename from weboob/tools/config.py rename to weboob/tools/config/yaml.py index f504184a591259270963c5ec56c2565ccdcb9d0d..8b70f4eee6defb8ae6bfb3ccd6857eb08ff3032e 100644 --- a/weboob/tools/config.py +++ b/weboob/tools/config/yaml.py @@ -21,16 +21,17 @@ from __future__ import with_statement import yaml -from logging import warning -from weboob.iconfig import IConfig, ConfigError, BackendConfig +from .iconfig import IConfig, ConfigError -class Config(IConfig): +class YamlConfig(IConfig): def __init__(self, path): self.path = path self.values = {} - def load(self): + def load(self, default={}): + self.values = default.copy() + try: with open(self.path, 'r') as f: self.values = yaml.load(f) @@ -82,15 +83,3 @@ def set(self, *args): raise ConfigError() v[args[-2]] = args[-1] - - def getfrontend(self, name): - return self.get('frontends', name, default={}) - - def getbackends(self): - d = {} - for key, value in self.get('backends', default={}).iteritems(): - if not 'type' in value: - warning("Missing 'type' item in config of '%s' backend" % key) - else: - d[key] = BackendConfig(key, value['type'], value.get('config', {})) - return d