aboutsummaryrefslogtreecommitdiffstats
path: root/lib/oe
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-04-14 18:25:58 -0700
committerChris Larson <chris_larson@mentor.com>2010-04-23 14:20:42 -0700
commit707bbb0667edfc9df15863286a02f64adfb5544d (patch)
treeb6d7cc8f0915aaffd9834c61bd36917838a60b6d /lib/oe
parent38cf80fce6aff11422770d84f21113f38c8dc57a (diff)
downloadopenembedded-707bbb0667edfc9df15863286a02f64adfb5544d.tar.gz
oe.path.relative: leverage os.path.relpath if available
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/oe')
-rw-r--r--lib/oe/path.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/oe/path.py b/lib/oe/path.py
index 7dafdb173e..48c4b9b633 100644
--- a/lib/oe/path.py
+++ b/lib/oe/path.py
@@ -15,22 +15,25 @@ def relative(src, dest):
>>> relative("/tmp", "/tmp/foo/bar")
foo/bar
"""
- from os.path import sep, pardir, normpath, commonprefix
+ import os.path
- destlist = normpath(dest).split(sep)
- srclist = normpath(src).split(sep)
+ if hasattr(os.path, "relpath"):
+ return os.path.relpath(dest, src)
+ else:
+ destlist = os.path.normpath(dest).split(os.path.sep)
+ srclist = os.path.normpath(src).split(os.path.sep)
- # Find common section of the path
- common = commonprefix([destlist, srclist])
- commonlen = len(common)
+ # Find common section of the path
+ common = os.path.commonprefix([destlist, srclist])
+ commonlen = len(common)
- # Climb back to the point where they differentiate
- relpath = [ pardir ] * (len(srclist) - commonlen)
- if commonlen < len(destlist):
- # Add remaining portion
- relpath += destlist[commonlen:]
+ # Climb back to the point where they differentiate
+ relpath = [ pardir ] * (len(srclist) - commonlen)
+ if commonlen < len(destlist):
+ # Add remaining portion
+ relpath += destlist[commonlen:]
- return sep.join(relpath)
+ return sep.join(relpath)
def format_display(path, metadata):
""" Prepare a path for display to the user. """