All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Garman <scott.a.garman@intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 1/3] path.py: add make_relative_symlink method
Date: Mon, 12 Mar 2012 19:08:45 -0700	[thread overview]
Message-ID: <bf65cecf177efa0cb06508aa95e63e4d3a65dcb1.1331604310.git.scott.a.garman@intel.com> (raw)
In-Reply-To: <cover.1331604310.git.scott.a.garman@intel.com>
In-Reply-To: <cover.1331604310.git.scott.a.garman@intel.com>

This method allows you to convert an absolute symlink into a
relative one.

Signed-off-by: Scott Garman <scott.a.garman@intel.com>
---
 meta/lib/oe/path.py |   27 +++++++++++++++++++++++++++
 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)
-- 
1.7.5.4




  reply	other threads:[~2012-03-13  2:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  2:08 [PATCH 0/3] ncurses library location fix Scott Garman
2012-03-13  2:08 ` Scott Garman [this message]
2012-03-13  2:08 ` [PATCH 2/3] ncurses: move only libncurses and libtinfo to base_libdir Scott Garman
2012-03-13 20:51   ` Andreas Oberritter
2012-03-13 22:11     ` Scott Garman
2012-03-13  2:08 ` [PATCH 3/3] gettext: do not set libncurses prefix explicitly Scott Garman
2012-03-13 13:16   ` Richard Purdie
2012-03-13 19:58     ` Scott Garman
2012-03-13  5:30 ` [PATCH 0/3] ncurses library location fix Scott Garman
2012-03-13  8:09 ` Koen Kooi
2012-03-13  8:52   ` Scott Garman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf65cecf177efa0cb06508aa95e63e4d3a65dcb1.1331604310.git.scott.a.garman@intel.com \
    --to=scott.a.garman@intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.