print an error if a specified backend is not enabled or existant

This commit is contained in:
Romain Bignon 2011-06-30 15:24:51 +02:00
commit 2804867a97
2 changed files with 10 additions and 8 deletions

View file

@ -33,11 +33,7 @@ from weboob.tools.backend import ObjectNotAvailable
from weboob.tools.log import createColoredFormatter, getLogger
__all__ = ['BackendNotFound', 'BaseApplication']
class BackendNotFound(Exception):
pass
__all__ = ['BaseApplication']
class ApplicationStorage(object):

View file

@ -30,7 +30,7 @@ from weboob.core.modules import ModuleLoadError
from weboob.tools.browser import BrowserUnavailable, BrowserIncorrectPassword
from weboob.tools.value import Value, ValueBool, ValueFloat, ValueInt
from .base import BackendNotFound, BaseApplication
from .base import BaseApplication
__all__ = ['ConsoleApplication', 'BackendNotGiven']
@ -43,6 +43,9 @@ class BackendNotGiven(Exception):
Exception.__init__(self, 'Please specify a backend to use for this argument (%s@backend_name). '
'Availables: %s.' % (id, ', '.join(name for name, backend in backends)))
class BackendNotFound(Exception):
pass
class ConsoleApplication(BaseApplication):
"""
Base application class for CLI applications.
@ -167,7 +170,8 @@ class ConsoleApplication(BaseApplication):
try:
super(ConsoleApplication, klass).run(args)
except BackendNotFound, e:
logging.error(e)
print 'Error: Backend "%s" not found.' % e
sys.exit(1)
def do(self, function, *args, **kwargs):
if not 'backends' in kwargs:
@ -179,12 +183,14 @@ class ConsoleApplication(BaseApplication):
_id, backend_name = _id.rsplit('@', 1)
except ValueError:
backend_name = None
backends = [(b.name, b) for b in self.enabled_backends]
if unique_backend and not backend_name:
backends = [(b.name, b) for b in self.enabled_backends]
if len(backends) == 1:
backend_name = backends[0]
else:
raise BackendNotGiven(_id, backends)
if not backend_name in dict(backends):
raise BackendNotFound(backend_name)
return _id, backend_name
def caps_included(self, modcaps, caps):