From 27876970f347c036a87ca079cb29607ef773f53e Mon Sep 17 00:00:00 2001 From: Nicolas Duhamel Date: Mon, 11 Apr 2011 14:37:24 +0200 Subject: [PATCH] backend stateful --- weboob/applications/videoob/videoob.py | 13 ++++++++++--- weboob/backends/canalplus/backend.py | 19 +++++++------------ weboob/backends/canalplus/browser.py | 4 ++-- weboob/capabilities/collection.py | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index 8533ecd8..3e9b9065 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -246,10 +246,16 @@ class Videoob(ReplApplication): def do_ls(self, line): self.videos = [] if len(self.working_dir) == 0: - for name in [b.NAME for b in self.weboob. iter_backends(caps=ICapCollection)]: + for name in [b.NAME for b in self.weboob.iter_backends(caps=ICapCollection)]: print name return 0 - for backend, rep in self.do('iter_resources', backends=self.working_dir[0]): + + backend = [b for b in self.enabled_backends if b.NAME == self.working_dir[0]][0] + + def do(backend): + return backend.iter_resources(self.working_dir[1:]) + + for backend, rep in self.do(do, backends=self.working_dir[0]): if isinstance(rep, BaseVideo): self.videos.append(rep) self.format(rep) @@ -311,6 +317,7 @@ class Videoob(ReplApplication): if len(self.working_dir) == 0: tmp = [b.NAME for b in self.weboob. iter_backends(caps=ICapCollection)] else: - tmp = [rep for backend, rep in self.do('iter_resources', backends=self.working_dir[0])] + backend = [b for b in self.enabled_backends if b.NAME == self.working_dir[0]][0] + tmp = [rep for rep in backend.iter_resources(self.working_dir[1:])] return [s[offs:] for s in tmp if s.startswith(mline)] diff --git a/weboob/backends/canalplus/backend.py b/weboob/backends/canalplus/backend.py index 9c71aded..9330fc6c 100644 --- a/weboob/backends/canalplus/backend.py +++ b/weboob/backends/canalplus/backend.py @@ -65,16 +65,11 @@ class CanalplusBackend(BaseBackend, ICapVideo, ICapCollection): return video OBJECTS = {CanalplusVideo: fill_video} - - working_coll = [] - - def get_working_collection(self): - return self.working_coll - - def change_working_collection(self, splited_path): - self.working_coll = self.browser.change_working_collection(splited_path) - return self.working_coll - def iter_resources(self): - rep = self.browser.iter_resources(self.working_coll) - return rep + def change_working_collection(self, splited_path): + with self.browser: + return self.browser.change_working_collection(splited_path) + + def iter_resources(self, splited_path): + with self.browser: + return self.browser.iter_resources(splited_path) diff --git a/weboob/backends/canalplus/browser.py b/weboob/backends/canalplus/browser.py index f4423d70..70dfff2b 100644 --- a/weboob/backends/canalplus/browser.py +++ b/weboob/backends/canalplus/browser.py @@ -94,7 +94,7 @@ class CanalplusBrowser(BaseBrowser): return walk(splited_path, collections) - def iter_resources(self, cur_coll): + def iter_resources(self, splited_path): self.home() collections = self.page.collections @@ -110,4 +110,4 @@ class CanalplusBrowser(BaseBrowser): return walk_res(path[1:], [collection.children for collection in collections if collection.title == i][0]) - return walk_res(cur_coll, collections) + return walk_res(splited_path, collections) diff --git a/weboob/capabilities/collection.py b/weboob/capabilities/collection.py index da37b892..baeb1275 100644 --- a/weboob/capabilities/collection.py +++ b/weboob/capabilities/collection.py @@ -67,5 +67,5 @@ class ICapCollection(IBaseCap): def change_working_collection(self, splited_path): raise NotImplementedError() - def iter_resources(self): + def iter_resources(self, splited_path): raise NotImplementedError()