X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FrunSalome.py;h=722629ad4694265738e3dee09443f937a813f01c;hb=7abfafb698042a8635b7cbf9d2347937f2036ba8;hp=c61998d896dd61c79d92a7744cee68277ec1d658;hpb=0657026ba3957eb1f47cdc69f704a68a20232058;p=modules%2Fkernel.git diff --git a/bin/runSalome.py b/bin/runSalome.py index c61998d89..722629ad4 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -1,429 +1,858 @@ #!/usr/bin/env python -usage="""USAGE: runSalome.py [options] - -[command line options] : ---help : affichage de l'aide ---gui : lancement du GUI ---logger : redirection des messages dans un fichier ---xterm : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre ---modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue ---containers=cpp,python,superv: lancement des containers cpp, python et de supervision - - La variable d'environnement _ROOT_DIR doit etre préalablement - positionnée (modulen doit etre en majuscule). - KERNEL_ROOT_DIR est obligatoire. -""" - -def message(code, msg=''): - if msg: print msg - sys.exit(code) - -import sys,os,string,glob,time,signal,pickle,getopt - -init_time=os.times() -opts, args=getopt.getopt(sys.argv[1:], 'hmglxc:', ['help','modules=','gui','logger','xterm','containers=']) -modules_root_dir={} -process_id={} -liste_modules={} -liste_containers={} -with_gui=0 -with_logger=0 -with_xterm=0 - -with_container_cpp=0 -with_container_python=0 -with_container_superv=0 - -try: - for o, a in opts: - if o in ('-h', '--help'): - print usage - sys.exit(1) - elif o in ('-g', '--gui'): - with_gui=1 - elif o in ('-l', '--logger'): - with_logger=1 - elif o in ('-x', '--xterm'): - with_xterm=1 - elif o in ('-m', '--modules'): - liste_modules = [x.upper() for x in a.split(',')] - elif o in ('-c', '--containers'): - liste_containers = [x.lower() for x in a.split(',')] - for r in liste_containers: - if r not in ('cpp', 'python', 'superv'): - message(1, 'Invalid -c/--containers option: %s' % a) - if 'cpp' in liste_containers: - with_container_cpp=1 - else: - with_container_cpp=0 - if 'python' in liste_containers: - with_container_python=1 - else: - with_container_python=0 - if 'superv' in liste_containers: - with_container_superv=1 - else: - with_container_superv=0 - -except getopt.error, msg: - print usage - sys.exit(1) - -# ----------------------------------------------------------------------------- -# -# Vérification des variables d'environnement -# -try: - kernel_root_dir=os.environ["KERNEL_ROOT_DIR"] - modules_root_dir["KERNEL"]=kernel_root_dir -except: - print usage - sys.exit(1) - -for module in liste_modules : - try: - module=module.upper() - module_root_dir=os.environ[module +"_ROOT_DIR"] - modules_root_dir[module]=module_root_dir - except: - print usage - sys.exit(1) - -# il faut KERNEL en premier dans la liste des modules -# - l'ordre des modules dans le catalogue sera identique -# - la liste des modules presents dans le catalogue est exploitée pour charger les modules CORBA python, -# il faut charger les modules python du KERNEL en premier - -if "KERNEL" in liste_modules:liste_modules.remove("KERNEL") -liste_modules[:0]=["KERNEL"] -#print liste_modules -#print modules_root_dir - -if "SUPERV" in liste_modules:with_container_superv=1 - +# 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 +# + +import sys, os, string, glob, time, pickle import orbmodule -# ----------------------------------------------------------------------------- -# -# Définition des classes d'objets pour le lancement des Server CORBA -# - -class Server: - CMD=[] - if with_xterm: - ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-e'] - else: - ARGS=[] - - def run(self): - args = self.ARGS+self.CMD - #print "args = ", args - pid = os.spawnvp(os.P_NOWAIT, args[0], args) - process_id[pid]=self.CMD +process_id = {} -class CatalogServer(Server): - SCMD1=['SALOME_ModuleCatalog_Server','-common'] - SCMD2=['-personal','${HOME}/Salome/resources/CatalogModulePersonnel.xml'] - - def setpath(self,liste_modules): - cata_path=[] - for module in liste_modules: - module_root_dir=modules_root_dir[module] - module_cata=module+"Catalog.xml" - print " ", module_cata - cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata))) - self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 - -class SalomeDSServer(Server): - CMD=['SALOMEDS_Server'] +# 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" -class RegistryServer(Server): - CMD=['SALOME_Registry_Server', '--salome_session','theSession'] - -class ContainerCPPServer(Server): - CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost'] - -class ContainerPYServer(Server): - CMD=['SALOME_ContainerPy.py','FactoryServerPy','-ORBInitRef','NameService=corbaname::localhost'] - -class ContainerSUPERVServer(Server): - CMD=['SALOME_Container','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost'] - -class LoggerServer(Server): - CMD=['SALOME_Logger_Server', 'logger.log'] - -class SessionLoader(Server): - CMD=['SALOME_Session_Loader'] - if with_container_cpp: - CMD=CMD+['CPP'] - if with_container_python: - CMD=CMD+['PY'] - if with_container_superv: - CMD=CMD+['SUPERV'] - if with_gui: - CMD=CMD+['GUI'] - -class SessionServer(Server): - CMD=['SALOME_Session_Server'] +# ----------------------------------------------------------------------------- -class NotifyServer(Server): - CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior'] +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 + if os.path.exists(directory): + newpath=[] + for _dir in os.environ[variable_name].split(":"): + if os.path.exists(_dir): + if not os.path.samefile(_dir, directory): + newpath.append(_dir) + else: + if os.path.abspath(_dir) != os.path.abspath(directory): + newpath.append(_dir) + pass + import string + newpath[:0] = [ directory ] + newpath = string.join(newpath,":") + os.environ[variable_name] = newpath + if variable_name == "PYTHONPATH": + sys.path[:0] = [directory] # ----------------------------------------------------------------------------- -# -# Fonction d'arrêt de salome -# -def killSalome(): - print "arret des serveurs SALOME" - for pid, cmd in process_id.items(): - print "arret du process %s : %s"% (pid, cmd[0]) - os.kill(pid,signal.SIGKILL) - print "arret du naming service" - os.system("killall -9 omniNames") +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 -# ----------------------------------------------------------------------------- -# -# Fonction de test -# - -def test(clt): - # create an LifeCycleCORBA instance - import LifeCycleCORBA - lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb) - med = lcc.FindOrLoadComponent("FactoryServer", "MED") - #pycalc = lcc.FindOrLoadComponent("FactoryServerPy", "CalculatorPy") + return args, modules_list, modules_root_dir # ----------------------------------------------------------------------------- -# -# Fonctions helper pour ajouter des variables d'environnement -# - -def add_path(directory): - os.environ["PATH"]=directory + ":" + os.environ["PATH"] -def add_ld_library_path(directory): - os.environ["LD_LIBRARY_PATH"]=directory + ":" + os.environ["LD_LIBRARY_PATH"] - -def add_python_path(directory): - os.environ["PYTHONPATH"]=directory + ":" + os.environ["PYTHONPATH"] - sys.path[:0]=[directory] +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 + + + 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") # ----------------------------------------------------------------------------- -# -# initialisation des variables d'environnement -# - -python_version="python%d.%d" % sys.version_info[0:2] - -# -# Ajout du chemin d'acces aux executables de KERNEL dans le PATH -# - -add_path(os.path.join(kernel_root_dir,"bin","salome")) -#print "PATH=",os.environ["PATH"] - -# -# Ajout des modules dans le LD_LIBRARY_PATH -# -for module in liste_modules: - module_root_dir=modules_root_dir[module] - add_ld_library_path(os.path.join(module_root_dir,"lib","salome")) -#print "LD_LIBRARY_PATH=",os.environ["LD_LIBRARY_PATH"] - -# -# Ajout des modules dans le PYTHONPATH (KERNEL prioritaire, donc en dernier) -# - -liste_modules_reverse=liste_modules[:] -liste_modules_reverse.reverse() -#print liste_modules -#print liste_modules_reverse -for module in liste_modules_reverse: - module_root_dir=modules_root_dir[module] - add_python_path(os.path.join(module_root_dir,"bin","salome")) - add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome")) - add_python_path(os.path.join(module_root_dir,"lib","salome")) -#print "PYTHONPATH=",sys.path - -# +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 + (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. + """%filedict + + # + # Impression arborescence Naming Service + # + + if clt != None: + print + print " --- registered objects tree in Naming Service ---" + clt.showNS() + + return clt -#print process_id +# ----------------------------------------------------------------------------- +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 -filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict' -#filedict='/tmp/'+os.getlogin()+'_SALOME_pidict' +# ----------------------------------------------------------------------------- -fpid=open(filedict, 'w') -pickle.dump(process_id,fpid) -fpid.close() +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 -print -print "Sauvegarde du dictionnaire des process dans ", filedict -print "Pour tuer les process SALOME, executer : python killSalome.py depuis" -print "une console, ou bien killSalome() depuis le present interpreteur," -print "s'il n'est pas fermé." -print "runSalome commence par tuer les process restants d'une execution précédente." +# ----------------------------------------------------------------------------- -# -# Impression arborescence Naming Service -# +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 clt != None: - print - print " --- registered objects tree in Naming Service ---" - clt.showNS() +# ----------------------------------------------------------------------------- +if __name__ == "__main__": + import user + clt,args = main()