summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-10-22 13:02:35 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2014-10-22 13:11:56 -0500
commitbb21c79f38c155fb14289479840efd8abdf54689 (patch)
tree593139e17bb43dc0973799e8c707d1771405ae66
parentee50f531ce6ba4a23d0b8c6e1ec81f09c0652874 (diff)
downloadbcfg2-bb21c79f38c155fb14289479840efd8abdf54689.tar.gz
bcfg2-bb21c79f38c155fb14289479840efd8abdf54689.tar.bz2
bcfg2-bb21c79f38c155fb14289479840efd8abdf54689.zip
Options: fix path canonicalization and file-like objects
This fixes canonicalizing PathOption values when the default value of a config file-only option is used. It also fixes PathOptions that get a file-like object instead of a filename string.
-rw-r--r--src/lib/Bcfg2/Options/Options.py11
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestOptions.py14
2 files changed, 17 insertions, 8 deletions
diff --git a/src/lib/Bcfg2/Options/Options.py b/src/lib/Bcfg2/Options/Options.py
index 36148c279..f1a201f1e 100644
--- a/src/lib/Bcfg2/Options/Options.py
+++ b/src/lib/Bcfg2/Options/Options.py
@@ -364,25 +364,20 @@ class PathOption(Option):
def _get_default(self):
""" Getter for the ``default`` property """
- if self.__class__.repository is None or self._default is None:
+ if not hasattr(self._default, "replace"):
return self._default
else:
- return self._default.replace("<repository>",
- self.__class__.repository)
+ return self._type(self._default)
default = property(_get_default, Option._set_default)
def _type(self, value):
"""Type function that fixes up <repository> macros."""
if self.__class__.repository is None:
- _debug("Cannot fix up <repository> macros yet for %s" % self)
return value
else:
- rv = self._original_type(Types.path(
+ return self._original_type(Types.path(
value.replace("<repository>", self.__class__.repository)))
- _debug("Fixing up <repository> macros in %s: %s -> %s" %
- (self, value, rv))
- return rv
class _BooleanOptionAction(argparse.Action):
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py b/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
index 94d30dd3a..a3190f2ca 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
@@ -75,6 +75,20 @@ class TestBasicOptions(OptionTestCase):
self.assertEqual(options.test_path_option,
os.path.abspath("./test"))
+ @make_config()
+ def test_default_path_canonicalization(self, config_file):
+ """canonicalize default PathOption values."""
+ testdir = os.path.expanduser("~/test")
+ result = argparse.Namespace()
+ parser = Parser(namespace=result)
+ parser.add_options([PathOption("--test1", default="~/test"),
+ PathOption(cf=("test", "test2"),
+ default="~/test"),
+ Common.repository])
+ parser.parse(["-C", config_file])
+ self.assertEqual(result.test1, testdir)
+ self.assertEqual(result.test2, testdir)
+
def test_default_bool(self):
"""use the default value of boolean options."""
options = self._test_options()