diff --git a/weboob/tools/application/base.py b/weboob/tools/application/base.py index 705405bd..66e5c5cd 100644 --- a/weboob/tools/application/base.py +++ b/weboob/tools/application/base.py @@ -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): diff --git a/weboob/tools/application/console.py b/weboob/tools/application/console.py index c5f6fdc0..a19bde27 100644 --- a/weboob/tools/application/console.py +++ b/weboob/tools/application/console.py @@ -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):