1 # Copyright (C) 2014-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # This file is imported by launchers to help with application folder detection.
24 # Import is possible because Python automatically add to sys.path the folder of
25 # a running script (here a launcher).
27 def __detectAppliPath(fromPath, launcherFile):
28 detection_criterion = "USERS" # the application folder is found if it contains a USERS subfolder
30 users_folder = os.path.join(fromPath, detection_criterion)
31 if os.path.isdir(users_folder):
34 pattern = os.path.sep + os.path.join("bin", "salome", "appliskel")
35 if fromPath.endswith(pattern):
36 currentPath = __detectAppliPath(fromPath[:-len(pattern)], launcherFile)
37 if not currentPath is None:
40 if sys.platform.startswith("linux"):
41 link_target = os.readlink(os.path.join(fromPath,launcherFile)) # LINUX ONLY
42 currentPath = os.path.dirname(os.path.abspath(link_target))
43 return __detectAppliPath(currentPath, launcherFile)
48 # Preliminary work to initialize path to SALOME Python modules
49 def initialize(launcherPath, launcherFile):
50 homePath = os.path.realpath(os.path.expanduser('~'))
51 appliPath = __detectAppliPath(launcherPath, launcherFile)
54 print("ERROR: Unable to find application folder")
57 appliPath = os.path.relpath(appliPath, homePath)
58 absoluteAppliPath = os.path.join(homePath, appliPath)
59 os.environ['APPLI'] = appliPath # needed to convert .sh environment files
60 os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
62 sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome", "test"))]
63 sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome"))]
65 # define folder to store omniorb config (initially in virtual application folder)
67 from salomeContextUtils import setOmniOrbUserPath
69 except Exception as e:
72 # End of preliminary work