# HG changeset patch # User osimons # Date 1252109358 0 # Node ID a9d8359f4dc95e5be5a73fc760ac7c69a61450f9 # Parent 463cd827f5670eba3257277d794cffbb260232d9 0.6dev: Follow-up on #436 / [737], changing to use `string.Template()` instead of `os.path.expandvars()` as this produces a consistent result across platforms and python version. This drops the Windows-specific syntax of `%VAR%` for the greater good... Should fix the 2 broken tests. diff --git a/bitten/build/config.py b/bitten/build/config.py --- a/bitten/build/config.py +++ b/bitten/build/config.py @@ -15,6 +15,7 @@ import os import platform import re +from string import Template log = logging.getLogger('bitten.config') @@ -170,7 +171,7 @@ provided, the reference is not replaced at all. Environment properties substitute from environment variables, supporting - common notations; ``$VAR``, ``${VAR}`` and ``%var%`` (Windows only). + the common notations of ``$VAR`` and ``${VAR}``. :param text: the string containing variable references :param vars: extra variables to use for the interpolation @@ -185,4 +186,5 @@ return m.group('def') else: return m.group(0) - return os.path.expandvars(self._VAR_RE.sub(_replace, text)) + return Template(self._VAR_RE.sub(_replace, text) + ).safe_substitute(os.environ) diff --git a/bitten/build/tests/config.py b/bitten/build/tests/config.py --- a/bitten/build/tests/config.py +++ b/bitten/build/tests/config.py @@ -177,25 +177,27 @@ def test_interpolate_environment(self): config = Configuration() - if os.name == 'posix': - self.assertEquals(os.environ['USER'], - config.interpolate('$USER')) - self.assertEquals('$user', - config.interpolate('$user')) - self.assertEquals(os.environ['USER'], - config.interpolate('${USER}')) - self.assertEquals('${user}', - config.interpolate('${user}')) - elif os.name == 'nt': - # Additional custom syntax + also case insensitive - self.assertEquals(os.environ['PROGRAMFILES'], - config.interpolate('%programfiles%')) - self.assertEquals(os.environ['programfiles'], - config.interpolate('%PROGRAMFILES%')) - self.assertEquals(os.environ['PROGRAMFILES'], - config.interpolate('$programfiles')) - self.assertEquals(os.environ['PROGRAMFILES'], - config.interpolate('${programfiles}')) + os.environ['BITTEN_TEST'] = 'foo' + try: + # regular substitutions + self.assertEquals(os.environ['BITTEN_TEST'], + config.interpolate('$BITTEN_TEST')) + self.assertEquals(os.environ['BITTEN_TEST'], + config.interpolate('${BITTEN_TEST}')) + if os.name == 'posix': + # case-sensitive + self.assertEquals('${bitten_test}', + config.interpolate('${bitten_test}')) + self.assertEquals('$bitten_test', + config.interpolate('$bitten_test')) + elif os.name == 'nt': + # case-insensitive + self.assertEquals(os.environ['bitten_test'], + config.interpolate('$bitten_test')) + self.assertEquals(os.environ['bitten_test'], + config.interpolate('${bitten_test}')) + finally: + del os.environ['BITTEN_TEST'] def suite(): suite = unittest.TestSuite() diff --git a/doc/configure.txt b/doc/configure.txt --- a/doc/configure.txt +++ b/doc/configure.txt @@ -205,11 +205,11 @@ args="Slave: ${family} ${os} ${version} ${machine} ${processor}"/> Additionally, environment variables are also interpolated, supporting -common notations; ``$VAR``, ``${VAR}`` and ``%var%`` (Windows only). +the common notations of ``$VAR`` and ``${VAR}``. .. code-block:: xml - + Authentication