3 import sys, os, string, glob, time, pickle
5 # this file is extraction of set_env from runSalome.py
6 # for reusage in automated tests
8 # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc.
9 # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used.
10 # but after - 'appname' = "SalomeApp", so using it in making the subdirectory is an error.
11 salome_subdir = "salome"
14 # -----------------------------------------------------------------------------
16 def add_path(directory, variable_name):
17 """Function helper to add environment variables"""
18 if sys.platform == "win32":
22 if not os.environ.has_key(variable_name):
23 os.environ[variable_name] = ""
25 if os.path.exists(directory):
27 for _dir in os.environ[variable_name].split(splitsym):
28 if os.path.exists(_dir):
30 if not os.path.samefile(_dir, directory):
37 if os.path.abspath(_dir) != os.path.abspath(directory):
42 newpath[:0] = [ directory ]
43 newpath = string.join(newpath, splitsym)
44 os.environ[variable_name] = newpath
45 if variable_name == "PYTHONPATH":
46 sys.path[:0] = [directory]
48 # -----------------------------------------------------------------------------
52 if __lib__dir__: return __lib__dir__
54 if platform.architecture()[0] == "64bit":
55 __lib__dir__ = "lib64"
60 # -----------------------------------------------------------------------------
64 Get list of modules, paths.
66 Read args from launch configure xml file and command line options.
67 Check variables <module>_ROOT_DIR and set list of used modules.
68 Return args, modules_list, modules_root_dir
71 # read args from launch configure xml file and command line options
73 import launchConfigureParser
74 args = launchConfigureParser.get_env()
76 # Check variables <module>_ROOT_DIR
77 # and set list of used modules (without KERNEL)
80 if args.has_key("modules"):
81 modules_list += args["modules"]
82 # KERNEL must be last in the list to locate it at the first place in PATH
84 modules_list[:0] = ["GUI"]
85 modules_list[:0] = ["KERNEL"]
86 modules_list.reverse()
91 for module in modules_list :
92 module_variable=module.upper()+"_ROOT_DIR"
93 if not os.environ.has_key(module_variable):
94 print "*******************************************************"
96 print "* Environment variable",module_variable,"must be set"
97 print "* Module", module, "will be not available"
99 print "********************************************************"
100 to_remove_list.append(module)
103 module_root_dir = os.environ[module_variable]
104 modules_root_dir[module]=module_root_dir
106 for to_remove in to_remove_list:
107 modules_list.remove(to_remove)
109 while "KERNEL" in modules_list:
110 modules_list.remove("KERNEL")
113 while "GUI" in modules_list:
114 modules_list.remove("GUI")
117 if "SUPERV" in modules_list and not 'superv' in args['standalone']:
118 args['standalone'].append("superv")
121 return args, modules_list, modules_root_dir
123 # -----------------------------------------------------------------------------
125 def set_env(args, modules_list, modules_root_dir):
126 """Add to the PATH-variables modules specific paths"""
128 python_version="python%d.%d" % sys.version_info[0:2]
129 modules_root_dir_list = []
131 modules_list = modules_list[:] + ["GUI"]
132 modules_list = modules_list[:] + ["KERNEL"]
133 for module in modules_list :
134 if modules_root_dir.has_key(module):
135 module_root_dir = modules_root_dir[module]
136 modules_root_dir_list[:0] = [module_root_dir]
137 if sys.platform == "win32":
138 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
141 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
143 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
145 if os.path.exists(module_root_dir + "/examples") :
146 add_path(os.path.join(module_root_dir,"examples"),
149 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
151 # add lib before site-packages to load script instead of dll if any (win32 platform)
152 add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
154 add_path(os.path.join(module_root_dir,get_lib_dir(),
155 python_version,"site-packages",
158 add_path(os.path.join(module_root_dir,get_lib_dir(),
159 python_version,"site-packages",
166 if sys.platform == 'win32':
167 os.environ["SALOMEPATH"]=";".join(modules_root_dir_list)
169 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
171 # set trace environment variable
173 if not os.environ.has_key("SALOME_trace"):
174 os.environ["SALOME_trace"]="local"
176 os.environ["SALOME_trace"]="file:"+args['file'][0]
178 os.environ["SALOME_trace"]="with_logger"
180 # set environment for SMESH plugins
182 if "SMESH" in modules_list:
183 os.environ["SMESH_MeshersList"]="StdMeshers"
184 if not os.environ.has_key("SALOME_StdMeshersResources"):
185 os.environ["SALOME_StdMeshersResources"] \
186 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources/smesh"
188 if args.has_key("SMESH_plugins"):
189 for plugin in args["SMESH_plugins"]:
191 if os.environ.has_key(plugin+"_ROOT_DIR"):
192 plugin_root = os.environ[plugin+"_ROOT_DIR"]
194 # workaround to avoid modifications of existing environment
195 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
196 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
199 if plugin_root != "":
200 os.environ["SMESH_MeshersList"] \
201 = os.environ["SMESH_MeshersList"]+":"+plugin
202 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
203 os.environ["SALOME_"+plugin+"Resources"] \
204 = plugin_root+"/share/"+args["appname"]+"/resources/"+plugin.lower()
205 add_path(os.path.join(plugin_root,get_lib_dir(),python_version,
206 "site-packages",salome_subdir),
208 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
212 if sys.platform == "win32":
213 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
216 add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
218 add_path(os.path.join(plugin_root,"bin",salome_subdir),
220 add_path(os.path.join(plugin_root,"bin",salome_subdir),
225 # set environment for SUPERV module
226 os.environ["ENABLE_MACRO_NODE"]="1"
227 # set resources variables if not yet set
228 # Done now by launchConfigureParser.py
229 #if os.getenv("GUI_ROOT_DIR"):
230 #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
231 #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
233 # set CSF_PluginDefaults variable only if it is not customized
235 if not os.getenv("CSF_PluginDefaults"):
236 os.environ["CSF_PluginDefaults"] \
237 = os.path.join(modules_root_dir["KERNEL"],"share",
238 salome_subdir,"resources","kernel")
239 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
240 = os.path.join(modules_root_dir["KERNEL"],"share",
241 salome_subdir,"resources","kernel")
243 if "GEOM" in modules_list:
244 print "GEOM OCAF Resources"
245 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
246 = os.path.join(modules_root_dir["GEOM"],"share",
247 salome_subdir,"resources","geom")
248 print "GEOM Shape Healing Resources"
249 os.environ["CSF_ShHealingDefaults"] \
250 = os.path.join(modules_root_dir["GEOM"],"share",
251 salome_subdir,"resources","geom")
253 # -----------------------------------------------------------------------------
256 args, modules_list, modules_root_dir = get_config()
257 set_env(args, modules_list, modules_root_dir)
260 # -----------------------------------------------------------------------------
262 if __name__ == "__main__":