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):
41 newpath[:0] = [ directory ]
42 newpath = string.join(newpath, splitsym)
43 os.environ[variable_name] = newpath
44 if variable_name == "PYTHONPATH":
45 sys.path[:0] = [directory]
47 # -----------------------------------------------------------------------------
51 Get list of modules, paths.
53 Read args from launch configure xml file and command line options.
54 Check variables <module>_ROOT_DIR and set list of used modules.
55 Return args, modules_list, modules_root_dir
58 # read args from launch configure xml file and command line options
60 import launchConfigureParser
61 args = launchConfigureParser.args
63 # Check variables <module>_ROOT_DIR
64 # and set list of used modules (without KERNEL)
67 if args.has_key("modules"):
68 modules_list += args["modules"]
69 # KERNEL must be last in the list to locate it at the first place in PATH
71 modules_list[:0] = ["GUI"]
72 modules_list[:0] = ["KERNEL"]
73 modules_list.reverse()
78 for module in modules_list :
79 module_variable=module.upper()+"_ROOT_DIR"
80 if not os.environ.has_key(module_variable):
81 print "*******************************************************"
83 print "* Environment variable",module_variable,"must be set"
84 print "* Module", module, "will be not available"
86 print "********************************************************"
87 to_remove_list.append(module)
90 module_root_dir = os.environ[module_variable]
91 modules_root_dir[module]=module_root_dir
93 for to_remove in to_remove_list:
94 modules_list.remove(to_remove)
96 while "KERNEL" in modules_list:
97 modules_list.remove("KERNEL")
100 while "GUI" in modules_list:
101 modules_list.remove("GUI")
104 if "SUPERV" in modules_list and not 'superv' in args['standalone']:
105 args['standalone'].append("superv")
108 return args, modules_list, modules_root_dir
110 # -----------------------------------------------------------------------------
112 def set_env(args, modules_list, modules_root_dir):
113 """Add to the PATH-variables modules specific paths"""
115 python_version="python%d.%d" % sys.version_info[0:2]
116 modules_root_dir_list = []
118 modules_list = modules_list[:] + ["GUI"]
119 modules_list = modules_list[:] + ["KERNEL"]
120 for module in modules_list :
121 if modules_root_dir.has_key(module):
122 module_root_dir = modules_root_dir[module]
123 modules_root_dir_list[:0] = [module_root_dir]
124 if sys.platform == "win32":
125 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
128 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
130 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
132 if os.path.exists(module_root_dir + "/examples") :
133 add_path(os.path.join(module_root_dir,"examples"),
136 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
138 # add lib before site-packages to load script instead of dll if any (win32 platform)
139 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
141 add_path(os.path.join(module_root_dir,"lib",
142 python_version,"site-packages",
145 add_path(os.path.join(module_root_dir,"lib",
146 python_version,"site-packages",
153 if sys.platform == 'win32':
154 os.environ["SALOMEPATH"]=";".join(modules_root_dir_list)
156 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
158 # set trace environment variable
160 if not os.environ.has_key("SALOME_trace"):
161 os.environ["SALOME_trace"]="local"
163 os.environ["SALOME_trace"]="file:"+args['file'][0]
165 os.environ["SALOME_trace"]="with_logger"
167 # set environment for SMESH plugins
169 if "SMESH" in modules_list:
170 os.environ["SMESH_MeshersList"]="StdMeshers"
171 if not os.environ.has_key("SALOME_StdMeshersResources"):
172 os.environ["SALOME_StdMeshersResources"] \
173 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
175 if args.has_key("SMESH_plugins"):
176 for plugin in args["SMESH_plugins"]:
178 if os.environ.has_key(plugin+"_ROOT_DIR"):
179 plugin_root = os.environ[plugin+"_ROOT_DIR"]
181 # workaround to avoid modifications of existing environment
182 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
183 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
186 if plugin_root != "":
187 os.environ["SMESH_MeshersList"] \
188 = os.environ["SMESH_MeshersList"]+":"+plugin
189 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
190 os.environ["SALOME_"+plugin+"Resources"] \
191 = plugin_root+"/share/"+args["appname"]+"/resources"
192 add_path(os.path.join(plugin_root,"lib",python_version,
193 "site-packages",salome_subdir),
195 add_path(os.path.join(plugin_root,"lib",salome_subdir),
197 add_path(os.path.join(plugin_root,"lib",salome_subdir),
199 add_path(os.path.join(plugin_root,"bin",salome_subdir),
201 add_path(os.path.join(plugin_root,"bin",salome_subdir),
206 # set environment for SUPERV module
207 os.environ["ENABLE_MACRO_NODE"]="1"
208 # set resources variables if not yet set
209 # Done now by launchConfigureParser.py
210 #if os.getenv("GUI_ROOT_DIR"):
211 #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
212 #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
214 # set CSF_PluginDefaults variable only if it is not customized
216 if not os.getenv("CSF_PluginDefaults"):
217 os.environ["CSF_PluginDefaults"] \
218 = os.path.join(modules_root_dir["KERNEL"],"share",
219 salome_subdir,"resources")
220 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
221 = os.path.join(modules_root_dir["KERNEL"],"share",
222 salome_subdir,"resources")
224 if "GEOM" in modules_list:
225 print "GEOM OCAF Resources"
226 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
227 = os.path.join(modules_root_dir["GEOM"],"share",
228 salome_subdir,"resources")
229 print "GEOM Shape Healing Resources"
230 os.environ["CSF_ShHealingDefaults"] \
231 = os.path.join(modules_root_dir["GEOM"],"share",
232 salome_subdir,"resources")
234 # -----------------------------------------------------------------------------
237 args, modules_list, modules_root_dir = get_config()
238 set_env(args, modules_list, modules_root_dir)
241 # -----------------------------------------------------------------------------
243 if __name__ == "__main__":