From f4f9ef25f48a34c19707d95ad8dd522af3fea68f Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 25 Sep 2010 02:16:07 -0400 Subject: [PATCH] fixes when no backends are loaded --- weboob/applications/videoob/videoob.py | 7 +++++++ weboob/tools/application/repl.py | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index 230618ed..0eb897ae 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -224,6 +224,13 @@ class Videoob(ReplApplication): If PATTERN is not given, this command will search for the latest videos. """ + if len(self.enabled_backends) == 0: + if self.interactive: + print 'No backend loaded. Please use the "backends" command.' + else: + print 'No backend loaded.' + return 1 + self.set_formatter_header(u'Search pattern: %s' % pattern if pattern else u'Latest videos') self.videos = [] for backend, video in self.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw, diff --git a/weboob/tools/application/repl.py b/weboob/tools/application/repl.py index 92e9f178..a28159c5 100644 --- a/weboob/tools/application/repl.py +++ b/weboob/tools/application/repl.py @@ -488,8 +488,8 @@ class ReplApplication(Cmd, BaseApplication): for backend in given_backends: try: self.enabled_backends.remove(backend) - except KeyError: - print '%s is not enabled' % backend + except ValueError: + print '%s is not enabled' % backend.name elif action == 'only': self.enabled_backends = set() for backend in given_backends: @@ -508,11 +508,14 @@ class ReplApplication(Cmd, BaseApplication): self.weboob.unload_backends(backend.name) try: self.enabled_backends.remove(backend) - except KeyError: + except ValueError: pass else: print 'Unknown action: "%s"' % action - return False + return 1 + + if len(self.enabled_backends) == 0: + print 'Warning: no more backends are loaded. %s is probably unusable.' % self.APPNAME.capitalize() def complete_backends(self, text, line, begidx, endidx): choices = [] @@ -523,14 +526,14 @@ class ReplApplication(Cmd, BaseApplication): args = line.split(' ') if len(args) == 2: choices = commands - elif len(args) == 3: + elif len(args) >= 3: if args[1] == 'enable': choices = sorted(available_backends_names - enabled_backends_names) elif args[1] == 'only': choices = sorted(available_backends_names) elif args[1] == 'disable': choices = sorted(enabled_backends_names) - elif args[1] == 'add': + elif args[1] == 'add' and len(args) == 3: self.weboob.modules_loader.load_all() for name, module in sorted(self.weboob.modules_loader.loaded.iteritems()): if not self.CAPS or self.caps_included(module.iter_caps(), self.CAPS.__name__):