Salome HOME
215a49e8d4e6a27c1b01205b62004c67e4b7f20f
[modules/kernel.git] / bin / appliskel / salome_starter.py
1 #! /usr/bin/env python
2
3 # Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
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.
9 #
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.
14 #
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
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 import os
23 import sys
24
25 # This file is imported by launchers to help with application folder detection.
26 # Import is possible because Python automatically add to sys.path the folder of
27 # a running script (here a launcher).
28
29 def __detectAppliPath(fromPath, launcherFile):
30   detection_criterion = "USERS" # the application folder is found if it contains a USERS subfolder
31
32   users_folder = os.path.join(fromPath, detection_criterion)
33   if os.path.isdir(users_folder):
34     return fromPath
35
36   pattern = "/bin/salome/appliskel"
37   if fromPath.endswith(pattern):
38     currentPath = __detectAppliPath(fromPath[:-len(pattern)], launcherFile)
39     if not currentPath is None:
40       return currentPath
41
42   if sys.platform.startswith("linux"):
43     link_target = os.readlink(os.path.join(fromPath,launcherFile)) # LINUX ONLY
44     currentPath = os.path.dirname(os.path.abspath(link_target))
45     return __detectAppliPath(currentPath, launcherFile)
46
47   return None
48 #
49
50 # Preliminary work to initialize path to SALOME Python modules
51 def initialize(launcherPath, launcherFile):
52   homePath = os.path.realpath(os.path.expanduser('~'))
53   appliPath = __detectAppliPath(launcherPath, launcherFile)
54
55   if appliPath is None:
56     print "ERROR: Unable to find application folder"
57     sys.exit(0)
58
59   appliPath = os.path.relpath(appliPath, homePath)
60   absoluteAppliPath = os.path.join(homePath, appliPath)
61   os.environ['APPLI'] = appliPath # needed to convert .sh environment files
62   os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
63
64   sys.path[:0] = [absoluteAppliPath+'/bin/salome']
65
66   # define folder to store omniorb config (initially in virtual application folder)
67   try:
68     from salomeContextUtils import setOmniOrbUserPath
69     setOmniOrbUserPath()
70   except Exception, e:
71     print e
72     sys.exit(1)
73 # End of preliminary work