'getPortNumber',
'getTmpDir',
'generateFileName',
+ 'makeTmpDir',
+ 'uniteFiles',
]
# ---
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 )
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:
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:
= 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):