fixes when no backends are loaded

This commit is contained in:
Romain Bignon 2010-09-25 02:16:07 -04:00
commit f4f9ef25f4
2 changed files with 16 additions and 6 deletions

View file

@ -224,6 +224,13 @@ class Videoob(ReplApplication):
If PATTERN is not given, this command will search for the latest videos. 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.set_formatter_header(u'Search pattern: %s' % pattern if pattern else u'Latest videos')
self.videos = [] self.videos = []
for backend, video in self.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw, for backend, video in self.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw,

View file

@ -488,8 +488,8 @@ class ReplApplication(Cmd, BaseApplication):
for backend in given_backends: for backend in given_backends:
try: try:
self.enabled_backends.remove(backend) self.enabled_backends.remove(backend)
except KeyError: except ValueError:
print '%s is not enabled' % backend print '%s is not enabled' % backend.name
elif action == 'only': elif action == 'only':
self.enabled_backends = set() self.enabled_backends = set()
for backend in given_backends: for backend in given_backends:
@ -508,11 +508,14 @@ class ReplApplication(Cmd, BaseApplication):
self.weboob.unload_backends(backend.name) self.weboob.unload_backends(backend.name)
try: try:
self.enabled_backends.remove(backend) self.enabled_backends.remove(backend)
except KeyError: except ValueError:
pass pass
else: else:
print 'Unknown action: "%s"' % action 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): def complete_backends(self, text, line, begidx, endidx):
choices = [] choices = []
@ -523,14 +526,14 @@ class ReplApplication(Cmd, BaseApplication):
args = line.split(' ') args = line.split(' ')
if len(args) == 2: if len(args) == 2:
choices = commands choices = commands
elif len(args) == 3: elif len(args) >= 3:
if args[1] == 'enable': if args[1] == 'enable':
choices = sorted(available_backends_names - enabled_backends_names) choices = sorted(available_backends_names - enabled_backends_names)
elif args[1] == 'only': elif args[1] == 'only':
choices = sorted(available_backends_names) choices = sorted(available_backends_names)
elif args[1] == 'disable': elif args[1] == 'disable':
choices = sorted(enabled_backends_names) choices = sorted(enabled_backends_names)
elif args[1] == 'add': elif args[1] == 'add' and len(args) == 3:
self.weboob.modules_loader.load_all() self.weboob.modules_loader.load_all()
for name, module in sorted(self.weboob.modules_loader.loaded.iteritems()): 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__): if not self.CAPS or self.caps_included(module.iter_caps(), self.CAPS.__name__):