add the method Weboob.do_backends()
This commit is contained in:
parent
d900375a39
commit
35fa94e504
2 changed files with 21 additions and 1 deletions
|
|
@ -138,6 +138,8 @@ class BackendsCall(object):
|
|||
while self.errors:
|
||||
errback(*self.errors.pop())
|
||||
|
||||
callback(None, None)
|
||||
|
||||
def callback_thread(self, callback, errback=None):
|
||||
"""
|
||||
Call this method to create a thread which will callback a
|
||||
|
|
@ -151,7 +153,9 @@ class BackendsCall(object):
|
|||
def errback(backend, error)
|
||||
|
||||
"""
|
||||
return Thread(target=self._callback_thread_run, args=(callback, errback))
|
||||
thread = Thread(target=self._callback_thread_run, args=(callback, errback))
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
def __iter__(self):
|
||||
# Don't know how to factorize with _callback_thread_run
|
||||
|
|
|
|||
|
|
@ -138,6 +138,22 @@ class Weboob(object):
|
|||
backends = [b for b in self.iter_backends(caps)]
|
||||
return BackendsCall(backends, function, *args, **kwargs)
|
||||
|
||||
def do_backends(self, backends, function, *args, **kwargs):
|
||||
if isinstance(backends, (str,unicode)):
|
||||
backends = [backend for backend in self.iter_backends() if backend.name == backends]
|
||||
elif isinstance(backends, (list,tuple)):
|
||||
old_backends = backends
|
||||
backends = []
|
||||
for b in old_backends:
|
||||
if isinstance(b, (str,unicode)):
|
||||
try:
|
||||
backends.append(self.backends[self.backends.index(b)])
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
backends.append(b)
|
||||
return BackendsCall(backends, function, *args, **kwargs)
|
||||
|
||||
def schedule(self, interval, function, *args):
|
||||
return self.scheduler.schedule(interval, function, *args)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue