diff options
author | Steven Knight <knight@baldmt.com> | 2002-04-22 19:21:26 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-04-22 19:21:26 (GMT) |
commit | 74f98d3083cfbb859bf032dba37ed14bbb5219dd (patch) | |
tree | 331e7f6b4cb4d8ec98a4cce203ab22f4ba893f9b /src/engine/SCons/Util.py | |
parent | 9afa958bb1b299c47b3197589ab7b9b89686cc6b (diff) | |
download | SCons-74f98d3083cfbb859bf032dba37ed14bbb5219dd.zip SCons-74f98d3083cfbb859bf032dba37ed14bbb5219dd.tar.gz SCons-74f98d3083cfbb859bf032dba37ed14bbb5219dd.tar.bz2 |
Several bug fixes from Charles Crain.
Diffstat (limited to 'src/engine/SCons/Util.py')
-rw-r--r-- | src/engine/SCons/Util.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 0abbd1e..08edde7 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -139,6 +139,23 @@ class PathList(UserList.UserList): # suffix and basepath. return self.__class__([ UserList.UserList.__getitem__(self, item), ]) +_env_var = re.compile(r'^\$([_a-zA-Z]\w*|{[^}]*})$') + +def get_environment_var(varstr): + """Given a string, first determine if it looks like a reference + to a single environment variable, like "$FOO" or "${FOO}". + If so, return that variable with no decorations ("FOO"). + If not, return None.""" + mo=_env_var.match(to_String(varstr)) + if mo: + var = mo.group(1) + if var[0] == '{': + return var[1:-1] + else: + return var + else: + return None + def quote_spaces(arg): if ' ' in arg or '\t' in arg: return '"%s"' % arg @@ -272,8 +289,10 @@ def is_List(e): def to_String(s): """Better than str() because it will preserve a unicode object without converting it to ASCII.""" - if is_String(s): - return s + if hasattr(types, 'UnicodeType') and \ + (type(s) is types.UnicodeType or \ + (isinstance(s, UserString) and type(s.data) is types.UnicodeType)): + return unicode(s) else: return str(s) |