]> SALOME platform Git repositories - modules/yacs.git/blob - bin/appliskel/salome
Salome HOME
Rename new launcher as "salome".
[modules/yacs.git] / bin / appliskel / salome
1 #! /usr/bin/env python
2
3 import os
4 import sys
5 import glob
6
7 # Preliminary work to initialize path to SALOME Python modules
8 def __initialize():
9   currentPath = os.path.dirname(__file__)
10   homePath = os.path.realpath(os.path.expanduser('~'))
11   appliPath = os.path.relpath(currentPath, homePath)
12
13   pattern = "/bin/salome/appliskel"
14   if appliPath.endswith(pattern):
15     appliPath = appliPath[:-len(pattern)]
16
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
20
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)
27
28   sys.path[:0] = [absoluteAppliPath+'/bin/salome']
29 # End of preliminary work
30
31 def __listDirectory(path):
32   allFiles = []
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
36   return allFiles
37 #
38
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)
44   else:
45     configFileNames = []
46
47   return configFileNames
48 #
49
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) ]
56
57   if len(configArgs) == 0:
58     return __getConfigFileNamesDefault(), args
59
60   args = [ x for x in args if not x.startswith(configOptionPrefix) ]
61   allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
62
63   configFileNames = []
64   for currentList in allLists:
65     elements = currentList.split(',')
66     for elt in elements:
67       elt = os.path.realpath(os.path.expanduser(elt))
68       if os.path.isdir(elt):
69         configFileNames += __listDirectory(elt)
70       else:
71         configFileNames += elt
72
73   return configFileNames, args
74 #
75
76
77 if __name__ == "__main__":
78   args = sys.argv[1:]
79
80   # Identify application path then locate configuration files
81   __initialize()
82   configFileNames, args = __getConfigFileNames(args)
83
84   # Create a SalomeRunner which parses configFileNames to initialize environment
85   from salomeRunner import SalomeRunner, SalomeRunnerException
86   try:
87     runner = SalomeRunner(configFileNames)
88
89     # Here set specific variables, if needed
90     # runner.addToPath('mypath')
91     # runner.addToLdLibraryPath('myldlibrarypath')
92     # runner.addToPythonPath('mypythonpath')
93     # runner.setEnviron('myvarname', 'value')
94
95
96     # Start SALOME, parsing command line arguments
97     runner.go(args)
98     print 'Thank you for using SALOME!'
99
100   except SalomeRunnerException, e:
101     import logging
102     logging.getLogger("salome").error(e)
103     sys.exit(1)
104 #