[Python-checkins] CVS: distutils/distutils util.py,1.30,1.31
Greg Ward
python-dev@python.org
Wed, 26 Apr 2000 21:53:52 -0400 (EDT)
Update of /projects/cvsroot/distutils/distutils
In directory newcnri:/tmp/cvs-serv1257
Modified Files:
util.py
Log Message:
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.
Index: util.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/util.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** util.py 2000/04/25 01:33:11 1.30
--- util.py 2000/04/27 01:53:46 1.31
***************
*** 6,10 ****
# created 1999/03/08, Greg Ward
! __revision__ = "$Id: util.py,v 1.30 2000/04/25 01:33:11 gward Exp $"
import sys, os, string, re, shutil
--- 6,10 ----
# created 1999/03/08, Greg Ward
! __revision__ = "$Id: util.py,v 1.31 2000/04/27 01:53:46 gward Exp $"
import sys, os, string, re, shutil
***************
*** 84,87 ****
--- 84,113 ----
# 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