diff options
author | Sylvain <syt@logilab.fr> | 2007-10-17 16:32:46 +0200 |
---|---|---|
committer | Sylvain <syt@logilab.fr> | 2007-10-17 16:32:46 +0200 |
commit | a6f3fae040099f13f07e1b6a6ba6836a82d48868 (patch) | |
tree | e8222a7432c984e0db9fa534a2092fbd1e44ebd0 | |
parent | 5b99e7b0b2c3caba7c3dfb36969df11d57669c29 (diff) | |
download | logilab-common-a6f3fae040099f13f07e1b6a6ba6836a82d48868.tar.gz |
extract input_option method
-rw-r--r-- | configuration.py | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/configuration.py b/configuration.py index 279c3c4..97dd8d5 100644 --- a/configuration.py +++ b/configuration.py @@ -479,30 +479,11 @@ class OptionsManagerMixIn(object): for section, option, optdict in provider.all_options(): if onlysection is not None and section != onlysection: continue - default = provider.option_default(option, optdict) - if optdict['type'] == 'password': - defaultstr = ': ' - elif default is REQUIRED: - defaultstr = '(required): ' - else: - if optdict.get('inputlevel', 0) > inputlevel: - provider.set_option(option, default, opt_dict=optdict) - continue - defaultstr = '(default: %s): ' % format_option_value(optdict, default) - print ':%s:' % option - print optdict.get('help') or option - inputfunc = INPUT_FUNCTIONS[optdict['type']] - value = inputfunc(optdict, defaultstr) - while default is REQUIRED and not value: - print 'please specify a value' - value = inputfunc(optdict, '%s: ' % option) - if value is None and default is not None: - value = default - provider.set_option(option, value, opt_dict=optdict) + provider.input_option(option, optdict, inputlevel) # now we can generate the configuration file if stream is not None: self.generate_config(stream) - + def load_config_file(self): """dispatch values previously read from a configuration file to each options provider) @@ -675,6 +656,28 @@ class OptionsProviderMixIn: _list.append(value) else: raise UnsupportedAction(action) + + def input_option(self, option, optdict, inputlevel=99): + default = self.option_default(option, optdict) + if default is REQUIRED: + defaultstr = '(required): ' + elif optdict.get('inputlevel', 0) > inputlevel: + self.set_option(option, default, opt_dict=optdict) + return + elif optdict['type'] == 'password': + defaultstr = ': ' + else: + defaultstr = '(default: %s): ' % format_option_value(optdict, default) + print ':%s:' % option + print optdict.get('help') or option + inputfunc = INPUT_FUNCTIONS[optdict['type']] + value = inputfunc(optdict, defaultstr) + while default is REQUIRED and not value: + print 'please specify a value' + value = inputfunc(optdict, '%s: ' % option) + if value is None and default is not None: + value = default + self.set_option(option, value, opt_dict=optdict) def get_option_def(self, opt_name): """return the dictionary defining an option given it's name""" |