X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FrunSalome.py;h=73a8b0df2037ff8f122adaf16decccb4dac15a82;hb=7e6982e9ccf83f3ede551d990d5a80807dcf1a87;hp=e129a4ff27f8e620b189fd467086df819855f6a5;hpb=9749fc1db72bd80e278405114b05ffc69b5031da;p=modules%2Fkernel.git diff --git a/bin/runSalome.py b/bin/runSalome.py index e129a4ff2..73a8b0df2 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2015 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 @@ -8,7 +8,7 @@ # 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. +# 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 @@ -31,11 +31,9 @@ import orbmodule import setenv from launchConfigureParser import verbose from server import process_id, Server - -if sys.platform == "win32": - SEP = ";" -else: - SEP = ":" +import json +import subprocess +from salomeContextUtils import ScriptAndArgsObjectEncoder # ----------------------------------------------------------------------------- @@ -67,7 +65,7 @@ def givenPortKill(port): try: killMyPort(my_port) except: - print "problem in LocalPortKill(), killMyPort("< 0: - self.SCMD2+=['--pyscript=%s'%(",".join(self.args['pyscript']))] + msg = json.dumps(self.args['pyscript'], cls=ScriptAndArgsObjectEncoder) + self.SCMD2+=['--pyscript=%s'%(msg)] pass pass pass @@ -382,21 +392,6 @@ class LauncherServer(Server): 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/kernel/channel.cfg', - '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior', - '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior', - '-DReportLogFile=/tmp/'+myLogName+'_notifd.report', - '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug', - ] - # # ----------------------------------------------------------------------------- @@ -430,14 +425,12 @@ def startSalome(args, modules_list, modules_root_dir): if args['wake_up_session']: if "OMNIORB_CONFIG" not in os.environ: from salome_utils import generateFileName - home = os.getenv("HOME") - appli = os.getenv("APPLI") + omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs={} - if appli is not None: - home = os.path.join(os.path.realpath(home), appli,"USERS") - kwargs["with_username"] = True - pass - last_running_config = generateFileName(home, prefix="omniORB", + if omniorbUserPath is not None: + kwargs["with_username"]=True + + last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", suffix="last", extension="cfg", hidden=True, @@ -482,18 +475,6 @@ def startSalome(args, modules_list, modules_root_dir): args["session_object"] = session return clt - # Save Naming service port name into - # the file args["ns_port_log_file"] - if args.has_key('ns_port_log_file'): - home = os.environ['HOME'] - appli= os.environ.get("APPLI") - if appli is not None: - home = os.path.join(os.path.realpath(home), appli, "USERS") - file_name = os.path.join(home, args["ns_port_log_file"]) - f = open(file_name, "w") - f.write(os.environ['NSPORT']) - f.close() - # Launch Logger Server (optional) # and wait until it is registered in naming service # @@ -503,14 +484,13 @@ def startSalome(args, modules_list, modules_root_dir): myServer.run() clt.waitLogger("Logger") - # Notify Server launch - # - - if sys.platform != "win32": - if verbose(): print "Notify Server to launch" - - myServer=NotifyServer(args,modules_root_dir) - myServer.run() + # set siman python path before the session server launching to import scripts inside python console + if simanStudyName(args): + # MPV: use os.environ here because session server is launched in separated process and sys.path is missed in this case + from salome_utils import getTmpDir + ppath = os.path.join(getTmpDir, "SimanSalome", args['siman_study'], + args['siman_scenario'], args['siman_user']) + os.environ["PYTHONPATH"] = ppath + os.pathsep + os.environ["PYTHONPATH"] # Launch Session Server (to show splash ASAP) # @@ -602,18 +582,8 @@ def startSalome(args, modules_list, modules_root_dir): else: clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) - # - # Launch local Python Container (FactoryServerPy), - # and wait until it is registered in naming service - # - if 'pyContainer' in args['standalone']: - myServer=ContainerPYServer(args) - myServer.run() - if sys.platform == "win32": - clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy") - else: - clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID) + raise Exception('Python containers no longer supported') # # Wait until Session Server is registered in naming service @@ -670,6 +640,27 @@ def startSalome(args, modules_list, modules_root_dir): except ImportError: pass + # siman session paramenters and checkout processing + if simanStudyName(args): + print '**********************************************' + print "Siman study name= '" + simanStudyName(args) + "'" + import SALOMEDS + obj = clt.Resolve('myStudyManager') + myStudyManager = obj._narrow(SALOMEDS.StudyManager) + aNewStudy = myStudyManager.NewStudy(simanStudyName(args)) + aSimS = myStudyManager.GetSimanStudy() + aSimS._set_StudyId(args['siman_study']) + aSimS._set_ScenarioId(args['siman_scenario']) + aSimS._set_UserId(args['siman_user']) + aSimS.CheckOut(aNewStudy) + # if session server is enabled, activate the created study + if args["gui"]: + print "Activate the SIMAN study in the SALOME GUI" + obj = clt.Resolve('/Kernel/Session') + mySession = obj._narrow(SALOME.Session) + mySession.emitMessage("simanCheckoutDone " + simanStudyName(args)) + print '**********************************************' + return clt # ----------------------------------------------------------------------------- @@ -739,55 +730,37 @@ def useSalome(args, modules_list, modules_root_dir): self.killSalomeWithPort.killMyPort(self.port) return pass - args['shutdown_servers'] = __utils__(args['port']) + def func(s): + del s + import atexit + atexit.register(func, __utils__(args['port'])) pass pass - # run python scripts, passed via --execute option + # run python scripts, passed as command line arguments toimport = [] - if args.has_key('pyscript'): - if args.has_key('gui') and args.has_key('session_gui'): - if not args['gui'] or not args['session_gui']: + 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 - for srcname in toimport : - if srcname == 'killall': - clt.showNS() - killAllPorts() - sys.exit(0) - else: - if os.path.isabs(srcname): - if os.path.exists(srcname): - execScript(srcname) - elif os.path.exists(srcname+".py"): - execScript(srcname+".py") - else: - print "Can't execute file %s" % srcname - pass - else: - found = False - for path in [os.getcwd()] + sys.path: - if os.path.exists(os.path.join(path,srcname)): - execScript(os.path.join(path,srcname)) - found = True - break - elif os.path.exists(os.path.join(path,srcname+".py")): - execScript(os.path.join(path,srcname+".py")) - found = True - break - pass - if not found: - print "Can't execute file %s" % srcname - pass - pass - pass - pass - pass return clt def execScript(script_path): print 'executing', script_path - sys.path.insert(0, os.path.dirname(script_path)) + sys.path.insert(0, os.path.realpath(os.path.dirname(script_path))) execfile(script_path,globals()) del sys.path[0] @@ -798,11 +771,8 @@ 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. """ - if sys.platform == "win32": - fileEnv = os.getenv('TEMP') - else: - fileEnv = '/tmp/' - + from salome_utils import getTmpDir + fileEnv = getTmpDir() fileEnv += os.getenv('USER') + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv=open(fileEnv,'w') @@ -828,9 +798,18 @@ def no_main(): def main(): """Salome launch as a main application""" + + # 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 - print "runSalome running on %s" % getHostName() args, modules_list, modules_root_dir = setenv.get_config() + print "runSalome running on %s" % getHostName() kill_salome(args) save_config = True @@ -912,10 +891,9 @@ def foreGround(clt, args): killMyPort(port) pass return +# -# ----------------------------------------------------------------------------- - -if __name__ == "__main__": +def runSalome(): import user clt,args = main() # -- @@ -941,5 +919,11 @@ if __name__ == "__main__": if test: foreGround(clt, args) pass - # -- pass +# + +# ----------------------------------------------------------------------------- + +if __name__ == "__main__": + runSalome() +#