diff options
author | Greg Ward <gward@python.net> | 2000-03-07 03:27:08 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 2000-03-07 03:27:08 (GMT) |
commit | 5091929c2cf04bfbd545835d2435e43bda6afa05 (patch) | |
tree | 9c25bc9b5a4da59f535ca5214cd96300e25e0d73 /Lib | |
parent | e2b4452d0c3cc869d27e382100fda4466d39314b (diff) | |
download | cpython-5091929c2cf04bfbd545835d2435e43bda6afa05.zip cpython-5091929c2cf04bfbd545835d2435e43bda6afa05.tar.gz cpython-5091929c2cf04bfbd545835d2435e43bda6afa05.tar.bz2 |
Added 'native_path()' for use on pathnames from the setup script: split on
slashes, and put back together again using the local directory separator.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/distutils/util.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py index 03c0c88..683d167 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -458,3 +458,31 @@ def get_platform (): return sys.platform # get_platform() + + +def native_path (pathname): + """Return 'pathname' as a name that will work on the native + filesystem, i.e. split it on '/' and put it back together again + using the current directory separator. Needed because filenames in + the setup script are always supplied in Unix style, and have to be + converted to the local convention before we can actually use them in + the filesystem. Raises DistutilsValueError if 'pathname' is + absolute (starts with '/') or contains local directory separators + (unless the local separator is '/', of course).""" + + if pathname[0] == '/': + raise DistutilsValueError, "path '%s' cannot be absolute" % pathname + if pathname[-1] == '/': + raise DistutilsValueError, "path '%s' cannot end with '/'" % pathname + if os.sep != '/': + if os.sep in pathname: + raise DistutilsValueError, \ + "path '%s' cannot contain '%c' character" % \ + (pathname, os.sep) + + paths = string.split (pathname, '/') + return apply (os.path.join, paths) + else: + return pathname + +# native_path () |