]> SALOME platform Git repositories - modules/kernel.git/blob - bin/appliskel/salome.py
Salome HOME
Merge from BR_KERNEL_REFACTORING
[modules/kernel.git] / bin / appliskel / salome.py
1 #! /usr/bin/env python
2
3 import os
4 import sys
5
6 # Preliminary work to initialize path to SALOME Python modules
7 def __initialize():
8   currentPath = os.path.dirname(__file__)
9   homePath = os.path.realpath(os.environ['HOME'])
10   appliPath = os.path.relpath(currentPath, homePath)
11   absoluteAppliPath = homePath+os.sep+appliPath
12   os.environ['APPLI'] = appliPath # needed to convert .sh environment files
13   os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
14
15   sys.path[:0] = [absoluteAppliPath+'/bin/salome']
16 # End of preliminary work
17
18 def __getConfigFileNamesDefault():
19   import glob
20
21   absoluteAppliPath = os.environ['ABSOLUTE_APPLI_PATH']
22   envdDir = absoluteAppliPath + '/env.d'
23   if os.path.isdir(envdDir):
24     configFileNames = glob.glob(envdDir+os.sep+'*.cfg') + glob.glob(envdDir+os.sep+'*.sh')
25     configFileNames = [os.path.basename(x) for x in configFileNames]
26   else:
27     configFileNames = []
28
29   configFileNames = [envdDir+'/'+x for x in configFileNames]
30   return configFileNames
31 #
32
33 def __getConfigFileNames(args):
34   # special case: configuration files are provided by user
35   # Search for command-line argument(s) --config=file1,file2,..., filen
36   configOptionPrefix = "--config="
37   configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
38
39   if len(configArgs) == 0:
40     return __getConfigFileNamesDefault(), args
41
42   args = [ x for x in args if not x.startswith(configOptionPrefix) ]
43   files = [ x.replace(configOptionPrefix, '') for x in configArgs ]
44   configFileNames = []
45   for x in files:
46     configFileNames += x.split(',')
47
48   return configFileNames, args
49 #
50
51 if __name__ == "__main__":
52   args = sys.argv[1:]
53
54   # Identify application path then locate configuration files
55   __initialize()
56   configFileNames, args = __getConfigFileNames(args)
57
58   # Create a SalomeRunner which parses configFileNames to initialize environment
59   from salomeRunner import SalomeRunner
60   runner = SalomeRunner(configFileNames)
61
62
63   # Here set specific variables, if needed
64   # runner.addToPath('mypath')
65   # runner.addToLdLibraryPath('myldlibrarypath')
66   # runner.addToPythonPath('mypythonpath')
67   # runner.setEnviron('myvarname', 'value')
68
69
70   # Start SALOME, parsing command line arguments
71   runner.go(args)
72
73   print 'Thank you for using SALOME!'
74 #