summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/util.py
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2000-04-27 01:53:46 (GMT)
committerGreg Ward <gward@python.net>2000-04-27 01:53:46 (GMT)
commit67f75d4bcb3630c0f5b6761fb758072cc342157e (patch)
treeddcf5dcc9204a914d9fff6c74c5abf745c89ea3a /Lib/distutils/util.py
parentbad9c7675a9da2907b6b3398c087e9928447a7d2 (diff)
downloadcpython-67f75d4bcb3630c0f5b6761fb758072cc342157e.zip
cpython-67f75d4bcb3630c0f5b6761fb758072cc342157e.tar.gz
cpython-67f75d4bcb3630c0f5b6761fb758072cc342157e.tar.bz2
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
even if it's already absolute. Currently only implemented for Unix; I'm not entirely sure of the right thing to do for DOS/Windows, and have no clue what to do for Mac OS.
Diffstat (limited to 'Lib/distutils/util.py')
-rw-r--r--Lib/distutils/util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index ca20ae0..8e642e1 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -85,6 +85,32 @@ def native_path (pathname):
# native_path ()
+def change_root (new_root, pathname):
+
+ """Return 'pathname' with 'new_root' prepended. If 'pathname' is
+ relative, this is equivalent to "os.path.join(new_root,pathname)".
+ Otherwise, it requires making 'pathname' relative and then joining the
+ two, which is tricky on DOS/Windows and Mac OS."""
+
+ if not abspath (pathname):
+ return os.path.join (new_root, pathname)
+
+ elif os.name == 'posix':
+ return os.path.join (new_root, pathname[1:])
+
+ elif os.name == 'nt':
+ (root_drive, root_path) = os.path.splitdrive (new_root)
+ (drive, path) = os.path.splitdrive (pathname)
+ raise RuntimeError, "I give up -- not sure how to do this on Windows"
+
+ elif os.name == 'mac':
+ raise RuntimeError, "no clue how to do this on Mac OS"
+
+ else:
+ raise DistutilsPlatformError, \
+ "nothing known about platform '%s'" % os.name
+
+
def _check_environ ():
"""Ensure that 'os.environ' has all the environment variables we
guarantee that users can use in config files, command-line