Salome HOME
7914df12466de675f2934d49a2c1478040dd90be
[modules/kernel.git] / bin / appliskel / salome
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( os.path.abspath( __file__ ) )
9   homePath = os.path.realpath(os.path.expanduser('~'))
10   appliPath = os.path.relpath(currentPath, homePath)
11
12   pattern = "/bin/salome/appliskel"
13   if appliPath.endswith(pattern):
14     appliPath = appliPath[:-len(pattern)]
15
16   absoluteAppliPath = os.path.join(homePath, appliPath)
17   os.environ['APPLI'] = appliPath # needed to convert .sh environment files
18   os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
19
20   sys.path[:0] = [absoluteAppliPath+'/bin/salome']
21
22   # define folder to store omniorb config (initially in virtual application folder)
23   try:
24     from salomeLauncherUtils import setOmniOrbUserPath
25     setOmniOrbUserPath()
26   except Exception, e:
27     print e
28     sys.exit(1)
29 # End of preliminary work
30
31 def main(args):
32   # Identify application path then locate configuration files
33   __initialize()
34
35   if args == ['--help']:
36     from salomeRunner import usage
37     usage()
38     sys.exit(0)
39
40   from salomeLauncherUtils import getConfigFileNames
41   configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
42   if len(unexisting) > 0:
43     print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting)
44     sys.exit(1)
45
46   # Create a SalomeRunner which parses configFileNames to initialize environment
47   try:
48     from salomeRunner import SalomeRunner, SalomeRunnerException
49     runner = SalomeRunner(configFileNames)
50
51     # Here set specific variables, if needed
52     # runner.addToPath('mypath')
53     # runner.addToLdLibraryPath('myldlibrarypath')
54     # runner.addToPythonPath('mypythonpath')
55     # runner.setEnviron('myvarname', 'value')
56
57     # Start SALOME, parsing command line arguments
58     runner.go(args)
59     print 'Thank you for using SALOME!'
60
61   except SalomeRunnerException, e:
62     import logging
63     logging.getLogger("salome").error(e)
64     sys.exit(1)
65 #
66
67 if __name__ == "__main__":
68   args = sys.argv[1:]
69   main(args)
70 #