summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-02-10 10:50:37 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2014-03-05 13:37:41 -0500
commit27d2556ce9a1b9aa92d50bc26f7d8759e836ad40 (patch)
tree5bd86f5cf9f74c39e2593bb1d7ae4da01e3d661a
parent64ba5bcd5945facf301e0b4f2cc92d326f054bf0 (diff)
downloadbcfg2-27d2556ce9a1b9aa92d50bc26f7d8759e836ad40.tar.gz
bcfg2-27d2556ce9a1b9aa92d50bc26f7d8759e836ad40.tar.bz2
bcfg2-27d2556ce9a1b9aa92d50bc26f7d8759e836ad40.zip
Options: Finalize actual value, not default value
This also fixes some extraneous calls in the option parsing loop.
-rw-r--r--src/lib/Bcfg2/Options/Actions.py3
-rw-r--r--src/lib/Bcfg2/Options/Options.py32
-rw-r--r--src/lib/Bcfg2/Options/Parser.py3
3 files changed, 21 insertions, 17 deletions
diff --git a/src/lib/Bcfg2/Options/Actions.py b/src/lib/Bcfg2/Options/Actions.py
index 3ebe75b5f..7b85f7c4c 100644
--- a/src/lib/Bcfg2/Options/Actions.py
+++ b/src/lib/Bcfg2/Options/Actions.py
@@ -132,7 +132,8 @@ class ComponentAction(argparse.Action):
in it. This lets a default be specified with a list of
strings instead of a list of classes. """
if not self._final:
- self.__call__(parser, namespace, self.default)
+ self.__call__(parser, namespace, getattr(namespace, self.dest,
+ self.default))
def __call__(self, parser, namespace, values, option_string=None):
if values is None:
diff --git a/src/lib/Bcfg2/Options/Options.py b/src/lib/Bcfg2/Options/Options.py
index 81bd7f7d8..136511f41 100644
--- a/src/lib/Bcfg2/Options/Options.py
+++ b/src/lib/Bcfg2/Options/Options.py
@@ -169,7 +169,10 @@ class Option(object):
the appropriate default value in the appropriate format."""
for parser, action in self.actions.items():
if hasattr(action, "finalize"):
- _debug("Finalizing %s for %s" % (self, parser))
+ if parser:
+ _debug("Finalizing %s for %s" % (self, parser))
+ else:
+ _debug("Finalizing %s" % self)
action.finalize(parser, namespace)
def from_config(self, cfp):
@@ -184,7 +187,6 @@ class Option(object):
"""
if not self.cf:
return None
- _debug("Setting %s from config file(s)" % self)
if '*' in self.cf[1]:
if cfp.has_section(self.cf[0]):
# build a list of known options in this section, and
@@ -194,23 +196,25 @@ class Option(object):
exclude.update(o.cf[1]
for o in parser.option_list
if o.cf and o.cf[0] == self.cf[0])
- return dict([(o, cfp.get(self.cf[0], o))
- for o in fnmatch.filter(cfp.options(self.cf[0]),
- self.cf[1])
- if o not in exclude])
+ rv = dict([(o, cfp.get(self.cf[0], o))
+ for o in fnmatch.filter(cfp.options(self.cf[0]),
+ self.cf[1])
+ if o not in exclude])
else:
- return dict()
+ rv = dict()
else:
+ if self.type:
+ rtype = self.type
+ else:
+ rtype = lambda x: x
try:
- val = cfp.getboolean(*self.cf)
+ rv = rtype(cfp.getboolean(*self.cf))
except ValueError:
- val = cfp.get(*self.cf)
+ rv = rtype(cfp.get(*self.cf))
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- return None
- if self.type:
- return self.type(val)
- else:
- return val
+ rv = None
+ _debug("Setting %s from config file(s): %s" % (self, rv))
+ return rv
def default_from_config(self, cfp):
""" Set the default value of this option from the config file
diff --git a/src/lib/Bcfg2/Options/Parser.py b/src/lib/Bcfg2/Options/Parser.py
index cb71d7491..d855b6232 100644
--- a/src/lib/Bcfg2/Options/Parser.py
+++ b/src/lib/Bcfg2/Options/Parser.py
@@ -261,8 +261,7 @@ class Parser(argparse.ArgumentParser):
self._set_defaults()
self.parse_known_args(args=self.argv, namespace=self.namespace)
self._parse_config_options()
- self._parse_config_options()
- self._finalize()
+ self._finalize()
# phase 4: fix up <repository> macros
_debug("Option parsing phase 4: Fix up macros")