add commands 'backends add' and 'backends remove'
This commit is contained in:
parent
04037e7893
commit
1e6de0f12e
1 changed files with 35 additions and 11 deletions
|
|
@ -175,7 +175,8 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
|
|
||||||
def load_backends(self, *args, **kwargs):
|
def load_backends(self, *args, **kwargs):
|
||||||
ret = super(ReplApplication, self).load_backends(*args, **kwargs)
|
ret = super(ReplApplication, self).load_backends(*args, **kwargs)
|
||||||
self.enabled_backends = list(self.weboob.iter_backends())
|
for name, backend in ret.iteritems():
|
||||||
|
self.enabled_backends.append(backend)
|
||||||
while len(self.enabled_backends) == 0:
|
while len(self.enabled_backends) == 0:
|
||||||
print 'Warning: there is currently no configured backend for %s' % self.APPNAME
|
print 'Warning: there is currently no configured backend for %s' % self.APPNAME
|
||||||
if not self.ask('Do you want to configure backends?', default=True):
|
if not self.ask('Do you want to configure backends?', default=True):
|
||||||
|
|
@ -213,7 +214,7 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
try:
|
try:
|
||||||
inst = self.add_backend(name)
|
inst = self.add_backend(name)
|
||||||
if inst:
|
if inst:
|
||||||
self.load_backends(names=inst)
|
self.load_backends(names=[inst])
|
||||||
except (KeyboardInterrupt,EOFError):
|
except (KeyboardInterrupt,EOFError):
|
||||||
print '\nAborted.'
|
print '\nAborted.'
|
||||||
|
|
||||||
|
|
@ -451,6 +452,8 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
* disable disable given backends
|
* disable disable given backends
|
||||||
* only enable given backends and disable the others
|
* only enable given backends and disable the others
|
||||||
* list display enabled and available backends
|
* list display enabled and available backends
|
||||||
|
* add add a backend
|
||||||
|
* remove remove a backend
|
||||||
"""
|
"""
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
|
|
@ -461,15 +464,16 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
action = args[0]
|
action = args[0]
|
||||||
given_backend_names = args[1:]
|
given_backend_names = args[1:]
|
||||||
|
|
||||||
skipped_backend_names = []
|
if action != 'add':
|
||||||
for backend_name in given_backend_names:
|
skipped_backend_names = []
|
||||||
if backend_name not in [backend.name for backend in self.weboob.iter_backends()]:
|
for backend_name in given_backend_names:
|
||||||
print 'Backend "%s" does not exist => skipping.' % backend_name
|
if backend_name not in [backend.name for backend in self.weboob.iter_backends()]:
|
||||||
skipped_backend_names.append(backend_name)
|
print 'Backend "%s" does not exist => skipping.' % backend_name
|
||||||
for skipped_backend_name in skipped_backend_names:
|
skipped_backend_names.append(backend_name)
|
||||||
given_backend_names.remove(skipped_backend_name)
|
for skipped_backend_name in skipped_backend_names:
|
||||||
|
given_backend_names.remove(skipped_backend_name)
|
||||||
|
|
||||||
if action in ('enable', 'disable', 'only'):
|
if action in ('enable', 'disable', 'only', 'add', 'remove'):
|
||||||
if not given_backend_names:
|
if not given_backend_names:
|
||||||
print 'Please give at least a backend name.'
|
print 'Please give at least a backend name.'
|
||||||
return
|
return
|
||||||
|
|
@ -492,13 +496,26 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
elif action == 'list':
|
elif action == 'list':
|
||||||
print 'Available: %s' % ', '.join(sorted(backend.name for backend in self.weboob.iter_backends()))
|
print 'Available: %s' % ', '.join(sorted(backend.name for backend in self.weboob.iter_backends()))
|
||||||
print 'Enabled: %s' % ', '.join(sorted(backend.name for backend in self.enabled_backends))
|
print 'Enabled: %s' % ', '.join(sorted(backend.name for backend in self.enabled_backends))
|
||||||
|
elif action == 'add':
|
||||||
|
for name in given_backend_names:
|
||||||
|
instname = self.add_backend(name)
|
||||||
|
if instname:
|
||||||
|
self.load_backends(names=[instname])
|
||||||
|
elif action == 'remove':
|
||||||
|
for backend in given_backends:
|
||||||
|
self.weboob.backends_config.remove_backend(backend.name)
|
||||||
|
self.weboob.unload_backends(backend.name)
|
||||||
|
try:
|
||||||
|
self.enabled_backends.remove(backend)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print 'Unknown action: "%s"' % action
|
print 'Unknown action: "%s"' % action
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def complete_backends(self, text, line, begidx, endidx):
|
def complete_backends(self, text, line, begidx, endidx):
|
||||||
choices = []
|
choices = []
|
||||||
commands = ['enable', 'disable', 'only', 'list']
|
commands = ['enable', 'disable', 'only', 'list', 'add', 'remove']
|
||||||
available_backends_names = set(backend.name for backend in self.weboob.iter_backends())
|
available_backends_names = set(backend.name for backend in self.weboob.iter_backends())
|
||||||
enabled_backends_names = set(backend.name for backend in self.enabled_backends)
|
enabled_backends_names = set(backend.name for backend in self.enabled_backends)
|
||||||
|
|
||||||
|
|
@ -512,6 +529,13 @@ class ReplApplication(Cmd, BaseApplication):
|
||||||
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':
|
||||||
|
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__):
|
||||||
|
choices.append(name)
|
||||||
|
elif args[1] == 'remove':
|
||||||
|
choices = sorted(available_backends_names)
|
||||||
|
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue