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:
|
if not line:
|
||||||
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
|
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
|
||||||
return 2
|
return 2
|
||||||
name, options = self.parse_command_args(line, 2, 1)
|
module_name, options = self.parse_command_args(line, 2, 1)
|
||||||
if options:
|
if options:
|
||||||
options = options.split(' ')
|
options = options.split(' ')
|
||||||
else:
|
else:
|
||||||
options = ()
|
options = ()
|
||||||
|
|
||||||
|
backend_name = module_name
|
||||||
|
try:
|
||||||
|
k, v = options[0].split('=',1)
|
||||||
|
except ValueError:
|
||||||
|
backend_name = options[0]
|
||||||
|
del options[0]
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
# set backend params from command-line arguments
|
# set backend params from command-line arguments
|
||||||
for option in options:
|
for option in options:
|
||||||
|
|
@ -116,7 +123,7 @@ class WeboobCfg(ReplApplication):
|
||||||
return 2
|
return 2
|
||||||
params[key] = value
|
params[key] = value
|
||||||
|
|
||||||
self.add_backend(name, params)
|
self.add_backend(module_name, backend_name, params)
|
||||||
|
|
||||||
def do_register(self, line):
|
def do_register(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ class ConsoleApplication(Application):
|
||||||
continue
|
continue
|
||||||
name = modules[i]
|
name = modules[i]
|
||||||
try:
|
try:
|
||||||
inst = self.add_backend(name, default_config)
|
inst = self.add_backend(name, name, default_config)
|
||||||
if inst:
|
if inst:
|
||||||
self.load_backends(names=[inst])
|
self.load_backends(names=[inst])
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
|
@ -183,7 +183,7 @@ class ConsoleApplication(Application):
|
||||||
for name in modules:
|
for name in modules:
|
||||||
if name in [b.NAME for b in self.weboob.iter_backends()]:
|
if name in [b.NAME for b in self.weboob.iter_backends()]:
|
||||||
continue
|
continue
|
||||||
inst = self.add_backend(name, default_config)
|
inst = self.add_backend(name, name, default_config)
|
||||||
if inst:
|
if inst:
|
||||||
self.load_backends(names=[inst])
|
self.load_backends(names=[inst])
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
|
@ -297,7 +297,7 @@ class ConsoleApplication(Application):
|
||||||
backend_config[key] = value.get()
|
backend_config[key] = value.get()
|
||||||
|
|
||||||
if ask_add and self.ask('Do you want to add the new register account?', default=True):
|
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
|
return backend_config
|
||||||
|
|
||||||
|
|
@ -312,9 +312,9 @@ class ConsoleApplication(Application):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def edit_backend(self, name, params=None):
|
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:
|
if params is None:
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
|
|
@ -322,22 +322,22 @@ class ConsoleApplication(Application):
|
||||||
config = None
|
config = None
|
||||||
try:
|
try:
|
||||||
if not edit:
|
if not edit:
|
||||||
minfo = self.weboob.repositories.get_module_info(name)
|
minfo = self.weboob.repositories.get_module_info(module_name)
|
||||||
if minfo is None:
|
if minfo is None:
|
||||||
raise ModuleLoadError(name, 'Module does not exist')
|
raise ModuleLoadError(module_name, 'Module does not exist')
|
||||||
if not minfo.is_installed():
|
if not minfo.is_installed():
|
||||||
print('Module "%s" is available but not installed.' % minfo.name)
|
print('Module "%s" is available but not installed.' % minfo.name)
|
||||||
self.install_module(minfo)
|
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
|
config = module.config
|
||||||
else:
|
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)
|
module = self.weboob.modules_loader.get_or_load_module(bname)
|
||||||
items.update(params)
|
items.update(params)
|
||||||
params = items
|
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:
|
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
|
return 1
|
||||||
|
|
||||||
# ask for params non-specified on command-line arguments
|
# ask for params non-specified on command-line arguments
|
||||||
|
|
@ -355,24 +355,25 @@ class ConsoleApplication(Application):
|
||||||
if asked_config:
|
if asked_config:
|
||||||
print('-------------------------%s' % ('-' * len(module.name)))
|
print('-------------------------%s' % ('-' * len(module.name)))
|
||||||
|
|
||||||
while not edit and self.weboob.backends_config.backend_exists(name):
|
while not edit and self.weboob.backends_config.backend_exists(backend_name):
|
||||||
print('Backend instance "%s" already exists in "%s"' % (name, self.weboob.backends_config.confpath), file=self.stderr)
|
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):
|
if not self.ask('Add new backend for module "%s"?' % module.name, default=False):
|
||||||
return 1
|
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:
|
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():
|
for key, value in params.iteritems():
|
||||||
if key.startswith('_'):
|
if key.startswith('_'):
|
||||||
continue
|
continue
|
||||||
config[key].set(value)
|
config[key].set(value)
|
||||||
config.save(edit=edit)
|
config.save(edit=edit)
|
||||||
print('Backend "%s" successfully %s.' % (name, 'edited' if edit else 'added'))
|
print('Backend "%s" successfully %s.' % (backend_name, 'edited' if edit else 'added'))
|
||||||
return name
|
return backend_name
|
||||||
except BackendAlreadyExists:
|
except BackendAlreadyExists:
|
||||||
print('Backend "%s" already exists.' % name, file=self.stderr)
|
print('Backend "%s" already exists.' % backend_name, file=self.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def ask(self, question, default=None, masked=None, regexp=None, choices=None, tiny=None):
|
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))
|
print('Disabled: %s' % ', '.join(disabled_backends_names))
|
||||||
elif action == 'add':
|
elif action == 'add':
|
||||||
for name in given_backend_names:
|
for name in given_backend_names:
|
||||||
instname = self.add_backend(name)
|
instname = self.add_backend(name, name)
|
||||||
if instname:
|
if instname:
|
||||||
self.load_backends(names=[instname])
|
self.load_backends(names=[instname])
|
||||||
elif action == 'register':
|
elif action == 'register':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue