factorize code to check loaded backends

This commit is contained in:
Romain Bignon 2011-04-05 08:44:42 +02:00
commit 3aa286fb94

View file

@ -82,11 +82,22 @@ class ConsoleApplication(BaseApplication):
for name, backend in ret.iteritems(): for name, backend in ret.iteritems():
self.enabled_backends.add(backend) self.enabled_backends.add(backend)
self.check_loaded_backends()
return ret
def check_loaded_backends(self, default_config=None):
while len(self.enabled_backends) == 0: while len(self.enabled_backends) == 0:
print 'Warning: there is currently no configured backend for %s' % self.APPNAME print 'Warning: there is currently no configured backend for %s' % self.APPNAME
if not self.ask('Do you want to configure backends?', default=True): if not self.ask('Do you want to configure backends?', default=True):
break return False
self.prompt_create_backends(default_config)
return True
def prompt_create_backends(self, default_config=None):
self.weboob.modules_loader.load_all() self.weboob.modules_loader.load_all()
r = '' r = ''
while r != 'q': while r != 'q':
@ -117,7 +128,7 @@ class ConsoleApplication(BaseApplication):
continue continue
name = backends[i] name = backends[i]
try: try:
inst = self.add_backend(name) inst = self.add_backend(name, default_config)
if inst: if inst:
self.load_backends(names=[inst]) self.load_backends(names=[inst])
except (KeyboardInterrupt, EOFError): except (KeyboardInterrupt, EOFError):
@ -125,8 +136,6 @@ class ConsoleApplication(BaseApplication):
print 'Right right!' print 'Right right!'
return ret
def _handle_options(self): def _handle_options(self):
self.load_default_backends() self.load_default_backends()