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 if "SUPERV" in modules_list and not 'supervContainer' in args['standalone']:
146 args['standalone'].append("supervContainer")
149 return args, modules_list, modules_root_dir
151 # -----------------------------------------------------------------------------
153 def set_env(args, modules_list, modules_root_dir, silent=False):
154 """Add to the PATH-variables modules specific paths"""
156 python_version="python%d.%d" % sys.version_info[0:2]
157 modules_root_dir_list = []
158 if os.getenv('SALOME_BATCH') == None:
159 os.putenv('SALOME_BATCH','0')
161 modules_list = modules_list[:] + ["GUI"]
162 modules_list = modules_list[:] + ["KERNEL"]
163 for module in modules_list :
164 if modules_root_dir.has_key(module):
165 module_root_dir = modules_root_dir[module]
166 modules_root_dir_list[:0] = [module_root_dir]
167 if sys.platform == "win32":
168 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
171 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
173 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
175 if os.path.exists(module_root_dir + "/examples") :
176 add_path(os.path.join(module_root_dir,"examples"),
179 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
181 # add lib before site-packages to load script instead of dll if any (win32 platform)
182 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
184 add_path(os.path.join(module_root_dir,get_lib_dir(),
185 python_version,"site-packages",
188 add_path(os.path.join(module_root_dir,get_lib_dir(),
189 python_version,"site-packages",
194 # set environment for SMESH plugins
195 if module == "SMESH" :
196 os.environ["SMESH_MeshersList"]="StdMeshers"
197 if not os.environ.has_key("SALOME_StdMeshersResources"):
198 os.environ["SALOME_StdMeshersResources"] \
199 = modules_root_dir["SMESH"]+"/share/"+salome_subdir+"/resources/smesh"
201 if args.has_key("SMESH_plugins"):
202 for plugin in args["SMESH_plugins"]:
204 if os.environ.has_key(plugin+"_ROOT_DIR"):
205 plugin_root = os.environ[plugin+"_ROOT_DIR"]
207 # workaround to avoid modifications of existing environment
208 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
209 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
212 if plugin_root != "":
213 os.environ["SMESH_MeshersList"] \
214 = os.environ["SMESH_MeshersList"]+":"+plugin
215 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
216 os.environ["SALOME_"+plugin+"Resources"] \
217 = plugin_root+"/share/"+salome_subdir+"/resources/"+plugin.lower()
218 add_path(os.path.join(plugin_root,get_lib_dir(),python_version, "site-packages",salome_subdir), "PYTHONPATH")
219 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PYTHONPATH")
221 if sys.platform == "win32":
222 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PATH")
224 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
225 add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
226 add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
232 if sys.platform == 'win32':
233 os.environ["SALOMEPATH"]=";".join(modules_root_dir_list)
235 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
237 # set trace environment variable
239 if not os.environ.has_key("SALOME_trace"):
240 os.environ["SALOME_trace"]="local"
242 os.environ["SALOME_trace"]="file:"+args['file'][0]
244 os.environ["SALOME_trace"]="with_logger"
246 # set environment for SUPERV module
247 os.environ["ENABLE_MACRO_NODE"]="1"
248 # set resources variables if not yet set
249 # Done now by launchConfigureParser.py
250 #if os.getenv("GUI_ROOT_DIR"):
251 #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"
253 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
254 = os.path.join(modules_root_dir["KERNEL"],"share",
255 salome_subdir,"resources","kernel")
257 if "GEOM" in modules_list:
258 if verbose() and not silent: print "GEOM OCAF Resources"
260 # set CSF_PluginDefaults variable only if it is not customized
263 if not os.getenv("CSF_PluginDefaults"):
264 os.environ["CSF_PluginDefaults"] \
265 = os.path.join(modules_root_dir["GEOM"],"share",
266 salome_subdir,"resources","geom")
267 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
268 = os.path.join(modules_root_dir["GEOM"],"share",
269 salome_subdir,"resources","geom")
270 if verbose() and not silent: print "GEOM Shape Healing Resources"
271 os.environ["CSF_ShHealingDefaults"] \
272 = os.path.join(modules_root_dir["GEOM"],"share",
273 salome_subdir,"resources","geom")
275 # -----------------------------------------------------------------------------
277 def main(silent=False):
278 args, modules_list, modules_root_dir = get_config(silent=silent)
279 set_env(args, modules_list, modules_root_dir, silent=silent)
282 # -----------------------------------------------------------------------------
284 if __name__ == "__main__":