Commit eca1e591 authored by Christophe Benz's avatar Christophe Benz

handle the case a backend is configured but not installed

parent 59b957d3
......@@ -25,7 +25,6 @@ import os
import re
import stat
import weboob.backends
from weboob.capabilities.cap import ICap
from weboob.tools.backend import BaseBackend
......@@ -171,9 +170,16 @@ class BackendsLoader(object):
def get_or_load_backend(self, backend_name):
if backend_name not in self.loaded:
self.load_backend(backend_name)
return self.loaded[backend_name]
if backend_name in self.loaded:
return self.loaded[backend_name]
else:
return None
def iter_existing_backend_names(self):
try:
import weboob.backends
except ImportError:
return
for path in weboob.backends.__path__:
regexp = re.compile('^%s/([\w\d_]+)$' % path)
for root, dirs, files in os.walk(path):
......
......@@ -47,7 +47,7 @@ class Weboob(object):
if not os.path.exists(self.workdir):
os.mkdir(self.workdir, 0700)
elif not os.path.isdir(self.workdir):
warning('"%s" is not a directory' % self.workdir)
warning(u'"%s" is not a directory' % self.workdir)
# Backends loader
self.backends_loader = BackendsLoader()
......@@ -64,7 +64,7 @@ class Weboob(object):
self.backends_loader.load_all()
for backend_name, backend in self.backends_loader.loaded.iteritems():
if caps is not None and not backend.has_caps(caps) or \
names is not None and backend_name not in names:
names is not None and backend_name not in names:
continue
backend_instance = backend.create_instance(self, backend_name, {}, storage)
self.backend_instances[backend_name] = loaded[backend_name] = backend_instance
......@@ -76,6 +76,11 @@ class Weboob(object):
if '_enabled' in params and not params['_enabled']:
continue
backend = self.backends_loader.get_or_load_backend(backend_name)
if backend is None:
warning(u'Backend "%s" is referenced in ~/.weboob/backends '
'configuration file, but was not found. '
'Hint: is it installed?' % backend_name)
continue
if caps is not None and not backend.has_caps(caps) or \
names is not None and instance_name not in names:
continue
......@@ -132,7 +137,7 @@ class Weboob(object):
else:
backends.append(backend)
else:
warning('The "backends" value isn\'t supported: %r' % _backends)
warning(u'The "backends" value isn\'t supported: %r' % _backends)
if 'caps' in kwargs:
caps = kwargs.pop('caps')
......
......@@ -63,6 +63,8 @@ class BackendCfg(QDialog):
def loadConfiguredBackendsList(self):
self.ui.configuredBackendsList.clear()
for instance_name, name, params in self.weboob.backends_config.iter_backends():
if name not in self.weboob.backends_loader.loaded:
continue
backend = self.weboob.backends_loader.loaded[name]
if self.caps and not backend.has_caps(*self.caps):
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment