changeset 142:09c10061838c

add a program to create relative links
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 May 2011 16:13:08 -0700
parents c4aaaa6d9c13
children 31a41264d51f
files python/relativelink.py
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/relativelink.py	Fri May 27 16:13:08 2011 -0700
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+def link(path_info, path=None):
+
+    segments = path_info.split('/')
+    if segments[0]:
+        segments.insert(0, '')
+    
+    if len(segments) <3:
+        if not path or path == '/':
+            return './'
+        return path
+
+    nlayers = len(segments[2:])
+    string = '../' * nlayers
+
+    if not path or path == '/':
+        return string
+    return string + path
+
+if __name__ == '__main__':
+    import sys
+    assert len(sys.argv[1:]) == 2, "need two arguments"
+    path_info, path = sys.argv[1:]
+    print link(path_info, path)