7 # Preliminary work to initialize path to SALOME Python modules
9 currentPath = os.path.dirname(__file__)
10 homePath = os.path.realpath(os.path.expanduser('~'))
11 appliPath = os.path.relpath(currentPath, homePath)
13 pattern = "/bin/salome/appliskel"
14 if appliPath.endswith(pattern):
15 appliPath = appliPath[:-len(pattern)]
17 absoluteAppliPath = os.path.join(homePath, appliPath)
18 os.environ['APPLI'] = appliPath # needed to convert .sh environment files
19 os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
21 # define folder to store omniorb config (initially in virtual application folder)
22 #omniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
23 omniorbUserPath = os.path.join(homePath, appliPath, "USERS")
24 os.environ['OMNIORB_USER_PATH'] = omniorbUserPath
25 if not os.path.exists(omniorbUserPath):
26 os.makedirs(omniorbUserPath)
28 sys.path[:0] = [absoluteAppliPath+'/bin/salome']
29 # End of preliminary work
31 def __listDirectory(path):
33 for root, dirs, files in os.walk(path):
34 configFileNames = glob.glob(os.path.join(root,'*.cfg')) + glob.glob(os.path.join(root,'*.sh'))
35 allFiles += configFileNames
39 def __getConfigFileNamesDefault():
40 absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
41 envdDir = absoluteAppliPath + '/env.d'
42 if os.path.isdir(envdDir):
43 configFileNames = __listDirectory(envdDir)
47 return configFileNames
50 def __getConfigFileNames(args):
51 # special case: configuration files are provided by user
52 # Search for command-line argument(s) --config=file1,file2,..., filen
53 # Search for command-line argument(s) --config=dir1,dir2,..., dirn
54 configOptionPrefix = "--config="
55 configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
57 if len(configArgs) == 0:
58 return __getConfigFileNamesDefault(), args
60 args = [ x for x in args if not x.startswith(configOptionPrefix) ]
61 allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
64 for currentList in allLists:
65 elements = currentList.split(',')
67 elt = os.path.realpath(os.path.expanduser(elt))
68 if os.path.isdir(elt):
69 configFileNames += __listDirectory(elt)
71 configFileNames += [elt]
73 return configFileNames, args
77 if __name__ == "__main__":
80 # Identify application path then locate configuration files
82 configFileNames, args = __getConfigFileNames(args)
84 # Create a SalomeRunner which parses configFileNames to initialize environment
85 from salomeRunner import SalomeRunner, SalomeRunnerException
87 runner = SalomeRunner(configFileNames)
89 # Here set specific variables, if needed
90 # runner.addToPath('mypath')
91 # runner.addToLdLibraryPath('myldlibrarypath')
92 # runner.addToPythonPath('mypythonpath')
93 # runner.setEnviron('myvarname', 'value')
96 # Start SALOME, parsing command line arguments
98 print 'Thank you for using SALOME!'
100 except SalomeRunnerException, e:
102 logging.getLogger("salome").error(e)