diff options
author | David Sommerseth <davids@redhat.com> | 2012-12-19 15:55:04 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2012-12-19 15:55:04 +0100 |
commit | f9e8cce6b39c0fb966562613da4292c7e952d7a7 (patch) | |
tree | 717a5383cf7636d3cba66ba0846ab13e411d6369 /rteval | |
parent | efe7c056315f7e613f125089300ae142150aa99c (diff) | |
download | rteval-f9e8cce6b39c0fb966562613da4292c7e952d7a7.tar.gz rteval-f9e8cce6b39c0fb966562613da4292c7e952d7a7.tar.xz rteval-f9e8cce6b39c0fb966562613da4292c7e952d7a7.zip |
Update config with values from the command line
Now all the command line argument modifications will update the
configuration object. Command line arguments will override any
default or configuration variables.
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'rteval')
-rw-r--r-- | rteval/modules/__init__.py | 2 | ||||
-rw-r--r-- | rteval/rtevalConfig.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/rteval/modules/__init__.py b/rteval/modules/__init__.py index ea5a0a2..f1d964b 100644 --- a/rteval/modules/__init__.py +++ b/rteval/modules/__init__.py @@ -231,7 +231,7 @@ the information provided by the module""" default = s.has_key('default') and s['default'] or None metavar = s.has_key('metavar') and s['metavar'] or None grparser.add_option('--%s-%s' % (shortmod, o), - dest="%s_%s" % (shortmod, o), + dest="%s___%s" % (shortmod, o), action='store', help='%s%s' % (descr, default and '(default: %s)' % default or ''), diff --git a/rteval/rtevalConfig.py b/rteval/rtevalConfig.py index 2658e77..4d7ba17 100644 --- a/rteval/rtevalConfig.py +++ b/rteval/rtevalConfig.py @@ -210,6 +210,20 @@ class rtevalConfig(object): return self.__config_files.__contains__(fname) + def UpdateFromOptionParser(self, parser): + "Parse through the command line options and update the appropriate config settings" + + last_sect = None + for sk,v in sorted(vars(parser.values).items()): + # optparse key template: {sectionname}___{key} + k = sk.split('___') + if k[0] != last_sect: + # If the section name changed, retrieve the section variables + sect = self.GetSection(k[0]) + last_sect = k[0] + setattr(sect, k[1], v) + + def AppendConfig(self, section, cfgvars): "Add more config parameters to a section. cfgvars must be a dictionary of parameters" self.__update_section(section, cfgvars) |