X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FrunSalome.py;h=b547c3703b69e025e538fa587125469f1964888b;hb=8384533bbf22649c38f839935489a6bab2e1a1c8;hp=8b19f288ecb08f1942fcad2d7924d4c7470423b7;hpb=836c34a4e2dd99f1f302a2c3ae93a51cd182368f;p=modules%2Fkernel.git diff --git a/bin/runSalome.py b/bin/runSalome.py index 8b19f288e..b547c3703 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -1,218 +1,39 @@ #!/usr/bin/env python +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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, or (at your option) any later version. +# +# 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 - -process_id = {} - -# salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, 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 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] - -# ----------------------------------------------------------------------------- - -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 - -# ----------------------------------------------------------------------------- - -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" - 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" - 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 +## @package runSalome +# \brief Module that provides services to launch SALOME +# - # 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("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome" - #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/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["KERNEL"],"share", - salome_subdir,"resources") - os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ - = os.path.join(modules_root_dir["KERNEL"],"share", - salome_subdir,"resources") - - 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") - print "GEOM Shape Healing Resources" - os.environ["CSF_ShHealingDefaults"] \ - = os.path.join(modules_root_dir["GEOM"],"share", - salome_subdir,"resources") +import sys, os, string, glob, time, pickle, re +import orbmodule +import setenv +from launchConfigureParser import verbose +from server import process_id, Server +import json +import subprocess +from salomeContextUtils import ScriptAndArgsObjectEncoder # ----------------------------------------------------------------------------- @@ -223,7 +44,7 @@ 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: @@ -232,19 +53,19 @@ def killLocalPort(): 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("< 0: + msg = json.dumps(self.args['pyscript'], cls=ScriptAndArgsObjectEncoder) + self.SCMD2+=['--pyscript=%s'%(msg)] + pass + pass + pass if self.args['noexcepthandler']: self.SCMD2+=['noexcepthandler'] + if self.args.has_key('user_config'): + self.SCMD2+=['--resources=%s'%self.args['user_config']] if self.args.has_key('modules'): - self.SCMD2+=['--modules ('] - for mod in self.args['modules']: - self.SCMD2+=[mod + ':'] - self.SCMD2+=[')'] + list_modules = [] + #keep only modules with GUI + for m in modules_list: + if m not in modules_root_dir: + list_modules.insert(0,m) + else: + fr1 = os.path.join(modules_root_dir[m],"share","salome","resources",m.lower(),"SalomeApp.xml") + fr2 = os.path.join(modules_root_dir[m],"share","salome","resources","SalomeApp.xml") + if os.path.exists(fr1) or os.path.exists(fr2): + list_modules.insert(0,m) + list_modules.reverse() + self.SCMD2+=['--modules (%s)' % ":".join(list_modules)] + pass + pass def setpath(self,modules_list,modules_root_dir): - cata_path=[] list_modules = modules_list[:] list_modules.reverse() if self.args["gui"] : list_modules = ["KERNEL", "GUI"] + list_modules else : list_modules = ["KERNEL"] + list_modules - for module in list_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_subdir,"resources", - module_cata))) + + cata_path=get_cata_path(list_modules,modules_root_dir) + if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']): - self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 + #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform + self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2 else: self.CMD=self.SCMD1 + self.SCMD2 - + if self.args.has_key('test'): + self.CMD+=['-test'] + self.args['test'] + elif self.args.has_key('play'): + self.CMD+=['-play'] + self.args['play'] + + if self.args["gdb_session"] or self.args["ddd_session"]: + f = open(".gdbinit4salome", "w") + f.write("set args ") + args = " ".join(self.CMD[1:]) + args = args.replace("(", "\(") + args = args.replace(")", "\)") + f.write(args) + f.write("\n") + f.close() + if self.args["ddd_session"]: + self.CMD = ["ddd", "--command=.gdbinit4salome", self.CMD[0]] + elif self.args["gdb_session"]: + self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]] + pass + pass + + if self.args["valgrind_session"]: + l = ["valgrind"] + val = os.getenv("VALGRIND_OPTIONS") + if val: + l += val.split() + pass + self.CMD = l + self.CMD + pass + # --- -class ContainerManagerServer(Server): +class LauncherServer(Server): def __init__(self,args): self.args=args self.initArgs() - self.SCMD1=['SALOME_ContainerManagerServer'] + self.SCMD1=['SALOME_LauncherServer'] self.SCMD2=[] if args["gui"] : if 'registry' in self.args['embedded']: @@ -477,75 +347,107 @@ class ContainerManagerServer(Server): self.SCMD2+=['--with','SALOMEDS','(',')'] if 'cppContainer' in self.args['embedded']: self.SCMD2+=['--with','Container','(','FactoryServer',')'] - + def setpath(self,modules_list,modules_root_dir): - cata_path=[] list_modules = modules_list[:] list_modules.reverse() if self.args["gui"] : - list_modules = ["GUI"] + list_modules - for module in ["KERNEL"] + list_modules: - if modules_root_dir.has_key(module): - 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", - self.args['appname'],"resources", - module_cata))) - pass - pass + list_modules = ["KERNEL", "GUI"] + list_modules + else : + list_modules = ["KERNEL"] + list_modules + + cata_path=get_cata_path(list_modules,modules_root_dir) + if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']): - self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 + #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform + self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2 else: self.CMD=self.SCMD1 + self.SCMD2 - -class NotifyServer(Server): - def __init__(self,args,modules_root_dir): - self.args=args - self.initArgs() - self.modules_root_dir=modules_root_dir - myLogName = os.environ["LOGNAME"] - self.CMD=['notifd','-c', - self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg', - '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior', - '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior', - '-DReportLogFile=/tmp/'+myLogName+'_notifd.report', - '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug', - ] - # # ----------------------------------------------------------------------------- -def startGUI(): +def startGUI(clt): """Salome Session Graphic User Interface activation""" import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog - reload(Engines) - reload(SALOME) - reload(SALOMEDS) import SALOME_Session_idl session=clt.waitNS("/Kernel/Session",SALOME.Session) session.GetInterface() - + # ----------------------------------------------------------------------------- def startSalome(args, modules_list, modules_root_dir): """Launch all SALOME servers requested by args""" init_time = os.times() - print "startSalome ", args - + if verbose(): print "startSalome ", args + + # + # Set server launch command + # + if args.has_key('server_launch_mode'): + Server.set_server_launch_mode(args['server_launch_mode']) + + # + # Wake up session option + # + if args['wake_up_session']: + if "OMNIORB_CONFIG" not in os.environ: + from salome_utils import generateFileName + omniorbUserPath = os.getenv("OMNIORB_USER_PATH") + kwargs={} + if omniorbUserPath is not None: + kwargs["with_username"]=True + + last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", + suffix="last", + extension="cfg", + hidden=True, + **kwargs) + os.environ['OMNIORB_CONFIG'] = last_running_config + pass + pass + # - # Initialisation ORB et Naming Service + # Initialisation ORB and Naming Service # - - clt=orbmodule.client() - # (non obligatoire) Lancement Logger Server - # et attente de sa disponibilite dans le naming service + clt=orbmodule.client(args) + + # + # Wake up session option + # + if args['wake_up_session']: + import Engines + import SALOME + import SALOMEDS + import SALOME_ModuleCatalog + import SALOME_Session_idl + session = clt.waitNS("/Kernel/Session",SALOME.Session) + status = session.GetStatSession() + if status.activeGUI: + from salome_utils import getPortNumber + port = getPortNumber() + msg = "Warning :" + msg += "\n" + msg += "Session GUI for port number %s is already active."%(port) + msg += "\n" + msg += "If you which to wake up another session," + msg += "\n" + msg += "please use variable OMNIORB_CONFIG" + msg += "\n" + msg += "to get the correct session object in naming service." + sys.stdout.write(msg+"\n") + sys.stdout.flush() + return clt + session.GetInterface() + args["session_object"] = session + return clt + + # Launch Logger Server (optional) + # and wait until it is registered in naming service # if args['logger']: @@ -553,40 +455,45 @@ def startSalome(args, modules_list, modules_root_dir): myServer.run() clt.waitLogger("Logger") - # Notify Server launch + # Launch Session Server (to show splash ASAP) # - print "Notify Server to launch" - - myServer=NotifyServer(args,modules_root_dir) - myServer.run() + if args["gui"]: + mySessionServ = SessionServer(args,args['modules'],modules_root_dir) + mySessionServ.setpath(modules_list,modules_root_dir) + mySessionServ.run() # - # Lancement Registry Server, - # attente de la disponibilite du Registry dans le Naming Service + # Launch Registry Server, + # and wait until it is registered in naming service # if ('registry' not in args['embedded']) | (args["gui"] == 0) : myServer=RegistryServer(args) myServer.run() - clt.waitNSPID("/Registry",myServer.PID) + if sys.platform == "win32": + clt.waitNS("/Registry") + else: + clt.waitNSPID("/Registry",myServer.PID) # - # Lancement Catalog Server, - # attente de la disponibilite du Catalog Server dans le Naming Service + # Launch Catalog Server, + # and wait until it is registered in naming service # - if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0): cataServer=CatalogServer(args) cataServer.setpath(modules_list,modules_root_dir) cataServer.run() import SALOME_ModuleCatalog - clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog) + if sys.platform == "win32": + clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog) + else: + clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog) # - # Lancement SalomeDS Server, - # attente de la disponibilite du SalomeDS dans le Naming Service + # Launch SalomeDS Server, + # and wait until it is registered in naming service # #print "ARGS = ",args @@ -594,19 +501,29 @@ def startSalome(args, modules_list, modules_root_dir): print "RunStudy" myServer=SalomeDSServer(args) myServer.run() - clt.waitNSPID("/myStudyManager",myServer.PID) + if sys.platform == "win32": + clt.waitNS("/Study") + else: + clt.waitNSPID("/Study",myServer.PID) # - # Lancement ContainerManagerServer + # Launch LauncherServer # - - myCmServer = ContainerManagerServer(args) + + myCmServer = LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() + # + # Launch ConnectionManagerServer + # + + myConnectionServer = ConnectionManagerServer(args) + myConnectionServer.run() + from Utils_Identity import getShortHostName - + if os.getenv("HOSTNAME") == None: if os.getenv("HOST") == None: os.environ["HOSTNAME"]=getShortHostName() @@ -614,64 +531,41 @@ def startSalome(args, modules_list, modules_root_dir): os.environ["HOSTNAME"]=os.getenv("HOST") theComputer = getShortHostName() - + # - # Lancement Container C++ local, - # attente de la disponibilite du Container C++ local dans le Naming Service + # Launch local C++ Container (FactoryServer), + # and wait until it is registered in naming service # - if 'cppContainer' in args['standalone']: + if ('cppContainer' in args['standalone']) | (args["gui"] == 0) : myServer=ContainerCPPServer(args) myServer.run() - clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) - - # - # Lancement Container Python local, - # attente de la disponibilite du Container Python local - # dans le Naming Service - # + if sys.platform == "win32": + clt.waitNS("/Containers/" + theComputer + "/FactoryServer") + else: + clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) if 'pyContainer' in args['standalone']: - myServer=ContainerPYServer(args) - myServer.run() - clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID) + raise Exception('Python containers no longer supported') # - # Lancement Container Supervision local, - # attente de la disponibilite du Container Supervision local - # dans le Naming Service - # - - if 'supervContainer' in args['standalone']: - myServer=ContainerSUPERVServer(args) - myServer.run() - clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID) - - # - # Lancement Session Server + # Wait until Session Server is registered in naming service # if args["gui"]: - mySessionServ = SessionServer(args) - mySessionServ.setpath(modules_list,modules_root_dir) - mySessionServ.run() -##---------------- - - # Attente de la disponibilite du Session Server dans le Naming Service - # - +##---------------- import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog - reload(Engines) - reload(SALOME) - reload(SALOMEDS) import SALOME_Session_idl - session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session) - + if sys.platform == "win32": + session=clt.waitNS("/Kernel/Session",SALOME.Session) + else: + session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session) + args["session_object"] = session end_time = os.times() - print + if verbose(): print print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4] - init_time[4]) @@ -683,25 +577,32 @@ def startSalome(args, modules_list, modules_root_dir): # additionnal external python interpreters # nbaddi=0 - + try: if 'interp' in args: - if args['interp']: - nbaddi = int(args['interp'][0]) + nbaddi = args['interp'] except: import traceback traceback.print_exc() print "-------------------------------------------------------------" print "-- to get an external python interpreter:runSalome --interp=1" print "-------------------------------------------------------------" - - print "additional external python interpreters: ", nbaddi + + if verbose(): print "additional external python interpreters: ", nbaddi if nbaddi: for i in range(nbaddi): print "i=",i anInterp=InterpServer(args) anInterp.run() - + + # set PYTHONINSPECT variable (python interpreter in interactive mode) + if args['pinter']: + os.environ["PYTHONINSPECT"]="1" + try: + import readline + except ImportError: + pass + return clt # ----------------------------------------------------------------------------- @@ -712,7 +613,8 @@ def useSalome(args, modules_list, modules_root_dir): save list of process, give info to user, show registered objects in Naming Service. """ - + global process_id + clt=None try: clt = startSalome(args, modules_list, modules_root_dir) @@ -721,51 +623,89 @@ def useSalome(args, modules_list, modules_root_dir): traceback.print_exc() print print - print "--- erreur au lancement Salome ---" - + print "--- Error during Salome launch ---" + #print process_id + from addToKillList import addToKillList from killSalomeWithPort import getPiDict - filedict = getPiDict(args['port']) - process_ids = [] - try: - fpid=open(filedict, 'r') - process_ids=pickle.load(fpid) - fpid.close() - except: + filedict = getPiDict(args['port']) + for pid, cmd in process_id.items(): + addToKillList(pid, cmd, args['port']) pass - - fpid=open(filedict, 'w') - process_ids.append(process_id) - pickle.dump(process_ids,fpid) - fpid.close() - - print """ + + if verbose(): print """ Saving of the dictionary of Salome processes in %s To kill SALOME processes from a console (kill all sessions from all ports): - python killSalome.py + python killSalome.py To kill SALOME from the present interpreter, if it is not closed : killLocalPort() --> kill this session (use CORBA port from args of runSalome) - givenPortKill(port) --> kill a specific session with given CORBA port + 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 + # Print Naming Service directory list # - + if clt != None: - print - print " --- registered objects tree in Naming Service ---" - clt.showNS() + if verbose(): + print + print " --- registered objects tree in Naming Service ---" + clt.showNS() + pass + + if not args['gui'] or not args['session_gui']: + if args['shutdown_servers']: + class __utils__(object): + def __init__(self, port): + self.port = port + import killSalomeWithPort + self.killSalomeWithPort = killSalomeWithPort + return + def __del__(self): + self.killSalomeWithPort.killMyPort(self.port) + return + pass + def func(s): + del s + import atexit + atexit.register(func, __utils__(args['port'])) + pass + pass + + # run python scripts, passed as command line arguments + toimport = [] + if args.has_key('gui') and args.has_key('session_gui'): + if not args['gui'] or not args['session_gui']: + if args.has_key('study_hdf'): + toopen = args['study_hdf'] + if toopen: + import salome + salome.salome_init(toopen) + if args.has_key('pyscript'): + toimport = args['pyscript'] + from salomeContextUtils import formatScriptsAndArgs + command = formatScriptsAndArgs(toimport) + if command: + proc = subprocess.Popen(command, shell=True) + addToKillList(proc.pid, command, args['port']) + res = proc.wait() + if res: sys.exit(1) # if there's an error when executing script, we should explicitly exit return clt +def execScript(script_path): + print 'executing', script_path + sys.path.insert(0, os.path.realpath(os.path.dirname(script_path))) + execfile(script_path,globals()) + del sys.path[0] + # ----------------------------------------------------------------------------- def registerEnv(args, modules_list, modules_root_dir): @@ -773,7 +713,10 @@ 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']) \ + from salome_utils import getTmpDir + fileEnv = getTmpDir() + from salome_utils import getUserName + fileEnv += getUserName() + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv=open(fileEnv,'w') pickle.dump((args, modules_list, modules_root_dir),fenv) @@ -789,21 +732,141 @@ def no_main(): args, modules_list, modules_root_dir = pickle.load(fenv) fenv.close() kill_salome(args) + from searchFreePort import searchFreePort + searchFreePort(args, 0) clt = useSalome(args, modules_list, modules_root_dir) return clt # ----------------------------------------------------------------------------- -def main(): +def main(exeName=None): """Salome launch as a main application""" - args, modules_list, modules_root_dir = get_config() + + # define folder to store omniorb config (initially in virtual application folder) + try: + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + except Exception, e: + print e + sys.exit(1) + + from salome_utils import getHostName + args, modules_list, modules_root_dir = setenv.get_config(exeName=exeName) + print "runSalome running on %s" % getHostName() + kill_salome(args) - set_env(args, modules_list, modules_root_dir) + save_config = True + if args.has_key('save_config'): + save_config = args['save_config'] + # -- + test = True + if args['wake_up_session']: + test = False + pass + if test: + from searchFreePort import searchFreePort + searchFreePort(args, save_config, args.get('useport')) + pass + # -- + #setenv.main() + setenv.set_env(args, modules_list, modules_root_dir) clt = useSalome(args, modules_list, modules_root_dir) return clt,args # ----------------------------------------------------------------------------- +def foreGround(clt, args): + # -- + if "session_object" not in args: + return + session = args["session_object"] + # -- + # Wait until gui is arrived + # tmax = nbtot * dt + # -- + gui_detected = False + dt = 0.1 + nbtot = 100 + nb = 0 + while 1: + try: + status = session.GetStatSession() + gui_detected = status.activeGUI + except: + pass + if gui_detected: + break + from time import sleep + sleep(dt) + nb += 1 + if nb == nbtot: + break + pass + # -- + if not gui_detected: + return + # -- + from salome_utils import getPortNumber + port = getPortNumber() + # -- + server = Server({}) + if sys.platform == "win32": + server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(os.getpid()), "%s"%(port)] + else: + server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(os.getpid()), "%s"%(port)] + server.run() + # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port)) + # -- + dt = 1.0 + try: + while 1: + try: + status = session.GetStatSession() + assert status.activeGUI + except: + break + from time import sleep + sleep(dt) + pass + pass + except KeyboardInterrupt: + from killSalomeWithPort import killMyPort + killMyPort(port) + pass + return +# + +def runSalome(): + import user + clt,args = main() + # -- + test = args['gui'] and args['session_gui'] + test = test or args['wake_up_session'] + # -- + # The next test covers the --pinter option or var PYTHONINSPECT setted + # -- + test = test and not os.environ.get('PYTHONINSPECT') + # -- + # The next test covers the python -i $KERNEL_ROOT_DIR/bin/salome/runSalome.py case + # -- + try: + from ctypes import POINTER, c_int, cast, pythonapi + iflag_ptr = cast(pythonapi.Py_InteractiveFlag, POINTER(c_int)) + test = test and not iflag_ptr.contents.value + except: + pass + # -- + test = test and os.getenv("SALOME_TEST_MODE", "0") != "1" + test = test and args['foreground'] + # -- + if test: + foreGround(clt, args) + pass + pass +# + +# ----------------------------------------------------------------------------- + if __name__ == "__main__": - import user - clt,args = main() + runSalome() +#