Back to index

salome-kernel  6.5.0
Functions | Variables
setenv Namespace Reference

Functions

def add_path
def get_lib_dir
def get_config
def set_env
def main

Variables

string salome_subdir = "salome"
 __lib__dir__ = None
tuple args = main()

Function Documentation

def setenv.add_path (   directory,
  variable_name 
)
Function helper to add environment variables

Definition at line 40 of file setenv.py.

00040 
00041 def add_path(directory, variable_name):
00042     """Function helper to add environment variables"""
00043     if sys.platform == "win32":
00044       splitsym = ";"
00045     else:
00046       splitsym = ":"
00047     if not os.environ.has_key(variable_name):
00048         os.environ[variable_name] = ""
00049         pass
00050     if os.path.exists(directory):
00051         newpath=[]
00052         for _dir in os.environ[variable_name].split(splitsym):
00053             if os.path.exists(_dir):
00054                 if sys.platform != "win32":
00055                     if not os.path.samefile(_dir, directory):
00056                         newpath.append(_dir)
00057                 else:
00058                     newpath.append(_dir)
00059             else:
00060                 if os.path.abspath(_dir) != os.path.abspath(directory):
00061                   newpath.append(_dir)
00062             pass
00063         import string
00064         newpath[:0] = [ directory ]
00065         newpath = string.join(newpath, splitsym)
00066         os.environ[variable_name] = newpath
00067         if variable_name == "PYTHONPATH":
00068             sys.path[:0] = [directory]
00069 
00070 # -----------------------------------------------------------------------------

Here is the caller graph for this function:

def setenv.get_config (   silent = False)
Get list of modules, paths.

Read args from launch configure xml file and command line options.
Check variables <module>_ROOT_DIR and set list of used modules.
Return args, modules_list, modules_root_dir    

Definition at line 81 of file setenv.py.

00081 
00082 def get_config(silent=False):
00083     """
00084     Get list of modules, paths.
00085     
00086     Read args from launch configure xml file and command line options.
00087     Check variables <module>_ROOT_DIR and set list of used modules.
00088     Return args, modules_list, modules_root_dir    
00089     """
00090     
00091     # read args from launch configure xml file and command line options
00092 
00093     #*** Test additional option
00094     #*** import optparse
00095     #*** help_str = "Test options addition."
00096     #*** o_j = optparse.Option("-j", "--join", action="store_true", dest="join", help=help_str)
00097 
00098     import launchConfigureParser
00099     args = launchConfigureParser.get_env()
00100 
00101     #*** Test additional option
00102     #*** args = launchConfigureParser.get_env([o_j])
00103     #*** if args.has_key("join"): print args["join"]
00104 
00105     # Check variables <module>_ROOT_DIR
00106     # and set list of used modules (without KERNEL)
00107 
00108     modules_list = []
00109     if args.has_key("modules"):
00110         modules_list += args["modules"]
00111     # KERNEL must be last in the list to locate it at the first place in PATH
00112     if args["gui"] :
00113         modules_list[:0] = ["GUI"]
00114     modules_list[:0] = ["KERNEL"]
00115     modules_list.reverse()
00116 
00117     modules_root_dir = {}
00118 
00119     to_remove_list=[]
00120     for module in modules_list :
00121         module_variable=module+"_ROOT_DIR"
00122         if not os.environ.has_key(module_variable):
00123             if not silent:
00124                 print "*******************************************************"
00125                 print "*"
00126                 print "* Environment variable",module_variable,"must be set"
00127                 print "* Module", module, "will be not available"
00128                 print "*"
00129                 print "********************************************************"
00130                 pass
00131             to_remove_list.append(module)
00132             continue
00133             pass
00134         module_root_dir = os.environ[module_variable]
00135         modules_root_dir[module]=module_root_dir
00136 
00137     for to_remove in to_remove_list:
00138         modules_list.remove(to_remove)
00139 
00140     while "KERNEL" in modules_list:
00141         modules_list.remove("KERNEL")
00142         pass
00143 
00144     while "GUI" in modules_list:
00145         modules_list.remove("GUI")
00146         pass
00147 
00148     return args, modules_list, modules_root_dir
00149 
00150 # -----------------------------------------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 72 of file setenv.py.

