Add module_name param in add_backend to allow command line interaction
This commit is contained in:
parent
a1eea6a098
commit
7155539965
3 changed files with 29 additions and 21 deletions
|
|
@ -100,12 +100,19 @@ class WeboobCfg(ReplApplication):
|
|||
if not line:
|
||||
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
|
||||
return 2
|
||||
name, options = self.parse_command_args(line, 2, 1)
|
||||
module_name, options = self.parse_command_args(line, 2, 1)
|
||||
if options:
|
||||
options = options.split(' ')
|
||||
else:
|
||||
options = ()
|
||||
|
||||
backend_name = module_name
|
||||
try:
|
||||
k, v = options[0].split('=',1)
|
||||
except ValueError:
|
||||
backend_name = options[0]
|
||||
del options[0]
|
||||
|
||||
params = {}
|
||||
# set backend params from command-line arguments
|
||||
for option in options:
|
||||
|
|
@ -116,7 +123,7 @@ class WeboobCfg(ReplApplication):
|
|||
return 2
|
||||
params[key] = value
|
||||
|
||||
self.add_backend(name, params)
|
||||
self.add_backend(module_name, backend_name, params)
|
||||
|
||||
def do_register(self, line):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class ConsoleApplication(Application):
|
|||
continue
|
||||
name = modules[i]
|
||||
try:
|
||||
inst = self.add_backend(name, default_config)
|
||||
inst = self.add_backend(name, name, default_config)
|
||||
if inst:
|
||||
self.load_backends(names=[inst])
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
|
|
@ -183,7 +183,7 @@ class ConsoleApplication(Application):
|
|||
for name in modules:
|
||||
if name in [b.NAME for b in self.weboob.iter_backends()]:
|
||||
continue
|
||||
inst = self.add_backend(name, default_config)
|
||||
inst = self.add_backend(name, name, default_config)
|
||||
if inst:
|
||||
self.load_backends(names=[inst])
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
|
|
@ -297,7 +297,7 @@ class ConsoleApplication(Application):
|
|||
backend_config[key] = value.get()
|
||||
|
||||
if ask_add and self.ask('Do you want to add the new register account?', default=True):
|
||||
return self.add_backend(name, backend_config, ask_register=False)
|
||||
return self.add_backend(name, name, backend_config, ask_register=False)
|
||||
|
||||
return backend_config
|
||||
|
||||
|
|
@ -312,9 +312,9 @@ class ConsoleApplication(Application):
|
|||
return True
|
||||
|
||||
def edit_backend(self, name, params=None):
|
||||
return self.add_backend(name, params, True)
|
||||
return self.add_backend(name, name, params, True)
|
||||
|
||||
def add_backend(self, name, params=None, edit=False, ask_register=True):
|
||||
def add_backend(self, module_name, backend_name, params=None, edit=False, ask_register=True):
|
||||
if params is None:
|
||||
params = {}
|
||||
|
||||
|
|
@ -322,22 +322,22 @@ class ConsoleApplication(Application):
|
|||
config = None
|
||||
try:
|
||||
if not edit:
|
||||
minfo = self.weboob.repositories.get_module_info(name)
|
||||
minfo = self.weboob.repositories.get_module_info(module_name)
|
||||
if minfo is None:
|
||||
raise ModuleLoadError(name, 'Module does not exist')
|
||||
raise ModuleLoadError(module_name, 'Module does not exist')
|
||||
if not minfo.is_installed():
|
||||
print('Module "%s" is available but not installed.' % minfo.name)
|
||||
self.install_module(minfo)
|
||||
module = self.weboob.modules_loader.get_or_load_module(name)
|
||||
module = self.weboob.modules_loader.get_or_load_module(module_name)
|
||||
config = module.config
|
||||
else:
|
||||
bname, items = self.weboob.backends_config.get_backend(name)
|
||||
bname, items = self.weboob.backends_config.get_backend(backend_name)
|
||||
module = self.weboob.modules_loader.get_or_load_module(bname)
|
||||
items.update(params)
|
||||
params = items
|
||||
config = module.config.load(self.weboob, bname, name, params, nofail=True)
|
||||
config = module.config.load(self.weboob, bname, backend_name, params, nofail=True)
|
||||
except ModuleLoadError as e:
|
||||
print('Unable to load module "%s": %s' % (name, e), file=self.stderr)
|
||||
print('Unable to load module "%s": %s' % (module_name, e), file=self.stderr)
|
||||
return 1
|
||||
|
||||
# ask for params non-specified on command-line arguments
|
||||
|
|
@ -355,24 +355,25 @@ class ConsoleApplication(Application):
|
|||
if asked_config:
|
||||
print('-------------------------%s' % ('-' * len(module.name)))
|
||||
|
||||
while not edit and self.weboob.backends_config.backend_exists(name):
|
||||
print('Backend instance "%s" already exists in "%s"' % (name, self.weboob.backends_config.confpath), file=self.stderr)
|
||||
while not edit and self.weboob.backends_config.backend_exists(backend_name):
|
||||
print('Backend instance "%s" already exists in "%s"' % (backend_name, self.weboob.backends_config.confpath), file=self.stderr)
|
||||
if not self.ask('Add new backend for module "%s"?' % module.name, default=False):
|
||||
return 1
|
||||
|
||||
name = self.ask('Please give new instance name', default='%s2' % name, regexp=r'^[\w\-_]+$')
|
||||
# TODO : Probably smarter to increment max existing backend, instead of fixed suffix
|
||||
backend_name = self.ask('Please give new instance name', default='%s2' % module_name, regexp=r'^[\w\-_]+$')
|
||||
|
||||
try:
|
||||
config = config.load(self.weboob, module.name, name, params, nofail=True)
|
||||
config = config.load(self.weboob, module.name, backend_name, params, nofail=True)
|
||||
for key, value in params.iteritems():
|
||||
if key.startswith('_'):
|
||||
continue
|
||||
config[key].set(value)
|
||||
config.save(edit=edit)
|
||||
print('Backend "%s" successfully %s.' % (name, 'edited' if edit else 'added'))
|
||||
return name
|
||||
print('Backend "%s" successfully %s.' % (backend_name, 'edited' if edit else 'added'))
|
||||
return backend_name
|
||||
except BackendAlreadyExists:
|
||||
print('Backend "%s" already exists.' % name, file=self.stderr)
|
||||
print('Backend "%s" already exists.' % backend_name, file=self.stderr)
|
||||
return 1
|
||||
|
||||
def ask(self, question, default=None, masked=None, regexp=None, choices=None, tiny=None):
|
||||
|
|
|
|||
|
|
@ -711,7 +711,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
print('Disabled: %s' % ', '.join(disabled_backends_names))
|
||||
elif action == 'add':
|
||||
for name in given_backend_names:
|
||||
instname = self.add_backend(name)
|
||||
instname = self.add_backend(name, name)
|
||||
if instname:
|
||||
self.load_backends(names=[instname])
|
||||
elif action == 'register':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue