Salome HOME
sh->cfg convert procedure, no delete temporary generated .cfg
[modules/kernel.git] / bin / setenv.py
index 7e1b93d80e610343a6f2831560e9423e49a365a0..9443fa1c1b6ce0bbbde594700af3c055d4873b7d 100755 (executable)
@@ -1,23 +1,26 @@
 #!/usr/bin/env python
-
-# Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
-#           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either 
+# License as published by the Free Software Foundation; either
 # version 2.1 of the License.
-# 
-# This library is distributed in the hope that it will be useful 
-# but WITHOUT ANY WARRANTY; without even the implied warranty of 
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Lesser General Public License for more details.
-# 
-# You should have received a copy of the GNU Lesser General Public  
-# License along with this library; if not, write to the Free Software 
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-# 
+#
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-# 
+#
 
 import sys, os, string, glob, time, pickle
 import orbmodule
@@ -70,18 +73,12 @@ def get_lib_dir():
     global __lib__dir__
     if __lib__dir__: return __lib__dir__
     import platform
-    if platform.architecture()[0] == "64bit":
-        if platform.machine() == "ia64":
-            __lib__dir__ = "lib"
-        else:
-            __lib__dir__ = "lib64"
-    else:
-        __lib__dir__ = "lib"
+    __lib__dir__ = "lib"
     return __lib__dir__
 
 # -----------------------------------------------------------------------------
 