00072 
00073 def get_lib_dir():
00074     global __lib__dir__
00075     if __lib__dir__: return __lib__dir__
00076     import platform
00077     __lib__dir__ = "lib"
00078     return __lib__dir__
00079 
00080 # -----------------------------------------------------------------------------

Here is the caller graph for this function:

def setenv.main (   silent = False)

Definition at line 244 of file setenv.py.

00244 
00245 def main(silent=False):
00246     args, modules_list, modules_root_dir = get_config(silent=silent)
00247     set_env(args, modules_list, modules_root_dir, silent=silent)
00248     return args
00249 
00250 # -----------------------------------------------------------------------------

Here is the call graph for this function:

def setenv.set_env (   args,
  modules_list,
  modules_root_dir,
  silent = False 
)
Add to the PATH-variables modules specific paths

Definition at line 151 of file setenv.py.

00151 
00152 def set_env(args, modules_list, modules_root_dir, silent=False):
00153     """Add to the PATH-variables modules specific paths"""
00154     
00155     import os
00156     from salome_utils import getTmpDir, generateFileName, makeTmpDir, getPortNumber
00157 
00158     # create temporary directory for environment files needed by modules from the list
00159     port = getPortNumber(False)
00160     if port:
00161         tmp_dir = getTmpDir()
00162         env_dir = generateFileName(tmp_dir, prefix="env", with_port=True)
00163         makeTmpDir(env_dir)
00164         pass
00165 
00166     python_version="python%d.%d" % sys.version_info[0:2]
00167     modules_root_dir_list = []
00168     if os.getenv('SALOME_BATCH') == None:
00169       os.putenv('SALOME_BATCH','0')
00170     if args["gui"] :
00171         modules_list = modules_list[:] + ["GUI"] 
00172     modules_list = modules_list[:] + ["KERNEL"] 
00173     for module in modules_list :
00174         if modules_root_dir.has_key(module):
00175             module_root_dir = modules_root_dir[module]
00176             modules_root_dir_list[:0] = [module_root_dir]
00177             if sys.platform == "win32":
00178               add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
00179                      "PATH")
00180             else:
00181               add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
00182                      "LD_LIBRARY_PATH")
00183             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
00184                      "PATH")
00185             if os.path.exists(module_root_dir + "/examples") :
00186                 add_path(os.path.join(module_root_dir,"examples"),
00187                          "PYTHONPATH")
00188                 pass
00189             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
00190                      "PYTHONPATH")
00191             # add lib before site-packages to load script instead of dll if any (win32 platform)
00192             add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir),
00193                      "PYTHONPATH")
00194             add_path(os.path.join(module_root_dir,get_lib_dir(),
00195                                   python_version,"site-packages",
00196                                   salome_subdir),
00197                      "PYTHONPATH")
00198             import platform
00199             if platform.machine() == "x86_64":
00200                 add_path(os.path.join(module_root_dir,"lib64",
00201                                       python_version,"site-packages",
00202                                       salome_subdir),
00203                          "PYTHONPATH")
00204                 pass
00205             add_path(os.path.join(module_root_dir,get_lib_dir(),
00206                                   python_version,"site-packages",
00207                                   salome_subdir,
00208                                   "shared_modules"),
00209                      "PYTHONPATH")
00210 
00211             # set environment by modules from the list
00212             if port:
00213                 try:
00214                     mod=__import__(module.lower()+"_setenv")
00215                     mod.set_env(args)
00216                     pass
00217                 except:
00218                     pass
00219                 pass
00220             pass
00221         pass
00222 
00223     if sys.platform == 'win32':
00224         os.environ["SALOMEPATH"]=";".join(modules_root_dir_list)
00225     else:
00226         os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
00227     
00228     # set trace environment variable
00229     
00230     if not os.environ.has_key("SALOME_trace"):
00231         os.environ["SALOME_trace"]="local"
00232     if args['file']:
00233         os.environ["SALOME_trace"]="file:"+args['file'][0]
00234     if args['logger']:
00235         os.environ["SALOME_trace"]="with_logger"
00236 
00237     # set resources variables if not yet set
00238 
00239     os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
00240     = os.path.join(modules_root_dir["KERNEL"],"share",
00241                    salome_subdir,"resources","kernel")
00242 
00243 # -----------------------------------------------------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 71 of file setenv.py.

tuple setenv.args = main()

Definition at line 253 of file setenv.py.

string setenv.salome_subdir = "salome"

Definition at line 35 of file setenv.py.