]> code.ossystems Code Review - openembedded-core.git/commitdiff
scripts: add lnr (link relative)
authorRoss Burton <ross.burton@intel.com>
Mon, 3 Mar 2014 20:23:34 +0000 (20:23 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 7 Mar 2014 14:57:39 +0000 (14:57 +0000)
lnr is a simple script to generate relative symlinks from absolute paths,
similar to "ln -r" but without requiring coreutils 8.16 (Ubuntu 12.04 and others
currently ship 8.13).

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
scripts/lnr [new file with mode: 0755]

diff --git a/scripts/lnr b/scripts/lnr
new file mode 100755 (executable)
index 0000000..9dacebe
--- /dev/null
@@ -0,0 +1,21 @@
+#! /usr/bin/env python
+
+# Create a *relative* symlink, just like ln --relative does but without needing
+# coreutils 8.16.
+
+import sys, os
+
+if len(sys.argv) != 3:
+   print "$ lnr TARGET LINK_NAME"
+   sys.exit(1)
+
+target = sys.argv[1]
+linkname = sys.argv[2]
+
+if os.path.isabs(target):
+   if not os.path.isabs(linkname):
+      linkname = os.path.abspath(linkname)
+   start = os.path.dirname(linkname)
+   target = os.path.relpath(target, start)
+
+os.symlink(target, linkname)