print an error if a specified backend is not enabled or existant
This commit is contained in:
parent
f99c6b31a8
commit
2804867a97
2 changed files with 10 additions and 8 deletions
|
|
@ -33,11 +33,7 @@ from weboob.tools.backend import ObjectNotAvailable
|
||||||
from weboob.tools.log import createColoredFormatter, getLogger
|
from weboob.tools.log import createColoredFormatter, getLogger
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['BackendNotFound', 'BaseApplication']
|
__all__ = ['BaseApplication']
|
||||||
|
|
||||||
|
|
||||||
class BackendNotFound(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationStorage(object):
|
class ApplicationStorage(object):
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ from weboob.core.modules import ModuleLoadError
|
||||||
from weboob.tools.browser import BrowserUnavailable, BrowserIncorrectPassword
|
from weboob.tools.browser import BrowserUnavailable, BrowserIncorrectPassword
|
||||||
from weboob.tools.value import Value, ValueBool, ValueFloat, ValueInt
|
from weboob.tools.value import Value, ValueBool, ValueFloat, ValueInt
|
||||||
|
|
||||||
from .base import BackendNotFound, BaseApplication
|
from .base import BaseApplication
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['ConsoleApplication', 'BackendNotGiven']
|
__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). '
|
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)))
|
'Availables: %s.' % (id, ', '.join(name for name, backend in backends)))
|
||||||
|
|
||||||
|
class BackendNotFound(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class ConsoleApplication(BaseApplication):
|
class ConsoleApplication(BaseApplication):
|
||||||
"""
|
"""
|
||||||
Base application class for CLI applications.
|
Base application class for CLI applications.
|
||||||
|
|
@ -167,7 +170,8 @@ class ConsoleApplication(BaseApplication):
|
||||||
try:
|
try:
|
||||||
super(ConsoleApplication, klass).run(args)
|
super(ConsoleApplication, klass).run(args)
|
||||||
except BackendNotFound, e:
|
except BackendNotFound, e:
|
||||||
logging.error(e)
|
print 'Error: Backend "%s" not found.' % e
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def do(self, function, *args, **kwargs):
|
def do(self, function, *args, **kwargs):
|
||||||
if not 'backends' in kwargs:
|
if not 'backends' in kwargs:
|
||||||
|
|
@ -179,12 +183,14 @@ class ConsoleApplication(BaseApplication):
|
||||||
_id, backend_name = _id.rsplit('@', 1)
|
_id, backend_name = _id.rsplit('@', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
backend_name = None
|
backend_name = None
|
||||||
if unique_backend and not backend_name:
|
|
||||||
backends = [(b.name, b) for b in self.enabled_backends]
|
backends = [(b.name, b) for b in self.enabled_backends]
|
||||||
|
if unique_backend and not backend_name:
|
||||||
if len(backends) == 1:
|
if len(backends) == 1:
|
||||||
backend_name = backends[0]
|
backend_name = backends[0]
|
||||||
else:
|
else:
|
||||||
raise BackendNotGiven(_id, backends)
|
raise BackendNotGiven(_id, backends)
|
||||||
|
if not backend_name in dict(backends):
|
||||||
|
raise BackendNotFound(backend_name)
|
||||||
return _id, backend_name
|
return _id, backend_name
|
||||||
|
|
||||||
def caps_included(self, modcaps, caps):
|
def caps_included(self, modcaps, caps):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue