Back to index

salome-smesh  6.5.0
smesh_setenv.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #  -*- coding: iso-8859-1 -*-
00003 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00004 #
00005 # This library is free software; you can redistribute it and/or
00006 # modify it under the terms of the GNU Lesser General Public
00007 # License as published by the Free Software Foundation; either
00008 # version 2.1 of the License.
00009 #
00010 # This library is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 # Lesser General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU Lesser General Public
00016 # License along with this library; if not, write to the Free Software
00017 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 #
00019 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00020 #
00021 
00022 import os, sys
00023 from setenv import add_path, get_lib_dir, salome_subdir
00024 
00025 # -----------------------------------------------------------------------------
00026 
00027 def set_env(args):
00028     """Add to the PATH-variables modules specific paths"""
00029     psep = os.pathsep
00030     python_version="python%d.%d" % sys.version_info[0:2]
00031 
00032 
00033     if not os.environ.has_key("SALOME_StdMeshersResources"):
00034         os.environ["SALOME_StdMeshersResources"] \
00035         = os.path.join(os.environ["SMESH_ROOT_DIR"],"share",salome_subdir,"resources","smesh")
00036         pass
00037 
00038     # find plugins
00039     plugin_list = []
00040     resource_path_list = []
00041     for env_var in os.environ.keys():
00042         value = os.environ[env_var]
00043         if env_var[-9:] == "_ROOT_DIR" and value:
00044             plugin_root = value
00045             plugin = env_var[:-9] # plugin name may have wrong case
00046 
00047             # look for NAMEOFPlugin.xml file among resource files
00048             resource_dir = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
00049             if not os.access( resource_dir, os.F_OK ): continue
00050             for resource_file in os.listdir( resource_dir ):
00051                 if not resource_file.endswith( ".xml") or \
00052                    resource_file.lower() != plugin.lower() + ".xml":
00053                     continue
00054                 # use "resources" attribute of "meshers-group" as name of plugin in a right case
00055                 from xml.dom.minidom import parse
00056                 xml_doc = parse( os.path.join( resource_dir, resource_file ))
00057                 meshers_nodes = xml_doc.getElementsByTagName("meshers-group")
00058                 if not meshers_nodes or not meshers_nodes[0].hasAttribute("resources"): continue
00059                 plugin = meshers_nodes[0].getAttribute("resources")
00060                 if plugin in plugin_list: continue
00061 
00062                 # add paths of plugin
00063               plugin_list.append(plugin)
00064                 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
00065                     resource_path = os.path.join(plugin_root,"share",salome_subdir,"resources",plugin.lower())
00066                     os.environ["SALOME_"+plugin+"Resources"] = resource_path
00067                     resource_path_list.append( resource_path )
00068                     add_path(os.path.join(plugin_root,get_lib_dir(),python_version, "site-packages",salome_subdir), "PYTHONPATH")
00069                     add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PYTHONPATH")
00070                     
00071                     if sys.platform == "win32":
00072                         add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "PATH")
00073                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
00074                     else:
00075                         add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH")
00076                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PYTHONPATH")
00077                         add_path(os.path.join(plugin_root,"bin",salome_subdir), "PATH")
00078                         pass
00079                     pass
00080                 break
00081     plugin_list.append("StdMeshers")
00082     os.environ["SMESH_MeshersList"] = ":".join(plugin_list)
00083     os.environ["SalomeAppConfig"] = os.environ["SalomeAppConfig"] + psep + psep.join(resource_path_list)
00084