Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40f23e0

Browse files
committed
Part of the fix for bug #410541: add ensure_relative() function
1 parent 96bc3b4 commit 40f23e0

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/distutils/dir_util.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
__revision__ = "$Id$"
88

9-
import os
9+
import os, sys
1010
from types import *
1111
from distutils.errors import DistutilsFileError, DistutilsInternalError
1212
from distutils import log
@@ -212,3 +212,17 @@ def remove_tree (directory, verbose=0, dry_run=0):
212212
except (IOError, OSError), exc:
213213
log.warn(grok_environment_error(
214214
exc, "error removing %s: " % directory))
215+
216+
217+
def ensure_relative (path):
218+
"""Take the full path 'path', and make it a relative path so
219+
it can be the second argument to os.path.join().
220+
"""
221+
drive, path = os.path.splitdrive(path)
222+
if sys.platform == 'mac':
223+
return os.sep + path
224+
else:
225+
if path[0:1] == os.sep:
226+
path = drive + path[1:]
227+
return path
228+

0 commit comments

Comments
 (0)