summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-03-11 11:23:33 +0000
committerJose Fonseca <jfonseca@vmware.com>2015-03-11 20:20:50 +0000
commit305ecc3ac89bfd158d521633c4c7fc80e9889364 (patch)
treec33cd08ac923352cb529da9dc82cff2fa8a27731
parent544a23ab0cc35c115e77a4a5419fef1d3bf11f73 (diff)
grouptools.py: Silently ignore mixed os.path.join usage on Windows too.
grouptools currently acts like a time-bomb: spite the good intention, it currently ignores when developers mistakenly use os.path.join with grouptools on Posix; then it explodes when the same code is used on Windows. t This change makes grouptools behavior on Windows the same as Linux, ie., silently ignore when os.path.join is mixed. (Another solution would be to use a different separator character on Linux, but that would be a much more complex change than I can afford to make at this moment.) Reviewed-by: Dylan Baker <baker.dylan.c@gmail.com>
-rw-r--r--framework/grouptools.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/framework/grouptools.py b/framework/grouptools.py
index 3d26bbc2c..1000a5137 100644
--- a/framework/grouptools.py
+++ b/framework/grouptools.py
@@ -30,6 +30,7 @@ posix paths they may not start with a leading '/'.
"""
import posixpath
+import os.path
__all__ = [
'join',
@@ -42,6 +43,22 @@ __all__ = [
'from_path'
]
+
+def _normalize(group):
+ """Helper to normalize group paths on Windows.
+
+ Although grouptools' heart is in the right place, the fact is that it fails
+ to spot when developers mistakedly use os.path.join for groups on Posix
+ systems.
+
+ So until this is improved somehow, make grouptools behavior on Windows
+ match Linux, ie, just silently ignore mixed use of grouptools and os.path.
+ """
+ if os.path.sep != '/':
+ group = group.replace(os.path.sep, '/')
+ return group
+
+
def _assert_illegal(group):
"""Helper that checks for illegal characters in input."""
assert isinstance(group, (str, unicode)), 'Type must be string or unicode'
@@ -61,6 +78,7 @@ def testname(group):
Analogous to os.path.basename
"""
+ group = _normalize(group)
_assert_illegal(group)
return posixpath.basename(group)
@@ -76,6 +94,7 @@ def groupname(group):
Analogous to os.path.dirname
"""
+ group = _normalize(group)
_assert_illegal(group)
return posixpath.dirname(group)
@@ -83,6 +102,7 @@ def groupname(group):
def splitname(group):
"""Split a group name, Returns tuple "(group, test)"."""
+ group = _normalize(group)
_assert_illegal(group)
return posixpath.split(group)
@@ -90,6 +110,7 @@ def splitname(group):
def commonprefix(args):
"""Given a list of groups, returns the longest common leading component."""
+ args = [_normalize(group) for group in args]
for group in args:
_assert_illegal(group)
@@ -103,6 +124,7 @@ def join(*args):
'\\' in them, as these are groups not paths.
"""
+ args = [_normalize(group) for group in args]
for group in args:
assert isinstance(group, (str, unicode)), \
'Type must be string or unicode'
@@ -121,6 +143,8 @@ def relgroup(large, small):
start is longer than the group then '' is returned.
"""
+ large = _normalize(large)
+ small = _normalize(small)
for element in {large, small}:
_assert_illegal(element)
@@ -138,6 +162,7 @@ def split(group):
If input is '' return an empty list
"""
+ group = _normalize(group)
_assert_illegal(group)
if group == '':
return []