diff options
author | Martin Jansa <Martin.Jansa@gmail.com> | 2010-05-27 12:44:07 +0200 |
---|---|---|
committer | Martin Jansa <Martin.Jansa@gmail.com> | 2010-05-27 12:44:07 +0200 |
commit | 293b05335ab540c4c8402e0a5caf2886b786a318 (patch) | |
tree | 11e5a7c2dce338058f150e08d1ff47c9d4d8eccd /lib/oe/path.py | |
parent | 1ee2156592ba17f64f3c9b8970285a259730b871 (diff) | |
parent | e9aacc4ce4784c91cb4908145b8fb7b3ec8aa6e0 (diff) | |
download | openembedded-293b05335ab540c4c8402e0a5caf2886b786a318.tar.gz |
Merge remote branch 'origin/org.openembedded.dev' into shr/testing2010
Conflicts:
recipes/linux/linux-openmoko-devel_git.bb
recipes/openmoko-3rdparty/pisi_0.5.2.bb
recipes/openmoko-3rdparty/pisi_0.5.3.bb
recipes/openmoko-3rdparty/pisi_0.5.bb
recipes/uclibc/uclibc_nptl.bb
Diffstat (limited to 'lib/oe/path.py')
-rw-r--r-- | lib/oe/path.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/oe/path.py b/lib/oe/path.py new file mode 100644 index 0000000000..8902951581 --- /dev/null +++ b/lib/oe/path.py @@ -0,0 +1,44 @@ +def join(*paths): + """Like os.path.join but doesn't treat absolute RHS specially""" + import os.path + return os.path.normpath("/".join(paths)) + +def relative(src, dest): + """ Return a relative path from src to dest. + + >>> relative("/usr/bin", "/tmp/foo/bar") + ../../tmp/foo/bar + + >>> relative("/usr/bin", "/usr/lib") + ../lib + + >>> relative("/tmp", "/tmp/foo/bar") + foo/bar + """ + import os.path + + 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 = os.path.commonprefix([destlist, srclist]) + commonlen = len(common) + + # Climb back to the point where they differentiate + relpath = [ os.path.pardir ] * (len(srclist) - commonlen) + if commonlen < len(destlist): + # Add remaining portion + relpath += destlist[commonlen:] + + return os.path.sep.join(relpath) + +def format_display(path, metadata): + """ Prepare a path for display to the user. """ + rel = relative(metadata.getVar("TOPDIR", 1), path) + if len(rel) > len(path): + return path + else: + return rel |