forked from jeffmahler/openrave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyrelpath.py
More file actions
19 lines (18 loc) · 747 Bytes
/
myrelpath.py
File metadata and controls
19 lines (18 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""relpath is not present in python 2.5 and below, so hold an implementation of it.
"""
try:
from os.path import relpath
except ImportError:
from posixpath import curdir, sep, pardir, join, abspath, commonprefix
def relpath(path, start=curdir):
"""Return a relative version of a path"""
if not path:
raise ValueError("no path specified")
start_list = abspath(start).split(sep)
path_list = abspath(path).split(sep)
# Work out how much of the filepath is shared by start and path.
i = len(commonprefix([start_list, path_list]))
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return curdir
return join(*rel_list)