-def get_config():
+def get_config(silent=False):
     """
     Get list of modules, paths.
     
@@ -122,12 +119,14 @@ def get_config():
     for module in modules_list :
         module_variable=module+"_ROOT_DIR"
         if not os.environ.has_key(module_variable):
-            print "*******************************************************"
-            print "*"
-            print "* Environment variable",module_variable,"must be set"
-            print "* Module", module, "will be not available"
-            print "*"
-            print "********************************************************"
+            if not silent:
+                print "*******************************************************"
+                print "*"
+                print "* Environment variable",module_variable,"must be set"
+                print "* Module", module, "will be not available"
+                print "*"
+                print "********************************************************"
+                pass
             to_remove_list.append(module)
             continue
             pass
@@ -145,17 +144,24 @@ def get_config():
         modules_list.remove("GUI")
         pass
 
-    if "SUPERV" in modules_list and not 'supervContainer' in args['standalone']:
-        args['standalone'].append("supervContainer")
-        pass
-   
     return args, modules_list, modules_root_dir
 
 # -----------------------------------------------------------------------------
 
-def set_env(args, modules_list, modules_root_dir):
+def set_env(args, modules_list, modules_root_dir, silent=False):
     """Add to the PATH-variables modules specific paths"""
     
+    import os
+    from salome_utils import getTmpDir, generateFileName, makeTmpDir, getPortNumber
+
+    # create temporary directory for environment files needed by modules from the list
+    port = getPortNumber(False)
+    if port:
+        tmp_dir = getTmpDir()
+        env_dir = generateFileName(tmp_dir, prefix="env", with_port=True)
+        makeTmpDir(env_dir)
+        pass
+
     python_version="python%d.%d" % sys.version_info[0:2]
     modules_root_dir_list = []
     if os.getenv('SALOME_BATCH') == None:
@@ -166,7 +172,8 @@ def set_env(args, modules_list, modules_root_dir):
     for module in modules_list :
         if modules_root_dir.has_key(module):
             module_root_dir = modules_root_dir[module]
-            modules_root_dir_list[:0] = [module_root_dir]
+            if module_root_dir not in modules_root_dir_list:
+              modules_root_dir_list[:0] = [module_root_dir]
             if sys.platform == "win32":
               add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
                      "PATH")
@@ -188,11 +195,28 @@ def set_env(args, modules_list, modules_root_dir):
                                   python_version,"site-packages",
                                   salome_subdir),
                      "PYTHONPATH")
+            import platform
+            if platform.machine() == "x86_64":
+                add_path(os.path.join(module_root_dir,"lib64",
+                                      python_version,"site-packages",
+                                      salome_subdir),
+                         "PYTHONPATH")
+                pass
             add_path(os.path.join(module_root_dir,get_lib_dir(),
                                   python_version,"site-packages",
                                   salome_subdir,
                                   "shared_modules"),
                      "PYTHONPATH")
+
+            # set environment by modules from the list
+            if port:
+                try:
+                    mod=__import__(module.lower()+"_setenv")
+                    mod.set_env(args)
+                    pass
+                except:
+                    pass
+                pass
             pass
         pass
 
@@ -210,85 +234,17 @@ def set_env(args, modules_list, modules_root_dir):
     if args['logger']:
         os.environ["SALOME_trace"]="with_logger"
 
-    # set environment for SMESH plugins
-
-    if "SMESH" in modules_list:
-        os.environ["SMESH_MeshersList"]="StdMeshers"
-        if not os.environ.has_key("SALOME_StdMeshersResources"):
-            os.environ["SALOME_StdMeshersResources"] \
-            = modules_root_dir["SMESH"]+"/share/"+salome_subdir+"/resources/smesh"
-            pass
-        if args.has_key("SMESH_plugins"):
-            for plugin in args["SMESH_plugins"]:
-                plugin_root = ""
-                if os.environ.has_key(plugin+"_ROOT_DIR"):
-                    plugin_root = os.environ[plugin+"_ROOT_DIR"]
-                else:
-                    # workaround to avoid modifications of existing environment
-                    if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
-                        plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
-                        pass
-                    pass
-                if plugin_root != "":
-                    os.environ["SMESH_MeshersList"] \
-                    = os.environ["SMESH_MeshersList"]+":"+plugin
-                    if not os.environ.has_key("SALOME_"+plugin+"Resources"):
-                        os.environ["SALOME_"+plugin+"Resources"] \
-                        = plugin_root+"/share/"+salome_subdir+"/resources/"+plugin.lower()
-                    add_path(os.path.join(plugin_root,get_lib_dir(),python_version,
-                                          "site-packages",salome_subdir),
-                             "PYTHONPATH")
-                    add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
-                             "PYTHONPATH")
-
-
-                    if sys.platform == "win32":
-                      add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
-                          "PATH")
-                    else:
-                      add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir),
-                               "LD_LIBRARY_PATH")
-                    add_path(os.path.join(plugin_root,"bin",salome_subdir),
-                             "PYTHONPATH")
-                    add_path(os.path.join(plugin_root,"bin",salome_subdir),
-                             "PATH")
-            pass
-        pass
-
-    # set environment for SUPERV module
-    os.environ["ENABLE_MACRO_NODE"]="1"
     # set resources variables if not yet set
-    # Done now by launchConfigureParser.py
-    #if os.getenv("GUI_ROOT_DIR"):
-        #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] =  os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"
 
     os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
     = os.path.join(modules_root_dir["KERNEL"],"share",
                    salome_subdir,"resources","kernel")
 
-    if "GEOM" in modules_list:
-        if verbose(): print "GEOM OCAF Resources" 
-        
-       # set CSF_PluginDefaults variable only if it is not customized
-        # by the user
-
-        if not os.getenv("CSF_PluginDefaults"):
-           os.environ["CSF_PluginDefaults"] \
-           = os.path.join(modules_root_dir["GEOM"],"share",
-                          salome_subdir,"resources","geom")
-        os.environ["CSF_GEOMDS_ResourcesDefaults"] \
-        = os.path.join(modules_root_dir["GEOM"],"share",
-                       salome_subdir,"resources","geom")
-        if verbose(): print "GEOM Shape Healing Resources"
-        os.environ["CSF_ShHealingDefaults"] \
-        = os.path.join(modules_root_dir["GEOM"],"share",
-                       salome_subdir,"resources","geom")
-
 # -----------------------------------------------------------------------------
 
-def main():
-    args, modules_list, modules_root_dir = get_config()
-    set_env(args, modules_list, modules_root_dir)
+def main(silent=False):
+    args, modules_list, modules_root_dir = get_config(silent=silent)
+    set_env(args, modules_list, modules_root_dir, silent=silent)
     return args
 
 # -----------------------------------------------------------------------------