X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FrunSalome.py;h=722629ad4694265738e3dee09443f937a813f01c;hb=7abfafb698042a8635b7cbf9d2347937f2036ba8;hp=af5d4c114f9fd937b6f52431a65999d6ff04568c;hpb=4770f6c6846b3b83673e0a00986a1fc1763b767b;p=modules%2Fkernel.git diff --git a/bin/runSalome.py b/bin/runSalome.py index af5d4c114..722629ad4 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -1,36 +1,38 @@ #!/usr/bin/env python -import sys, os, string, glob, time, pickle +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# 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 +# 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 +# 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 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# -### read launch configure xml file and command line options -import launchConfigureParser -args = launchConfigureParser.args +import sys, os, string, glob, time, pickle +import orbmodule -### kill servers if it is need +process_id = {} -from killSalome import killAllPorts +# salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources/kernel, etc. +# before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used. +# but after - 'appname' = "SalomeApp", so using it in making the subdirectory is an error. +salome_subdir = "salome" -def killLocalPort(): - from killSalomeWithPort import killMyPort - my_port=str(args['port']) - try: - killMyPort(my_port) - except: - print "problem in killLocalPort()" - pass - pass - -if args['killall']: - killAllPorts() -elif args['portkill']: - killLocalPort() - # ----------------------------------------------------------------------------- -# -# Fonctions helper pour ajouter des variables d'environnement -# def add_path(directory, variable_name): + """Function helper to add environment variables""" if not os.environ.has_key(variable_name): os.environ[variable_name] = "" pass @@ -51,365 +53,730 @@ def add_path(directory, variable_name): if variable_name == "PYTHONPATH": sys.path[:0] = [directory] +# ----------------------------------------------------------------------------- + +def get_config(): + """ + Get list of modules, paths. + + Read args from launch configure xml file and command line options. + Check variables _ROOT_DIR and set list of used modules. + Return args, modules_list, modules_root_dir + """ + + # read args from launch configure xml file and command line options + + import launchConfigureParser + args = launchConfigureParser.args + + # Check variables _ROOT_DIR + # and set list of used modules (without KERNEL) + + modules_list = [] + if args.has_key("modules"): + modules_list += args["modules"] + # KERNEL must be last in the list to locate it at the first place in PATH + if args["gui"] : + modules_list[:0] = ["GUI"] + modules_list[:0] = ["KERNEL"] + modules_list.reverse() + + modules_root_dir = {} + + to_remove_list=[] + 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 "********************************************************" + to_remove_list.append(module) + continue + pass + module_root_dir = os.environ[module_variable] + modules_root_dir[module]=module_root_dir + + for to_remove in to_remove_list: + modules_list.remove(to_remove) + + while "KERNEL" in modules_list: + modules_list.remove("KERNEL") + pass + + while "GUI" in modules_list: + modules_list.remove("GUI") + pass + + if "SUPERV" in modules_list and not 'superv' in args['standalone']: + args['standalone'].append("superv") + pass + + return args, modules_list, modules_root_dir -init_time = os.times() # ----------------------------------------------------------------------------- -# -# Check variables _ROOT_DIR and set list of used modules (without KERNEL) -# Add to the PATH-variables modules' specific paths -# -modules_list = [] -if args.has_key("modules"): - modules_list += args["modules"] -modules_list[:0] = ["KERNEL"] # KERNEL must be last in the list to locate it at the first place in PATH variables -modules_list.reverse() - -modules_root_dir = {} -modules_root_dir_list = [] -python_version="python%d.%d" % sys.version_info[0:2] - -to_remove_list=[] -for module in modules_list : - module_variable=module.upper()+"_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 "*******************************************************************************" - to_remove_list.append(module) - continue + +def set_env(args, modules_list, modules_root_dir): + """Add to the PATH-variables modules specific paths""" + + python_version="python%d.%d" % sys.version_info[0:2] + modules_root_dir_list = [] + if args["gui"] : + modules_list = modules_list[:] + ["GUI"] + modules_list = modules_list[:] + ["KERNEL"] + 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] + add_path(os.path.join(module_root_dir,"lib",salome_subdir), + "LD_LIBRARY_PATH") + add_path(os.path.join(module_root_dir,"bin",salome_subdir), + "PATH") + if os.path.exists(module_root_dir + "/examples") : + add_path(os.path.join(module_root_dir,"examples"), + "PYTHONPATH") + pass + add_path(os.path.join(module_root_dir,"bin",salome_subdir), + "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib", + python_version,"site-packages", + salome_subdir), + "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib",salome_subdir), + "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib", + python_version,"site-packages", + salome_subdir, + "shared_modules"), + "PYTHONPATH") + pass pass - module_root_dir = os.environ[module_variable] - modules_root_dir[module]=module_root_dir - modules_root_dir_list[:0] = [module_root_dir] - add_path(os.path.join(module_root_dir,"lib",args['appname']), "LD_LIBRARY_PATH") - add_path(os.path.join(module_root_dir,"bin",args['appname']), "PATH") - if os.path.exists(module_root_dir + "/examples") : - add_path(os.path.join(module_root_dir,"examples"), "PYTHONPATH") - -for to_remove in to_remove_list: - modules_list.remove(to_remove) - -while "KERNEL" in modules_list: - modules_list.remove("KERNEL") - pass -# KERNEL must be last in the list to locate it at the first place in PYTHONPATH variable -list_modules = modules_list[:] + ["KERNEL"] -for module in list_modules: - module_root_dir = modules_root_dir[module] - add_path(os.path.join(module_root_dir,"bin",args['appname']), "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib",python_version,"site-packages",args['appname']), "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib",args['appname']), "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib",python_version,"site-packages",args['appname'],"shared_modules"), "PYTHONPATH") - -#os.environ["SALOMEPATH"]=":".join(modules_root_dir.values()) -os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) -if "SUPERV" in modules_list and not 'superv' in args['standalone']: - args['standalone'].append("superv") - pass + os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) + + # set trace environment variable + + if not os.environ.has_key("SALOME_trace"): + os.environ["SALOME_trace"]="local" + if args['file']: + os.environ["SALOME_trace"]="file:"+args['file'][0] + 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/"+args["appname"]+"/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/"+args["appname"]+"/resources/"+plugin.lower() + add_path(os.path.join(plugin_root,"lib",python_version, + "site-packages",salome_subdir), + "PYTHONPATH") + add_path(os.path.join(plugin_root,"lib",salome_subdir), + "PYTHONPATH") + add_path(os.path.join(plugin_root,"lib",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" + + # 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["KERNEL"],"share", + salome_subdir,"resources","kernel") + os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["KERNEL"],"share", + salome_subdir,"resources","kernel") + + if "GEOM" in modules_list: + print "GEOM OCAF Resources" + os.environ["CSF_GEOMDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources","geom") + print "GEOM Shape Healing Resources" + os.environ["CSF_ShHealingDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources","geom") + +# ----------------------------------------------------------------------------- + +from killSalome import killAllPorts + +def killLocalPort(): + """ + kill servers from a previous SALOME exection, if needed, + on the CORBA port given in args of runSalome + """ + + from killSalomeWithPort import killMyPort + my_port=str(args['port']) + try: + killMyPort(my_port) + except: + print "problem in killLocalPort()" + pass + pass + +def givenPortKill(port): + """ + kill servers from a previous SALOME exection, if needed, + on the same CORBA port + """ + + from killSalomeWithPort import killMyPort + my_port=port + try: + killMyPort(my_port) + except: + print "problem in LocalPortKill(), killMyPort("< kill this session - killAllPorts() --> kill all sessions + killLocalPort() --> kill this session + (use CORBA port from args of runSalome) + givenPortKill(port) --> kill a specific session with given CORBA port + killAllPorts() --> kill all sessions - runSalome, with --killall option, starts with killing the processes resulting from the previous execution. + runSalome, with --killall option, starts with killing + the processes resulting from the previous execution. """%filedict # @@ -442,3 +812,47 @@ if __name__ == "__main__": print print " --- registered objects tree in Naming Service ---" clt.showNS() + + return clt + +# ----------------------------------------------------------------------------- + +def registerEnv(args, modules_list, modules_root_dir): + """ + Register args, modules_list, modules_root_dir in a file + for further use, when SALOME is launched embedded in an other application. + """ + fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \ + + '_' + args['appname'].upper() + '_env' + fenv=open(fileEnv,'w') + pickle.dump((args, modules_list, modules_root_dir),fenv) + fenv.close() + os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv + +# ----------------------------------------------------------------------------- + +def no_main(): + """Salome Launch, when embedded in other application""" + fileEnv = os.environ["SALOME_LAUNCH_CONFIG"] + fenv=open(fileEnv,'r') + args, modules_list, modules_root_dir = pickle.load(fenv) + fenv.close() + kill_salome(args) + clt = useSalome(args, modules_list, modules_root_dir) + return clt + +# ----------------------------------------------------------------------------- + +def main(): + """Salome launch as a main application""" + args, modules_list, modules_root_dir = get_config() + kill_salome(args) + set_env(args, modules_list, modules_root_dir) + clt = useSalome(args, modules_list, modules_root_dir) + return clt,args + +# ----------------------------------------------------------------------------- + +if __name__ == "__main__": + import user + clt,args = main()