diff --git a/weboob/applications/weboobcfg/weboobcfg.py b/weboob/applications/weboobcfg/weboobcfg.py index cace8c47..21b2ed9a 100644 --- a/weboob/applications/weboobcfg/weboobcfg.py +++ b/weboob/applications/weboobcfg/weboobcfg.py @@ -72,6 +72,7 @@ class WeboobCfg(ConsoleApplication): params[key] = self.ask(' [%s] %s' % (key, value.description), default=value.default, masked=value.is_masked, + choices=value.choices, regexp=value.regexp) else: print ' [%s] %s: %s' % (key, value.description, '(masked)' if value.is_masked else params[key]) @@ -104,9 +105,10 @@ class WeboobCfg(ConsoleApplication): def command_listconfigured(self): self.set_default_formatter('table') for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()): + backend = self.weboob.backends_loader.get_or_load_backend(name) row = OrderedDict([('Instance name', instance_name), ('Backend name', name), - ('Configuration', ', '.join('%s=%s' % (key, value) for key, value in params.iteritems())), + ('Configuration', ', '.join('%s=%s' % (key, ('*****' if backend.config[key].is_masked else value)) for key, value in params.iteritems())), ]) self.format(row) diff --git a/weboob/backends/dlfp/backend.py b/weboob/backends/dlfp/backend.py index d7e93979..b2c4b287 100644 --- a/weboob/backends/dlfp/backend.py +++ b/weboob/backends/dlfp/backend.py @@ -35,8 +35,8 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesReply): VERSION = '0.1' LICENSE = 'GPLv3' DESCRIPTION = "Da Linux French Page" - CONFIG = {'username': BaseBackend.ConfigField(description='Username on website'), - 'password': BaseBackend.ConfigField(description='Password of account', is_masked=True), + CONFIG = {'username': BaseBackend.ConfigField(description='Username on website', regexp='.+'), + 'password': BaseBackend.ConfigField(description='Password of account', regexp='.+', is_masked=True), 'get_news': BaseBackend.ConfigField(default=True, description='Get newspapers'), 'get_telegrams': BaseBackend.ConfigField(default=False, description='Get telegrams'), } diff --git a/weboob/tools/application/console.py b/weboob/tools/application/console.py index 1e59b221..86b7152c 100644 --- a/weboob/tools/application/console.py +++ b/weboob/tools/application/console.py @@ -116,7 +116,7 @@ class ConsoleApplication(BaseApplication): def _get_completions(self): return set(name for name, arguments, doc_string in self._commands) - def ask(self, question, default=None, masked=False, regexp=None): + def ask(self, question, default=None, masked=False, regexp=None, choices=None): """ Ask a question to user. @@ -127,19 +127,39 @@ class ConsoleApplication(BaseApplication): @return entered text by user (str) """ + is_bool = False + + if choices: + question = u'%s (%s)' % (question, + '/'.join([s for s in (choices.iterkeys() if isinstance(choices, dict) + else choices)])) if default is not None: - question = u'%s [%s]' % (question, default) - hidden_msg = u'(input chars are hidden) ' if masked else '' - question = u'%s%s: ' % (hidden_msg, question) + if isinstance(default, bool): + question = u'%s (%s/%s)' % (question, 'Y' if default else 'y', + 'n' if default else 'N') + choices = ('y', 'n', 'Y', 'N') + default = 'y' if default else 'n' + is_bool = True + else: + question = u'%s [%s]' % (question, default) + + if masked: + question = u'(input chars are hidden) %s' % question + + question += ': ' correct = False while not correct: line = getpass.getpass(question) if masked else raw_input(question) if not line and default is not None: line = default - correct = not regexp or re.match(regexp, unicode(line)) + correct = (not regexp or re.match(regexp, unicode(line))) and \ + (not choices or unicode(line) in [unicode(s) for s in (choices.iterkeys() if isinstance(choices, dict) else choices)]) - return line + if is_bool: + return line.lower() == 'y' + else: + return line def process_command(self, command=None, *args): if command is None: