[oe-commits] Chris Larson : Revert "oe.path.relative: switch to a different appraoch"
git version control
git at git.openembedded.org
Sat Apr 24 21:15:14 UTC 2010
Module: openembedded.git
Branch: org.openembedded.dev
Commit: 22f3b74fec790847c3e353aad84b51252637a90f
URL: http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=22f3b74fec790847c3e353aad84b51252637a90f
Author: Chris Larson <chris_larson at mentor.com>
Date: Sat Apr 24 14:14:22 2010 -0700
Revert "oe.path.relative: switch to a different appraoch"
Drop this for now, seems to cause issues with python 2.5.
This reverts commit 5c923fd35c369bae929fc0e110121abeaffab493.
---
lib/oe/path.py | 35 +++++++++++++++++++----------------
1 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/lib/oe/path.py b/lib/oe/path.py
index 8433ee1..48c4b9b 100644
--- a/lib/oe/path.py
+++ b/lib/oe/path.py
@@ -1,12 +1,10 @@
def join(*paths):
"""Like os.path.join but doesn't treat absolute RHS specially"""
- from os import sep
- from os.path import normpath
+ import os.path
+ return os.path.normpath("/".join(paths))
- return normpath(sep.join(paths))
-
-def relative(src, dest=None):
- """ Return a relative path from src to dest(default=cwd).
+def relative(src, dest):
+ """ Return a relative path from src to dest.
>>> relative("/usr/bin", "/tmp/foo/bar")
../../tmp/foo/bar
@@ -17,20 +15,25 @@ def relative(src, dest=None):
>>> relative("/tmp", "/tmp/foo/bar")
foo/bar
"""
- if dest is None:
- dest = getcwd()
+ import os.path
if hasattr(os.path, "relpath"):
return os.path.relpath(dest, src)
else:
- from os import getcwd, sep
- from os.path import abspath, normpath
-
- srclist = abspath(src).split(sep)
- destlist = abspath(dest).split(sep)
- loc = [spath == dpath for spath, dpath in zip(srclist, destlist)].index(False)
- rellist = ([ ".." ] * (len(srclist) - loc)) + destlist[loc:]
- return sep.join(rellist)
+ 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 = 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:]
+
+ return sep.join(relpath)
def format_display(path, metadata):
""" Prepare a path for display to the user. """
More information about the Openembedded-commits
mailing list