5 def relpath(target, base):
6 """ Find relative path from base to target
7 if target== "/local/chris/appli" and base== "/local/chris" the result is appli
8 if target== /tmp/appli and base /local/chris the result is ../../tmp/appli
10 target=target.split(os.path.sep)
11 base=base.split(os.path.sep)
12 for i in xrange(len(base)):
13 if base[i] != target[i]:
17 p=['..']*(len(base)-i-1)+target[i+1:]
20 return os.path.join( *p )
22 def set_var(VAR, strpath):
23 """Set VAR environment variable """
24 value = "%r" % strpath
25 shell = os.getenv('SHELL')
26 if shell and shell.endswith('csh'):
27 return "setenv %s %s" % (VAR, value)
29 return "export %s=%s" % (VAR, value)
32 applipath=relpath(os.path.abspath(os.path.dirname(__file__)),os.path.abspath(os.getenv('HOME')))
34 #print set_var('APPLI', applipath)