comparison python/relativelink.py @ 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
children
comparison
equal deleted inserted replaced
141:c4aaaa6d9c13 142:09c10061838c
1 #!/usr/bin/env python
2
3 def link(path_info, path=None):
4
5 segments = path_info.split('/')
6 if segments[0]:
7 segments.insert(0, '')
8
9 if len(segments) <3:
10 if not path or path == '/':
11 return './'
12 return path
13
14 nlayers = len(segments[2:])
15 string = '../' * nlayers
16
17 if not path or path == '/':
18 return string
19 return string + path
20
21 if __name__ == '__main__':
22 import sys
23 assert len(sys.argv[1:]) == 2, "need two arguments"
24 path_info, path = sys.argv[1:]
25 print link(path_info, path)