add interactivity for adding backends

This commit is contained in:
Christophe Benz 2010-05-14 19:02:33 +02:00
commit 8763d20a08

View file

@ -56,9 +56,7 @@ class WeboobCfg(ConsoleApplication):
first_line = True first_line = True
for cap in module.iter_caps(): for cap in module.iter_caps():
if first_line: if first_line:
print ' %-14s %-21s %s' % (name, print ' %-14s %-21s %s' % (name, cap.__name__, module.get_description())
cap.__name__,
module.get_description())
first_line = False first_line = False
else: else:
print ' %s' % cap.__name__ print ' %s' % cap.__name__
@ -100,9 +98,11 @@ class WeboobCfg(ConsoleApplication):
@ConsoleApplication.command('Add a backend') @ConsoleApplication.command('Add a backend')
def command_add(self, type, name=None, *options): def command_add(self, name, *options):
if not name: self.weboob.modules_loader.load()
return self.command_modinfo(type) if name not in [module_name for module_name, module in self.weboob.modules_loader.modules.iteritems()]:
logging.error(u'Backend "%s" does not exist.' % name)
return 1
params = {} params = {}
for param in options: for param in options:
@ -114,24 +114,34 @@ class WeboobCfg(ConsoleApplication):
params[key] = value params[key] = value
try: try:
self.weboob.backends_config.add_backend(name, type, params) self.weboob.backends_config.add_backend(name, name, params)
print u'Backend "%s" successfully added' % name
except ConfigParser.DuplicateSectionError, e: except ConfigParser.DuplicateSectionError, e:
logging.error('Error: %s (filename=%s)' % (e, self.weboob.backends_config.confpath)) print u'Backend "%s" is already configured in file %s' % (name, self.weboob.backends_config.confpath)
return 1 response = raw_input(u'Add new instance of "%s" backend ? [yN] ' % name)
if response.lower() == 'y':
while True:
new_name = raw_input(u'Please give new instance name (could be "%s_1"): ' % name)
if not new_name:
continue
try:
self.weboob.backends_config.add_backend(new_name, name, params)
print u'Backend "%s" successfully added under instance name "%s"' % (name, instance_name)
break
except ConfigParser.DuplicateSectionError, e:
print u'Instance "%s" is already configured for backend "%s".' % (new_name, name)
@ConsoleApplication.command('List backends') @ConsoleApplication.command('List backends')
def command_list(self): def command_list(self):
print ' Name Type Params ' print ' Instance Name Name Params '
print '+--------------+--------------+------------------------------------------------+' print '+---------------+--------------+------------------------------------------------+'
for name, _type, params in self.weboob.backends_config.iter_backends(): for instance_name, name, params in self.weboob.backends_config.iter_backends():
print ' %-14s %-14s %-47s' % (name, print ' %-15s %-14s %-47s' % (instance_name, name, ', '.join('%s=%s' % (key, value) for key, value in params.iteritems()))
_type,
', '.join(['%s=%s' % (key, value) for key, value in params.iteritems()]))
@ConsoleApplication.command('Remove a backend') @ConsoleApplication.command('Remove a backend')
def command_remove(self, name): def command_remove(self, instance_name):
try: try:
self.weboob.backends_config.remove_backend(name) self.weboob.backends_config.remove_backend(instance_name)
except ConfigParser.NoSectionError: except ConfigParser.NoSectionError:
logging.error("Backend '%s' does not exist" % name) logging.error("Backend '%s' does not exist" % instance_name)
return 1 return 1