From: ouv Date: Wed, 6 May 2009 13:08:35 +0000 (+0000) Subject: Improvement of "setenv.py" script - setting of custom enviroment by those modules... X-Git-Tag: V5_1_2rc1~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=615fed5a434a792544d27801f41fad1dc213f1c3;p=modules%2Fkernel.git Improvement of "setenv.py" script - setting of custom enviroment by those modules, which have it, is performed by their own "_setenv.py" scripts situated in their "bin" folders. --- diff --git a/bin/salome_utils.py b/bin/salome_utils.py index cf22daf17..61d609273 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -43,6 +43,8 @@ __all__ = [ 'getPortNumber', 'getTmpDir', 'generateFileName', + 'makeTmpDir', + 'uniteFiles', ] # --- @@ -346,3 +348,61 @@ def generateFileName( dir, prefix = None, suffix = None, extension = None, pass pass return os.path.normpath(name) + +# --- + +def makeTmpDir( path ): + """ + Make temporary directory with the specified path. + If the directory exists then clear its contents. + + Parameters: + - path : absolute path to the directory to be created. + """ + import os + + if os.path.exists( path ): + os.system( "rm -rf " + path + "/*" ) + pass + else: + os.makedirs( path, 0777 ) + pass + +# --- + +def uniteFiles( src_file, dest_file ): + """ + Unite contents of the source file with contents of the destination file + and put result of the uniting to the destination file. + If the destination file does not exist then the source file is simply + copied to its path. + + Parameters: + - src_file : absolute path to the source file + - dest_file : absolute path to the destination file + """ + import os + + if not os.path.exists( src_file ): + return + pass + + if os.path.exists( dest_file ): + # add a symbol of new line to contents of the destination file (just in case) + dest = open( dest_file, 'r' ) + dest_lines = dest.readlines() + dest.close() + + dest_lines.append( "\n" ) + + dest = open( dest_file, 'w' ) + dest.writelines( dest_lines ) + dest.close() + + command = "cat " + src_file + " >> " + dest_file + pass + else: + command = "cp " + src_file + " " + dest_file + pass + + os.system( command ) diff --git a/bin/setenv.py b/bin/setenv.py index 4eeff394b..cde2e1165 100755 --- a/bin/setenv.py +++ b/bin/setenv.py @@ -153,6 +153,14 @@ def get_config(silent=False): 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 + + # create temporary directory for environment files needed by modules from the list + tmp_dir = getTmpDir() + env_dir = generateFileName(tmp_dir, prefix="env", with_port=True) + makeTmpDir(env_dir) + python_version="python%d.%d" % sys.version_info[0:2] modules_root_dir_list = [] if os.getenv('SALOME_BATCH') == None: @@ -190,45 +198,17 @@ def set_env(args, modules_list, modules_root_dir, silent=False): salome_subdir, "shared_modules"), "PYTHONPATH") - - # set environment for SMESH plugins - if module == "SMESH" : - 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 - pass - pass - + + # set environment by modules from the list + try: + mod=__import__(module.lower()+"_setenv") + mod.set_env(args) + pass + except: + pass + pass + pass + if sys.platform == 'win32': os.environ["SALOMEPATH"]=";".join(modules_root_dir_list) else: @@ -254,24 +234,6 @@ def set_env(args, modules_list, modules_root_dir, silent=False): = os.path.join(modules_root_dir["KERNEL"],"share", salome_subdir,"resources","kernel") - if "GEOM" in modules_list: - if verbose() and not silent: 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() and not silent: print "GEOM Shape Healing Resources" - os.environ["CSF_ShHealingDefaults"] \ - = os.path.join(modules_root_dir["GEOM"],"share", - salome_subdir,"resources","geom") - # ----------------------------------------------------------------------------- def main(silent=False):