3 # Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 def __detectAppliPath(fromPath):
26 detection_criterion = "USERS" # the application folder is found if it contains a USERS subfolder
28 users_folder = os.path.join(fromPath, detection_criterion)
29 if os.path.isdir(users_folder):
32 pattern = "/bin/salome/appliskel"
33 if fromPath.endswith(pattern):
34 currentPath = __detectAppliPath(fromPath[:-len(pattern)])
35 if not currentPath is None:
38 if sys.platform.startswith("linux"):
39 filename = os.path.basename(__file__)
40 link_target = os.readlink(os.path.join(fromPath,filename)) # LINUX ONLY
41 currentPath = os.path.dirname(os.path.abspath(link_target))
42 return __detectAppliPath(currentPath)
47 # Preliminary work to initialize path to SALOME Python modules
49 currentPath = os.path.dirname( os.path.abspath( __file__ ) )
50 homePath = os.path.realpath(os.path.expanduser('~'))
52 appliPath = __detectAppliPath(currentPath)
55 print "ERROR: Unable to find application folder"
58 appliPath = os.path.relpath(appliPath, homePath)
59 absoluteAppliPath = os.path.join(homePath, appliPath)
60 os.environ['APPLI'] = appliPath # needed to convert .sh environment files
61 os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
63 sys.path[:0] = [absoluteAppliPath+'/bin/salome']
65 # define folder to store omniorb config (initially in virtual application folder)
67 from salomeContextUtils import setOmniOrbUserPath
72 # End of preliminary work
75 # Identify application path then locate configuration files
78 if args == ['--help']:
79 from salomeContext import usage
83 from salomeContextUtils import getConfigFileNames
84 configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
85 if len(unexisting) > 0:
86 print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting)
89 # Create a SalomeContext which parses configFileNames to initialize environment
90 from salomeContextUtils import SalomeContextException
92 from salomeContext import SalomeContext
93 context = SalomeContext(configFileNames)
95 # Here set specific variables, if needed
96 # context.addToPath('mypath')
97 # context.addToLdLibraryPath('myldlibrarypath')
98 # context.addToPythonPath('mypythonpath')
99 # context.setVariable('myvarname', 'value')
101 # Start SALOME, parsing command line arguments
102 (out, err), returncode = context.runSalome(args)
103 #print 'Thank you for using SALOME!'
106 sys.stdout.write(out)
109 sys.stderr.write(err)
112 except SalomeContextException, e:
114 logging.getLogger("salome").error(e)
118 if __name__ == "__main__":