]> SALOME platform Git repositories - modules/kernel.git/blob - bin/appliskel/getAppliPath.py
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / bin / appliskel / getAppliPath.py
1 #!/usr/bin/env python
2
3 import os
4
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
9     """
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]:
14         i=i-1
15         #not in base
16         break
17     p=['..']*(len(base)-i-1)+target[i+1:]
18     if p == []:
19       return '.'
20     return os.path.join( *p )
21
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)
28     else:
29         return "export %s=%s" % (VAR, value)
30         
31
32 applipath=relpath(os.path.abspath(os.path.dirname(__file__)),os.path.abspath(os.getenv('HOME')))
33
34 #print set_var('APPLI', applipath)
35 print applipath