diff options
author | Doug Anderson <dianders@chromium.org> | 2012-12-03 14:43:17 +0000 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2013-01-31 15:23:40 -0800 |
commit | 8568baed3bd9b4c0b8d71d1f933cdac459b0eae1 (patch) | |
tree | 7f04bfce9b08dacb8d94bea7ec97723300388889 /tools/patman/settings.py | |
parent | 21a19d70e2c2aa45cfe62c6adf8ceee9fcfbcacb (diff) | |
download | u-boot-imx-8568baed3bd9b4c0b8d71d1f933cdac459b0eae1.zip u-boot-imx-8568baed3bd9b4c0b8d71d1f933cdac459b0eae1.tar.gz u-boot-imx-8568baed3bd9b4c0b8d71d1f933cdac459b0eae1.tar.bz2 |
patman: Add support for settings in .patman
This patch adds support for a [settings] section in the .patman file.
In this section you can add settings that will affect the default
values for command-line options.
Support is added in a generic way such that any setting can be updated
by just referring to the "dest" of the option that is passed to the
option parser. At the moment options that would make sense to put in
settings are "ignore_errors", "process_tags", and "verbose". You
could override them like:
[settings]
ignore_errors: True
process_tags: False
verbose: True
The settings functionality is also used in a future change which adds
support for per-project settings.
Signed-off-by: Doug Anderson <dianders@chromium.org>
Diffstat (limited to 'tools/patman/settings.py')
-rw-r--r-- | tools/patman/settings.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 4dda17b..5208f7d 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -88,13 +88,43 @@ def CreatePatmanConfigFile(config_fname): print >>f, "[alias]\nme: %s <%s>" % (name, email) f.close(); -def Setup(config_fname=''): +def _UpdateDefaults(parser, config): + """Update the given OptionParser defaults based on config. + + We'll walk through all of the settings from the parser + For each setting we'll look for a default in the option parser. + If it's found we'll update the option parser default. + + The idea here is that the .patman file should be able to update + defaults but that command line flags should still have the final + say. + + Args: + parser: An instance of an OptionParser whose defaults will be + updated. + config: An instance of SafeConfigParser that we will query + for settings. + """ + defaults = parser.get_default_values() + for name, val in config.items('settings'): + if hasattr(defaults, name): + default_val = getattr(defaults, name) + if isinstance(default_val, bool): + val = config.getboolean('settings', name) + elif isinstance(default_val, int): + val = config.getint('settings', name) + parser.set_default(name, val) + else: + print "WARNING: Unknown setting %s" % name + +def Setup(parser, config_fname=''): """Set up the settings module by reading config files. Args: + parser: The parser to update config_fname: Config filename to read ('' for default) """ - settings = ConfigParser.SafeConfigParser() + config = ConfigParser.SafeConfigParser() if config_fname == '': config_fname = '%s/.patman' % os.getenv('HOME') @@ -102,11 +132,12 @@ def Setup(config_fname=''): print "No config file found ~/.patman\nCreating one...\n" CreatePatmanConfigFile(config_fname) - settings.read(config_fname) + config.read(config_fname) - for name, value in settings.items('alias'): + for name, value in config.items('alias'): alias[name] = value.split(',') + _UpdateDefaults(parser, config) # These are the aliases we understand, indexed by alias. Each member is a list. alias = {} |