summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorScott Garman <scott.a.garman@intel.com>2012-03-12 17:07:19 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-03-13 11:52:11 +0000
commit19e92dfe063968154d8744936ece19e6aca3466a (patch)
tree5f1c887beb5a36ce6019103fdb05744dc5e4d09b /meta/lib/oe
parent5fff3ea93bf353149e1642360c78cba27de3b174 (diff)
downloadast2050-yocto-poky-19e92dfe063968154d8744936ece19e6aca3466a.zip
ast2050-yocto-poky-19e92dfe063968154d8744936ece19e6aca3466a.tar.gz
path.py: add make_relative_symlink method
This method allows you to convert an absolute symlink into a relative one. (From OE-Core rev: 71062c1e0fb45a4b4e58ea5d217706aa2b402d88) Signed-off-by: Scott Garman <scott.a.garman@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/path.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index 683b097..1fdfa87 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -40,6 +40,33 @@ def relative(src, dest):
return os.path.sep.join(relpath)
+def make_relative_symlink(path):
+ """ Convert an absolute symlink to a relative one """
+ if not os.path.islink(path):
+ return
+ link = os.readlink(path)
+ if not os.path.isabs(link):
+ return
+
+ # find the common ancestor directory
+ ancestor = path
+ depth = 0
+ while ancestor and not link.startswith(ancestor):
+ ancestor = ancestor.rpartition('/')[0]
+ depth += 1
+
+ if not ancestor:
+ print "make_relative_symlink() Error: unable to find the common ancestor of %s and its target" % path
+ return
+
+ base = link.partition(ancestor)[2].strip('/')
+ while depth > 1:
+ base = "../" + base
+ depth -= 1
+
+ os.remove(path)
+ os.symlink(base, path)
+
def format_display(path, metadata):
""" Prepare a path for display to the user. """
rel = relative(metadata.getVar("TOPDIR", True), path)
OpenPOWER on IntegriCloud