From: Andrew M. Kuchling Date: Tue, 26 Nov 2002 17:42:48 +0000 (+0000) Subject: Part of the fix for bug #410541: add ensure_relative() function X-Git-Tag: v2.3c1~3229 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=40f23e0ddf4aa875cc46e1bddeb88a0a3b7c3fdc;p=thirdparty%2FPython%2Fcpython.git Part of the fix for bug #410541: add ensure_relative() function --- diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py index ca9fa9dc7fcb..bd1ea0f24368 100644 --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -6,7 +6,7 @@ Utility functions for manipulating directories and directory trees.""" __revision__ = "$Id$" -import os +import os, sys from types import * from distutils.errors import DistutilsFileError, DistutilsInternalError from distutils import log @@ -212,3 +212,17 @@ def remove_tree (directory, verbose=0, dry_run=0): except (IOError, OSError), exc: log.warn(grok_environment_error( exc, "error removing %s: " % directory)) + + +def ensure_relative (path): + """Take the full path 'path', and make it a relative path so + it can be the second argument to os.path.join(). + """ + drive, path = os.path.splitdrive(path) + if sys.platform == 'mac': + return os.sep + path + else: + if path[0:1] == os.sep: + path = drive + path[1:] + return path +