Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
This commit is contained in:
parent
a76bbd4566
commit
4b46ef9a4f
|
@ -86,22 +86,22 @@ def native_path (pathname):
|
||||||
|
|
||||||
|
|
||||||
def change_root (new_root, pathname):
|
def change_root (new_root, pathname):
|
||||||
|
|
||||||
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
|
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
|
||||||
relative, this is equivalent to "os.path.join(new_root,pathname)".
|
relative, this is equivalent to "os.path.join(new_root,pathname)".
|
||||||
Otherwise, it requires making 'pathname' relative and then joining the
|
Otherwise, it requires making 'pathname' relative and then joining the
|
||||||
two, which is tricky on DOS/Windows and Mac OS."""
|
two, which is tricky on DOS/Windows and Mac OS.
|
||||||
|
"""
|
||||||
if not abspath (pathname):
|
if os.name == 'posix':
|
||||||
return os.path.join (new_root, pathname)
|
if not os.path.isabs (pathname):
|
||||||
|
return os.path.join (new_root, pathname)
|
||||||
elif os.name == 'posix':
|
else:
|
||||||
return os.path.join (new_root, pathname[1:])
|
return os.path.join (new_root, pathname[1:])
|
||||||
|
|
||||||
elif os.name == 'nt':
|
elif os.name == 'nt':
|
||||||
(root_drive, root_path) = os.path.splitdrive (new_root)
|
|
||||||
(drive, path) = os.path.splitdrive (pathname)
|
(drive, path) = os.path.splitdrive (pathname)
|
||||||
raise RuntimeError, "I give up -- not sure how to do this on Windows"
|
if path[0] == '\\':
|
||||||
|
path = path[1:]
|
||||||
|
return os.path.join (new_root, path)
|
||||||
|
|
||||||
elif os.name == 'mac':
|
elif os.name == 'mac':
|
||||||
raise RuntimeError, "no clue how to do this on Mac OS"
|
raise RuntimeError, "no clue how to do this on Mac OS"
|
||||||
|
|
Loading…
Reference in New Issue