3 # Copyright (C) 2014-2017 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 # 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).
29 def __detectAppliPath(fromPath, launcherFile):
30 detection_criterion = "USERS" # the application folder is found if it contains a USERS subfolder
32 users_folder = os.path.join(fromPath, detection_criterion)
33 if os.path.isdir(users_folder):
36 pattern = os.path.sep + os.path.join("bin", "salome", "appliskel")
37 if fromPath.endswith(pattern):
38 currentPath = __detectAppliPath(fromPath[:-len(pattern)], launcherFile)
39 if not currentPath is None:
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)
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)
56 print("ERROR: Unable to find application folder")
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
64 sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome", "test"))]
65 sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome"))]
67 # define folder to store omniorb config (initially in virtual application folder)
69 from salomeContextUtils import setOmniOrbUserPath
71 except Exception as e:
74 # End of preliminary work