diff --git a/doc/ubuntu-dev-tools.5 b/doc/ubuntu-dev-tools.5 index 7325f86..2229e8f 100644 --- a/doc/ubuntu-dev-tools.5 +++ b/doc/ubuntu-dev-tools.5 @@ -59,8 +59,8 @@ This specifies the preferred test\-builder, one of .TP .B UBUNTUTOOLS_UPDATE_BUILDER -Boolean. Whether or not to update the test\-builder before each test -build. +Whether or not to update the test\-builder before each test build. +.RB "One of " yes " or " no " (default). .TP .B UBUNTUTOOLS_LPINSTANCE diff --git a/ubuntutools/config.py b/ubuntutools/config.py index 0e8bcb6..12bdafa 100644 --- a/ubuntutools/config.py +++ b/ubuntutools/config.py @@ -67,7 +67,7 @@ class UDTConfig(object): f.close() return config - def get_value(self, key, default=None, compat_keys=[]): + def get_value(self, key, default=None, boolean=False, compat_keys=[]): """Retrieve a value from the environment or configuration files. keys are prefixed with the script name, falling back to UBUNTUTOOLS for package-wide keys. @@ -90,8 +90,11 @@ class UDTConfig(object): for store in (os.environ, self.config): if k in store: value = store[k] - if value in ('yes', 'no'): - value = value == 'yes' + if boolean: + if value in ('yes', 'no'): + value = value == 'yes' + else: + continue return value return default diff --git a/ubuntutools/test/test_config.py b/ubuntutools/test/test_config.py index 052ebd5..2d32cf2 100644 --- a/ubuntutools/test/test_config.py +++ b/ubuntutools/test/test_config.py @@ -83,9 +83,9 @@ REPEAT=yes 'REPEAT': 'yes', }) - def get_value(self, key, default=None, compat_keys=[]): + def get_value(self, *args, **kwargs): config = UDTConfig(prefix='TEST') - return config.get_value(key, default=default, compat_keys=compat_keys) + return config.get_value(*args, **kwargs) def test_defaults(self): self.assertEqual(self.get_value('BUILDER'), 'pbuilder') @@ -120,9 +120,11 @@ REPEAT=yes def test_boolean(self): config_files['user'] = "TEST_BOOLEAN=yes" - self.assertEqual(self.get_value('BOOLEAN'), True) + self.assertEqual(self.get_value('BOOLEAN', boolean=True), True) config_files['user'] = "TEST_BOOLEAN=no" - self.assertEqual(self.get_value('BOOLEAN'), False) + self.assertEqual(self.get_value('BOOLEAN', boolean=True), False) + config_files['user'] = "TEST_BOOLEAN=true" + self.assertEqual(self.get_value('BOOLEAN', boolean=True), None) def test_nonpackagewide(self): config_files['user'] = 'UBUNTUTOOLS_FOOBAR=a'