From 35fa94e5048cbe554725e27c56c9df06885da436 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 29 Apr 2010 22:24:05 +0200 Subject: [PATCH] add the method Weboob.do_backends() --- weboob/bcall.py | 6 +++++- weboob/ouiboube.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/weboob/bcall.py b/weboob/bcall.py index 727c9ef7..2d47b593 100644 --- a/weboob/bcall.py +++ b/weboob/bcall.py @@ -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 diff --git a/weboob/ouiboube.py b/weboob/ouiboube.py index 49bfaffd..c80beb10 100644 --- a/weboob/ouiboube.py +++ b/weboob/ouiboube.py @@ -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)