Back to index

salome-smesh  6.5.0
Functions
smesh_setenv Namespace Reference

Functions

def set_env

Function Documentation

def smesh_setenv.set_env (   args)
Add to the PATH-variables modules specific paths

Definition at line 27 of file smesh_setenv.py.

00027 
00028 def set_env(args):
00029     """Add to the PATH-variables modules specific paths"""
00030     psep = os.pathsep
00031     python_version="python%d.%d" % sys.version_info[0:2]
00032 
00033 
00034     if not os.environ.has_key("SALOME_StdMeshersResources"):
00035         os.environ["SALOME_StdMeshersResources"] \
00036         = os.path.join(os.environ["SMESH_ROOT_DIR"],"share",salome_subdir,"resources","smesh")
00037         pass
00038 
00039     # find plugins
00040     plugin_list = []
00041     resource_path_list = []
00042     for env_var in os.environ.keys():
00043         value = os.environ[env_var]
00044         if env_var[-9:] == "_ROOT_DIR" and value:
00045             plugin_root = value
00046             plugin = env_var[:-9] # plugin name may have wrong case
00047 
00048             # look for NAMEOFPlugin.xml file among resource files
00049             resource_dir = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
00050             if not os.access( resource_dir, os.F_OK ): continue
00051             for resource_file in os.listdir( resource_dir ):
00052                 if not resource_file.endswith( ".xml") or \
00053                    resource_file.lower() != plugin.lower() + ".xml":
00054                     continue
00055                 # use "resources" attribute of "meshers-group" as name of plugin in a right case
00056                 from xml.dom.minidom import parse
00057                 xml_doc = parse( os.path.join( resource_dir, resource_file ))
00058                 meshers_nodes = xml_doc.getElementsByTagName("meshers-group")
00059                 if not meshers_nodes or not meshers_nodes[0].hasAttribute("resources"): continue
00060                 plugin = meshers_nodes[0].getAttribute("resources")
00061                 if plugin in plugin_list: continue
00062 
00063                 # add paths of plugin
00064               plugin_list.append(plugin)
00065                 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
00066                     resource_path = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
00067                     os.environ["SALOME_"+plugin+"Resources"] = resource_path
00068                     resource_path_list.append( resource_path )
00069                     add_path(os.path.join(plugin_root,get_lib_dir(),python_version, "site-packages",salome_subdir), "PYTHONPATH")
00070                     add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PYTHONPATH")
00071                     
00072                     if sys.platform == "win32":
00073                         add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PATH")
00074                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
00075                     else:
00076                         add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
00077                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
00078                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
00079                         pass
00080                     pass
00081                 break
00082     plugin_list.append("StdMeshers")
00083     os.environ["SMESH_MeshersList"] = ":".join(plugin_list)
00084     os.environ["SalomeAppConfig"] = os.environ["SalomeAppConfig"] + psep + psep.join(resource_path_list)
00085