all loaded backends are now configured (refs #368)

This commit is contained in:
Romain Bignon 2010-08-19 22:13:01 +02:00
commit 9581fa0b19
15 changed files with 17 additions and 45 deletions

View file

@ -39,7 +39,7 @@ class Boobank(ConsoleApplication):
@ConsoleApplication.command('List every available accounts') @ConsoleApplication.command('List every available accounts')
def command_list(self): def command_list(self):
self.load_configured_backends(ICapBank) self.load_backends(ICapBank)
tot_balance = 0.0 tot_balance = 0.0
tot_coming = 0.0 tot_coming = 0.0
try: try:
@ -63,7 +63,7 @@ class Boobank(ConsoleApplication):
def command_history(self, id): def command_history(self, id):
id, backend_name = self.parse_id(id) id, backend_name = self.parse_id(id)
names = (backend_name,) if backend_name is not None else None names = (backend_name,) if backend_name is not None else None
self.load_configured_backends(ICapBank, names=names) self.load_backends(ICapBank, names=names)
def do(backend): def do(backend):
account = backend.get_account(id) account = backend.get_account(id)
@ -76,7 +76,7 @@ class Boobank(ConsoleApplication):
def command_coming(self, id): def command_coming(self, id):
id, backend_name = self.parse_id(id) id, backend_name = self.parse_id(id)
names = (backend_name,) if backend_name is not None else None names = (backend_name,) if backend_name is not None else None
self.load_configured_backends(ICapBank, names=names) self.load_backends(ICapBank, names=names)
def do(backend): def do(backend):
account = backend.get_account(id) account = backend.get_account(id)

View file

@ -32,7 +32,7 @@ class Chatoob(ConsoleApplication):
COPYRIGHT = 'Copyright(C) 2010 Christophe Benz' COPYRIGHT = 'Copyright(C) 2010 Christophe Benz'
def main(self, argv): def main(self, argv):
self.load_configured_backends(ICapChat) self.load_backends(ICapChat)
#for backend, result in self.do('start_chat_polling', self.on_new_chat_message): #for backend, result in self.do('start_chat_polling', self.on_new_chat_message):
#logging.info(u'Polling chat messages for backend %s' % backend) #logging.info(u'Polling chat messages for backend %s' % backend)
return self.process_command(*argv[1:]) return self.process_command(*argv[1:])

View file

@ -35,7 +35,7 @@ class Geolooc(ConsoleApplication):
print >>sys.stderr, 'Syntax: %s ipaddr' % argv[0] print >>sys.stderr, 'Syntax: %s ipaddr' % argv[0]
return 1 return 1
self.load_configured_backends(ICapGeolocIp) self.load_backends(ICapGeolocIp)
for backend, location in self.do('get_location', argv[1]): for backend, location in self.do('get_location', argv[1]):
self.format(location) self.format(location)

View file

@ -38,7 +38,7 @@ class HaveSex(PromptApplication):
def main(self, argv): def main(self, argv):
self.load_config() self.load_config()
self.load_configured_backends(ICapDating, storage=self.create_storage(self.STORAGE_FILENAME)) self.load_backends(ICapDating, storage=self.create_storage(self.STORAGE_FILENAME))
self.do('init_optimizations').wait() self.do('init_optimizations').wait()

View file

@ -93,7 +93,7 @@ class Monboob(ConsoleApplication):
def main(self, argv): def main(self, argv):
self.load_config() self.load_config()
self.load_configured_backends(ICapMessages, storage=self.create_storage()) self.load_backends(ICapMessages, storage=self.create_storage())
return self.process_command(*argv[1:]) return self.process_command(*argv[1:])

View file

@ -27,7 +27,7 @@ class QBoobMsg(QtApplication):
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon' COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
def main(self, argv): def main(self, argv):
self.load_configured_backends(ICapMessages, storage=self.create_storage()) self.load_backends(ICapMessages, storage=self.create_storage())
self.main_window = MainWindow(self.config, self.weboob) self.main_window = MainWindow(self.config, self.weboob)
self.main_window.show() self.main_window.show()

View file

@ -29,7 +29,7 @@ class QHaveSex(QtApplication):
def main(self, argv): def main(self, argv):
self.create_storage(self.STORAGE_FILENAME) self.create_storage(self.STORAGE_FILENAME)
self.load_configured_backends(ICapDating) self.load_backends(ICapDating)
self.main_window = MainWindow(self.config, self.weboob) self.main_window = MainWindow(self.config, self.weboob)
self.main_window.show() self.main_window.show()

View file

@ -27,7 +27,7 @@ class QWeboobCfg(QtApplication):
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon' COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
def main(self, argv): def main(self, argv):
self.load_configured_backends() self.load_backends()
self.dlg = BackendCfg(self.weboob) self.dlg = BackendCfg(self.weboob)
self.dlg.show() self.dlg.show()

View file

@ -29,9 +29,6 @@ class WeboobCli(ConsoleApplication):
VERSION = '0.1' VERSION = '0.1'
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon' COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
def add_application_options(self, group):
group.add_option('-C', '--configured', action='store_true', help='load configured backends')
def main(self, argv): def main(self, argv):
if len(argv) < 3: if len(argv) < 3:
print >>sys.stderr, "Syntax: %s capability command [args ..]" % argv[0] print >>sys.stderr, "Syntax: %s capability command [args ..]" % argv[0]
@ -41,10 +38,7 @@ class WeboobCli(ConsoleApplication):
cmd = argv[2] cmd = argv[2]
args = argv[3:] args = argv[3:]
if self.options.configured: self.load_backends(cap_s)
self.load_configured_backends(cap_s)
else:
self.load_backends(cap_s)
for backend, obj in self.do(cmd, *args): for backend, obj in self.do(cmd, *args):
self.format(obj) self.format(obj)

View file

@ -32,7 +32,7 @@ class Weboorrents(ConsoleApplication):
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon' COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
def main(self, argv): def main(self, argv):
self.load_configured_backends(ICapTorrent) self.load_backends(ICapTorrent)
return self.process_command(*argv[1:]) return self.process_command(*argv[1:])
@ConsoleApplication.command('Get information about a torrent') @ConsoleApplication.command('Get information about a torrent')

View file

@ -68,21 +68,7 @@ class Weboob(object):
def deinit(self): def deinit(self):
self.unload_backends() self.unload_backends()
def load_backends(self, caps=None, names=None, storage=None): def load_backends(self, caps=None, names=None, modules=None, storage=None):
loaded = {}
if storage is None:
storage = self.storage
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:
continue
backend_instance = backend.create_instance(self, backend_name, {}, storage)
self.backend_instances[backend_name] = loaded[backend_name] = backend_instance
return loaded
def load_configured_backends(self, caps=None, names=None, modules=None, storage=None):
loaded = {} loaded = {}
if storage is None: if storage is None:
storage = self.storage storage = self.storage

View file

@ -179,14 +179,6 @@ class BaseApplication(object):
logging.warning(u'No backend loaded') logging.warning(u'No backend loaded')
return loaded return loaded
def load_configured_backends(self, caps=None, names=None, *args, **kwargs):
if names is None:
names = self.requested_backends
loaded = self.weboob.load_configured_backends(caps, names, *args, **kwargs)
if not loaded:
logging.warning(u'No configured backend loaded')
return loaded
def _get_optparse_version(self): def _get_optparse_version(self):
version = None version = None
if self.VERSION: if self.VERSION:

View file

@ -273,8 +273,8 @@ class ConsoleApplication(BaseApplication):
register_command = staticmethod(register_command) register_command = staticmethod(register_command)
command = staticmethod(command) command = staticmethod(command)
def load_configured_backends(self, caps=None, names=None, *args, **kwargs): def load_backends(self, caps=None, names=None, *args, **kwargs):
loaded_backends = BaseApplication.load_configured_backends(self, caps, names, *args, **kwargs) loaded_backends = BaseApplication.load_backends(self, caps, names, *args, **kwargs)
if not loaded_backends: if not loaded_backends:
logging.error(u'Cannot start application: no configured backend was found.\nHere is a list of all available backends:') logging.error(u'Cannot start application: no configured backend was found.\nHere is a list of all available backends:')
from weboob.applications.weboobcfg import WeboobCfg from weboob.applications.weboobcfg import WeboobCfg

View file

@ -310,6 +310,6 @@ class BackendCfg(QDialog):
ret = (len(self.to_load) > 0 or len(self.to_unload) > 0) ret = (len(self.to_load) > 0 or len(self.to_unload) > 0)
self.weboob.unload_backends(self.to_unload) self.weboob.unload_backends(self.to_unload)
self.weboob.load_configured_backends(names=self.to_load) self.weboob.load_backends(names=self.to_load)
return ret return ret

View file

@ -32,7 +32,7 @@ class BackendTest(TestCase):
self.backend = None self.backend = None
self.weboob = Weboob() self.weboob = Weboob()
if self.weboob.load_configured_backends(modules=[self.BACKEND]): if self.weboob.load_backends(modules=[self.BACKEND]):
self.backend = choice(self.weboob.backend_instances.values()) self.backend = choice(self.weboob.backend_instances.values())
def run(self, result): def run(self, result):