summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Larson <clarson@mvista.com>2009-03-13 13:35:56 -0700
committerChris Larson <clarson@kergoth.com>2009-03-21 20:40:53 -0700
commit4cd7e03d78aed8ee6f3bd18d569a0ee9b2587633 (patch)
treedbcea87a4931f08e58af4d27e9e483f58bf10677
parentcca2065fe51746581e17a0dce3acab9a91196fc6 (diff)
base.bbclass: Add base_path_relative.
base_path_relative returns a relative path from src to dest. Examples: >>> base_path_relative("/usr/bin", "/tmp/foo/bar") ../../tmp/foo/bar >>> base_path_relative("/usr/bin", "/usr/lib") ../lib >>> base_path_relative("/tmp", "/tmp/foo/bar") foo/bar Signed-off-by: Chris Larson <clarson@mvista.com>
-rw-r--r--classes/base.bbclass29
1 files changed, 29 insertions, 0 deletions
diff --git a/classes/base.bbclass b/classes/base.bbclass
index 11f6554d2d..9bcd2abb3c 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -10,6 +10,35 @@ def base_path_join(a, *p):
path += '/' + b
return path
+def base_path_relative(src, dest):
+ """ Return a relative path from src to dest.
+
+ >>> base_path_relative("/usr/bin", "/tmp/foo/bar")
+ ../../tmp/foo/bar
+
+ >>> base_path_relative("/usr/bin", "/usr/lib")
+ ../lib
+
+ >>> base_path_relative("/tmp", "/tmp/foo/bar")
+ foo/bar
+ """
+ from os.path import sep, pardir, normpath, commonprefix
+
+ destlist = normpath(dest).split(sep)
+ srclist = normpath(src).split(sep)
+
+ # Find common section of the path
+ common = 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)
+
# for MD5/SHA handling
def base_chk_load_parser(config_path):
import ConfigParser, os, bb