2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import sys, os, string, glob, time, pickle
25 from launchConfigureParser import verbose
27 # this file is extraction of set_env from runSalome.py
28 # for reusage in automated tests
30 # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc.
31 # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used.
32 # but after - 'appname' = "SalomeApp", so using it in making the subdirectory is an error.
33 salome_subdir = "salome"
36 # -----------------------------------------------------------------------------
38 def add_path(directory, variable_name):
39 """Function helper to add environment variables"""
40 if sys.platform == "win32":
44 if not os.environ.has_key(variable_name):
45 os.environ[variable_name] = ""
47 if os.path.exists(directory):
49 for _dir in os.environ[variable_name].split(splitsym):
50 if os.path.exists(_dir):
51 if sys.platform != "win32":
52 if not os.path.samefile(_dir, directory):
57 if os.path.abspath(_dir) != os.path.abspath(directory):
61 newpath[:0] = [ directory ]
62 newpath = string.join(newpath, splitsym)
63 os.environ[variable_name] = newpath
64 if variable_name == "PYTHONPATH":
65 sys.path[:0] = [directory]
67 # -----------------------------------------------------------------------------
72 if __lib__dir__: return __lib__dir__
77 # -----------------------------------------------------------------------------
79 def get_config(silent=False):
81 Get list of modules, paths.
83 Read args from launch configure xml file and command line options.
84 Check variables <module>_ROOT_DIR and set list of used modules.
85 Return args, modules_list, modules_root_dir
88 # read args from launch configure xml file and command line options
90 #*** Test additional option
92 #*** help_str = "Test options addition."
93 #*** o_j = optparse.Option("-j", "--join", action="store_true", dest="join", help=help_str)
95 import launchConfigureParser
96 args = launchConfigureParser.get_env()
98 #*** Test additional option
99 #*** args = launchConfigureParser.get_env([o_j])
100 #*** if args.has_key("join"): print args["join"]
102 # Check variables <module>_ROOT_DIR
103 # and set list of used modules (without KERNEL)
106 if args.has_key("modules"):
107 modules_list += args["modules"]
108 # KERNEL must be last in the list to locate it at the first place in PATH
110 modules_list[:0] = ["GUI"]
111 modules_list[:0] = ["KERNEL"]
112 modules_list.reverse()
114 modules_root_dir = {}
117 for module in modules_list :
118 module_variable=module+"_ROOT_DIR"
119 if not os.environ.has_key(module_variable):
121 print "*******************************************************"
123 print "* Environment variable",module_variable,"must be set"
124 print "* Module", module, "will be not available"
126 print "********************************************************"
128 to_remove_list.append(module)
131 module_root_dir = os.environ[module_variable]
132 modules_root_dir[module]=module_root_dir
134 for to_remove in to_remove_list:
135 modules_list.remove(to_remove)
137 while "KERNEL" in modules_list:
138 modules_list.remove("KERNEL")
141 while "GUI" in modules_list:
142 modules_list.remove("GUI")
145 return args, modules_list, modules_root_dir
147 # -----------------------------------------------------------------------------
149 def set_env(args, modules_list, modules_root_dir, silent=False):
150 """Add to the PATH-variables modules specific paths"""
153 from salome_utils import getTmpDir, generateFileName, makeTmpDir, getPortNumber
155 # create temporary directory for environment files needed by modules from the list
156 port = getPortNumber(False)
158 tmp_dir = getTmpDir()
159 env_dir = generateFileName(tmp_dir, prefix="env", with_port=True)
163 python_version="python%d.%d" % sys.version_info[0:2]
164 modules_root_dir_list = []
165 if os.getenv('SALOME_BATCH') == None:
166 os.putenv('SALOME_BATCH','0')
168 modules_list = modules_list[:] + ["GUI"]
169 modules_list = modules_list[:] + ["KERNEL"]
170 for module in modules_list :
171 if modules_root_dir.has_key(module):
172 module_root_dir = modules_root_dir[module]
173 modules_root_dir_list[:0] = [module_root_dir]
174 if sys.platform == "win32":
175 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
178 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
180 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
182 if os.path.exists(module_root_dir + "/examples") :
183 add_path(os.path.join(module_root_dir,"examples"),
186 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
188 # add lib before site-packages to load script instead of dll if any (win32 platform)
189 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
191 add_path(os.path.join(module_root_dir,get_lib_dir(),
192 python_version,"site-packages",
195 add_path(os.path.join(module_root_dir,get_lib_dir(),
196 python_version,"site-packages",
201 # set environment by modules from the list
204 mod=__import__(module.lower()+"_setenv")
213 if sys.platform == 'win32':
214 os.environ["SALOMEPATH"]=";".join(modules_root_dir_list)
216 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
218 # set trace environment variable
220 if not os.environ.has_key("SALOME_trace"):
221 os.environ["SALOME_trace"]="local"
223 os.environ["SALOME_trace"]="file:"+args['file'][0]
225 os.environ["SALOME_trace"]="with_logger"
227 # set resources variables if not yet set
229 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
230 = os.path.join(modules_root_dir["KERNEL"],"share",
231 salome_subdir,"resources","kernel")
233 # -----------------------------------------------------------------------------
235 def main(silent=False):
236 args, modules_list, modules_root_dir = get_config(silent=silent)
237 set_env(args, modules_list, modules_root_dir, silent=silent)
240 # -----------------------------------------------------------------------------
242 if __name__ == "__main__":