2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 # \brief Module that provides services to launch SALOME
29 import sys, os, string, glob, time, pickle, re
32 from launchConfigureParser import verbose
33 from server import process_id, Server
35 if sys.platform == "win32":
40 # -----------------------------------------------------------------------------
42 from killSalome import killAllPorts
46 kill servers from a previous SALOME exection, if needed,
47 on the CORBA port given in args of runSalome
50 from killSalomeWithPort import killMyPort
51 my_port=str(args['port'])
55 print "problem in killLocalPort()"
59 def givenPortKill(port):
61 kill servers from a previous SALOME exection, if needed,
62 on the same CORBA port
65 from killSalomeWithPort import killMyPort
70 print "problem in LocalPortKill(), killMyPort("<<port<<")"
74 def kill_salome(args):
76 Kill servers from previous SALOME executions, if needed;
77 depending on args 'killall' or 'portkill', kill all executions,
78 or only execution on the same CORBA port
83 elif args['portkill']:
84 givenPortKill(str(args['port']))
86 # -----------------------------------------------------------------------------
88 # Class definitions to launch CORBA Servers
91 class InterpServer(Server):
92 def __init__(self,args):
94 if sys.platform != "win32":
95 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
96 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
98 self.CMD=['cmd', '/c', 'start cmd.exe', '/K', 'python']
103 print "INTERPSERVER::command = ", command
104 if sys.platform == "win32":
106 pid = win32pm.spawnpid( string.join(command, " "),'-nc' )
108 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
109 process_id[pid]=self.CMD
114 def get_cata_path(list_modules,modules_root_dir):
115 """Build a list of catalog paths (cata_path) to initialize the ModuleCatalog server
120 for module in list_modules:
121 if modules_root_dir.has_key(module):
122 module_root_dir=modules_root_dir[module]
123 module_cata=module+"Catalog.xml"
124 cata_file=os.path.join(module_root_dir, "share",setenv.salome_subdir, "resources",module.lower(), module_cata)
126 if os.path.exists(cata_file):
127 cata_path.append(cata_file)
128 modules_cata[module]=cata_file
130 cata_file=os.path.join(module_root_dir, "share",setenv.salome_subdir, "resources", module_cata)
131 if os.path.exists(cata_file):
132 cata_path.append(cata_file)
133 modules_cata[module]=cata_file
135 for path in os.getenv("SALOME_CATALOGS_PATH","").split(SEP):
136 if os.path.exists(path):
137 for cata_file in glob.glob(os.path.join(path,"*Catalog.xml")):
138 module_name= os.path.basename(cata_file)[:-11]
139 if not modules_cata.has_key(module_name):
140 cata_path.append(cata_file)
141 modules_cata[module_name]=cata_file
147 class CatalogServer(Server):
148 def __init__(self,args):
151 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
153 home_dir=os.getenv('HOME')
154 if home_dir is not None:
155 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
157 def setpath(self,modules_list,modules_root_dir):
158 list_modules = modules_list[:]
159 list_modules.reverse()
160 if self.args["gui"] :
161 list_modules = ["KERNEL", "GUI"] + list_modules
163 list_modules = ["KERNEL"] + list_modules
165 cata_path=get_cata_path(list_modules,modules_root_dir)
167 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
171 class SalomeDSServer(Server):
172 def __init__(self,args):
175 self.CMD=['SALOMEDS_Server']
179 class ConnectionManagerServer(Server):
180 def __init__(self,args):
183 self.CMD=['SALOME_ConnectionManagerServer']
187 class RegistryServer(Server):
188 def __init__(self,args):
191 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
195 class ContainerCPPServer(Server):
196 def __init__(self,args):
199 self.CMD=['SALOME_Container','FactoryServer']
203 class ContainerPYServer(Server):
204 def __init__(self,args):
207 if sys.platform == "win32":
208 self.CMD=[os.environ["PYTHONBIN"], '\"'+os.environ["KERNEL_ROOT_DIR"] + '/bin/salome/SALOME_ContainerPy.py'+'\"','FactoryServerPy']
210 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
214 class LoggerServer(Server):
215 def __init__(self,args):
218 from salome_utils import generateFileName
219 if sys.platform == "win32": dirpath = os.environ["HOME"]
220 else: dirpath = "/tmp"
221 logfile = generateFileName( dirpath,
227 print "==========================================================="
228 print "Logger server: put log to the file:"
230 print "==========================================================="
231 self.CMD=['SALOME_Logger_Server', logfile]
233 pass # end of LoggerServer class
237 class SessionServer(Server):
238 def __init__(self,args,modules_list,modules_root_dir):
239 self.args = args.copy()
240 # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
241 #self.args['xterm']=0
244 self.SCMD1=['SALOME_Session_Server']
246 if 'registry' in self.args['embedded']:
247 self.SCMD1+=['--with','Registry',
248 '(','--salome_session','theSession',')']
249 if 'moduleCatalog' in self.args['embedded']:
250 self.SCMD1+=['--with','ModuleCatalog','(','-common']
251 home_dir=os.getenv('HOME')
252 if home_dir is not None:
253 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
255 if 'study' in self.args['embedded']:
256 self.SCMD2+=['--with','SALOMEDS','(',')']
257 if 'cppContainer' in self.args['embedded']:
258 self.SCMD2+=['--with','Container','(','FactoryServer',')']
259 if 'SalomeAppEngine' in self.args['embedded']:
260 self.SCMD2+=['--with','SalomeAppEngine','(',')']
262 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
264 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
268 if self.args.has_key('session_gui'):
269 session_gui = self.args['session_gui']
272 if self.args['splash']:
273 self.SCMD2+=['SPLASH']
275 if self.args['study_hdf'] is not None:
276 self.SCMD2+=['--study-hdf=%s'%self.args['study_hdf']]
280 if self.args['noexcepthandler']:
281 self.SCMD2+=['noexcepthandler']
282 if self.args.has_key('user_config'):
283 self.SCMD2+=['--resources=%s'%self.args['user_config']]
284 if self.args.has_key('modules'):
286 #keep only modules with GUI
287 for m in modules_list:
288 if m not in modules_root_dir:
289 list_modules.insert(0,m)
291 fr1 = os.path.join(modules_root_dir[m],"share","salome","resources",m.lower(),"SalomeApp.xml")
292 fr2 = os.path.join(modules_root_dir[m],"share","salome","resources","SalomeApp.xml")
293 if os.path.exists(fr1) or os.path.exists(fr2):
294 list_modules.insert(0,m)
295 list_modules.reverse()
296 self.SCMD2+=['--modules (%s)' % ":".join(list_modules)]
298 if self.args.has_key('pyscript') and len(self.args['pyscript']) > 0:
299 self.SCMD2+=['--pyscript=%s'%(",".join(self.args['pyscript']))]
301 def setpath(self,modules_list,modules_root_dir):
302 list_modules = modules_list[:]
303 list_modules.reverse()
304 if self.args["gui"] :
305 list_modules = ["KERNEL", "GUI"] + list_modules
307 list_modules = ["KERNEL"] + list_modules
309 cata_path=get_cata_path(list_modules,modules_root_dir)
311 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
312 #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform
313 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
315 self.CMD=self.SCMD1 + self.SCMD2
316 if self.args.has_key('test'):
317 self.CMD+=['-test'] + self.args['test']
318 elif self.args.has_key('play'):
319 self.CMD+=['-play'] + self.args['play']
321 if self.args["gdb_session"] or self.args["ddd_session"]:
322 f = open(".gdbinit4salome", "w")
324 args = " ".join(self.CMD[1:])
325 args = args.replace("(", "\(")
326 args = args.replace(")", "\)")
330 if self.args["ddd_session"]:
331 self.CMD = ["ddd", "--command=.gdbinit4salome", self.CMD[0]]
332 elif self.args["gdb_session"]:
333 self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]]
337 if self.args["valgrind_session"]:
339 val = os.getenv("VALGRIND_OPTIONS")
343 self.CMD = l + self.CMD
348 class LauncherServer(Server):
349 def __init__(self,args):
352 self.SCMD1=['SALOME_LauncherServer']
355 if 'registry' in self.args['embedded']:
356 self.SCMD1+=['--with','Registry',
357 '(','--salome_session','theSession',')']
358 if 'moduleCatalog' in self.args['embedded']:
359 self.SCMD1+=['--with','ModuleCatalog','(','-common']
360 self.SCMD2+=['-personal',
361 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
362 if 'study' in self.args['embedded']:
363 self.SCMD2+=['--with','SALOMEDS','(',')']
364 if 'cppContainer' in self.args['embedded']:
365 self.SCMD2+=['--with','Container','(','FactoryServer',')']
367 def setpath(self,modules_list,modules_root_dir):
368 list_modules = modules_list[:]
369 list_modules.reverse()
370 if self.args["gui"] :
371 list_modules = ["KERNEL", "GUI"] + list_modules
373 list_modules = ["KERNEL"] + list_modules
375 cata_path=get_cata_path(list_modules,modules_root_dir)
377 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
378 #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform
379 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
381 self.CMD=self.SCMD1 + self.SCMD2
383 class NotifyServer(Server):
384 def __init__(self,args,modules_root_dir):
387 self.modules_root_dir=modules_root_dir
388 myLogName = os.environ["LOGNAME"]
389 self.CMD=['notifd','-c',
390 self.modules_root_dir["KERNEL"] +'/share/salome/resources/kernel/channel.cfg',
391 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
392 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
393 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
394 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
398 # -----------------------------------------------------------------------------
401 """Salome Session Graphic User Interface activation"""
405 import SALOME_ModuleCatalog
406 import SALOME_Session_idl
407 session=clt.waitNS("/Kernel/Session",SALOME.Session)
408 session.GetInterface()
410 # -----------------------------------------------------------------------------
412 def startSalome(args, modules_list, modules_root_dir):
413 """Launch all SALOME servers requested by args"""
414 init_time = os.times()
416 if verbose(): print "startSalome ", args
419 # Set server launch command
421 if args.has_key('server_launch_mode'):
422 Server.set_server_launch_mode(args['server_launch_mode'])
425 # Wake up session option
427 if args['wake_up_session']:
428 if "OMNIORB_CONFIG" not in os.environ:
429 from salome_utils import generateFileName
430 home = os.getenv("HOME")
431 appli = os.getenv("APPLI")
433 if appli is not None:
434 home = os.path.join(home, appli,"USERS")
435 kwargs["with_username"] = True
437 last_running_config = generateFileName(home, prefix="omniORB",
442 os.environ['OMNIORB_CONFIG'] = last_running_config
447 # Initialisation ORB and Naming Service
450 clt=orbmodule.client(args)
453 # Wake up session option
455 if args['wake_up_session']:
459 import SALOME_ModuleCatalog
460 import SALOME_Session_idl
461 session = clt.waitNS("/Kernel/Session",SALOME.Session)
462 status = session.GetStatSession()
464 from salome_utils import getPortNumber
465 port = getPortNumber()
468 msg += "Session GUI for port number %s is already active."%(port)
470 msg += "If you which to wake up another session,"
472 msg += "please use variable OMNIORB_CONFIG"
474 msg += "to get the correct session object in naming service."
475 sys.stdout.write(msg+"\n")
478 session.GetInterface()
479 args["session_object"] = session
482 # Save Naming service port name into
483 # the file args["ns_port_log_file"]
484 if args.has_key('ns_port_log_file'):
485 home = os.environ['HOME']
486 appli= os.environ.get("APPLI")
487 if appli is not None:
488 home = os.path.join(home, appli, "USERS")
489 file_name = os.path.join(home, args["ns_port_log_file"])
490 f = open(file_name, "w")
491 f.write(os.environ['NSPORT'])
494 # Launch Logger Server (optional)
495 # and wait until it is registered in naming service
499 myServer=LoggerServer(args)
501 clt.waitLogger("Logger")
503 # Notify Server launch
506 if sys.platform != "win32":
507 if verbose(): print "Notify Server to launch"
509 myServer=NotifyServer(args,modules_root_dir)
512 # Launch Session Server (to show splash ASAP)
516 mySessionServ = SessionServer(args,args['modules'],modules_root_dir)
517 mySessionServ.setpath(modules_list,modules_root_dir)
521 # Launch Registry Server,
522 # and wait until it is registered in naming service
525 if ('registry' not in args['embedded']) | (args["gui"] == 0) :
526 myServer=RegistryServer(args)
528 if sys.platform == "win32":
529 clt.waitNS("/Registry")
531 clt.waitNSPID("/Registry",myServer.PID)
534 # Launch Catalog Server,
535 # and wait until it is registered in naming service
538 if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
539 cataServer=CatalogServer(args)
540 cataServer.setpath(modules_list,modules_root_dir)
542 import SALOME_ModuleCatalog
543 if sys.platform == "win32":
544 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
546 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
549 # Launch SalomeDS Server,
550 # and wait until it is registered in naming service
553 #print "ARGS = ",args
554 if ('study' not in args['embedded']) | (args["gui"] == 0):
556 myServer=SalomeDSServer(args)
558 if sys.platform == "win32":
559 clt.waitNS("/myStudyManager")
561 clt.waitNSPID("/myStudyManager",myServer.PID)
564 # Launch LauncherServer
567 myCmServer = LauncherServer(args)
568 myCmServer.setpath(modules_list,modules_root_dir)
572 # Launch ConnectionManagerServer
575 myConnectionServer = ConnectionManagerServer(args)
576 myConnectionServer.run()
579 from Utils_Identity import getShortHostName
581 if os.getenv("HOSTNAME") == None:
582 if os.getenv("HOST") == None:
583 os.environ["HOSTNAME"]=getShortHostName()
585 os.environ["HOSTNAME"]=os.getenv("HOST")
587 theComputer = getShortHostName()
590 # Launch local C++ Container (FactoryServer),
591 # and wait until it is registered in naming service
594 if ('cppContainer' in args['standalone']) | (args["gui"] == 0) :
595 myServer=ContainerCPPServer(args)
597 if sys.platform == "win32":
598 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
600 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
603 # Launch local Python Container (FactoryServerPy),
604 # and wait until it is registered in naming service
607 if 'pyContainer' in args['standalone']:
608 myServer=ContainerPYServer(args)
610 if sys.platform == "win32":
611 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
613 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
616 # Wait until Session Server is registered in naming service
624 import SALOME_ModuleCatalog
625 import SALOME_Session_idl
626 if sys.platform == "win32":
627 session=clt.waitNS("/Kernel/Session",SALOME.Session)
629 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
630 args["session_object"] = session
631 end_time = os.times()
633 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
636 # ASV start GUI without Loader
638 # session.GetInterface()
641 # additionnal external python interpreters
647 nbaddi = args['interp']
650 traceback.print_exc()
651 print "-------------------------------------------------------------"
652 print "-- to get an external python interpreter:runSalome --interp=1"
653 print "-------------------------------------------------------------"
655 if verbose(): print "additional external python interpreters: ", nbaddi
657 for i in range(nbaddi):
659 anInterp=InterpServer(args)
662 # set PYTHONINSPECT variable (python interpreter in interactive mode)
664 os.environ["PYTHONINSPECT"]="1"
672 # -----------------------------------------------------------------------------
674 def useSalome(args, modules_list, modules_root_dir):
676 Launch all SALOME servers requested by args,
677 save list of process, give info to user,
678 show registered objects in Naming Service.
684 clt = startSalome(args, modules_list, modules_root_dir)
687 traceback.print_exc()
690 print "--- Error during Salome launch ---"
694 from addToKillList import addToKillList
695 from killSalomeWithPort import getPiDict
697 filedict = getPiDict(args['port'])
698 for pid, cmd in process_id.items():
699 addToKillList(pid, cmd, args['port'])
702 if verbose(): print """
703 Saving of the dictionary of Salome processes in %s
704 To kill SALOME processes from a console (kill all sessions from all ports):
706 To kill SALOME from the present interpreter, if it is not closed :
707 killLocalPort() --> kill this session
708 (use CORBA port from args of runSalome)
709 givenPortKill(port) --> kill a specific session with given CORBA port
710 killAllPorts() --> kill all sessions
712 runSalome, with --killall option, starts with killing
713 the processes resulting from the previous execution.
717 # Print Naming Service directory list
723 print " --- registered objects tree in Naming Service ---"
727 if not args['gui'] or not args['session_gui']:
728 if args['shutdown_servers']:
729 class __utils__(object):
730 def __init__(self, port):
732 import killSalomeWithPort
733 self.killSalomeWithPort = killSalomeWithPort
736 self.killSalomeWithPort.killMyPort(self.port)
739 args['shutdown_servers'] = __utils__(args['port'])
743 # run python scripts, passed via --execute option
745 if args.has_key('pyscript'):
746 if args.has_key('gui') and args.has_key('session_gui'):
747 if not args['gui'] or not args['session_gui']:
748 toimport = args['pyscript']
750 for srcname in toimport :
751 if srcname == 'killall':
756 if os.path.isabs(srcname):
757 if os.path.exists(srcname):
759 elif os.path.exists(srcname+".py"):
760 execScript(srcname+".py")
762 print "Can't execute file %s" % srcname
766 for path in [os.getcwd()] + sys.path:
767 if os.path.exists(os.path.join(path,srcname)):
768 execScript(os.path.join(path,srcname))
771 elif os.path.exists(os.path.join(path,srcname+".py")):
772 execScript(os.path.join(path,srcname+".py"))
777 print "Can't execute file %s" % srcname
785 def execScript(script_path):
786 print 'executing', script_path
787 sys.path.insert(0, os.path.dirname(script_path))
788 execfile(script_path,globals())
791 # -----------------------------------------------------------------------------
793 def registerEnv(args, modules_list, modules_root_dir):
795 Register args, modules_list, modules_root_dir in a file
796 for further use, when SALOME is launched embedded in an other application.
798 if sys.platform == "win32":
799 fileEnv = os.getenv('TEMP')
803 fileEnv += os.getenv('USER') + "_" + str(args['port']) \
804 + '_' + args['appname'].upper() + '_env'
805 fenv=open(fileEnv,'w')
806 pickle.dump((args, modules_list, modules_root_dir),fenv)
808 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
810 # -----------------------------------------------------------------------------
812 def searchFreePort(args, save_config=1):
813 print "Searching for a free port for naming service:",
815 if sys.platform == "win32":
816 tmp_file = os.getenv('TEMP');
819 tmp_file = os.path.join(tmp_file, '.netstat_%s'%os.getpid())
821 ###status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT))
822 os.system( "netstat -a -n > %s" % tmp_file );
823 f = open( tmp_file, 'r' );
824 ports = f.readlines();
826 os.remove( tmp_file );
828 def portIsUsed(port, data):
829 regObj = re.compile( ".*tcp.*:([0-9]+).*:.*listen", re.IGNORECASE );
832 p = int(regObj.match(item).group(1))
833 if p == port: return True
844 if not portIsUsed(NSPORT, ports):
845 print "%s - OK"%(NSPORT)
847 from salome_utils import generateFileName, getHostName
848 hostname = getHostName()
850 home = os.getenv("HOME")
851 appli = os.getenv("APPLI")
853 if appli is not None:
854 home = os.path.join(home, appli,"USERS")
855 kwargs["with_username"]=True
857 omniorb_config = generateFileName(home, prefix="omniORB",
864 initref = "NameService=corbaname::%s:%s"%(hostname, NSPORT)
865 from omniORB import CORBA
866 if CORBA.ORB_ID == "omniORB4":
867 orbdata.append("InitRef = %s"%(initref))
868 orbdata.append("giopMaxMsgSize = 2097152000 # 2 GBytes")
869 orbdata.append("traceLevel = 0 # critical errors only")
871 orbdata.append("ORBInitRef %s"%(initref))
872 orbdata.append("ORBgiopMaxMsgSize = 2097152000 # 2 GBytes")
873 orbdata.append("ORBtraceLevel = 0 # critical errors only")
876 f = open(omniorb_config, "w")
877 f.write("\n".join(orbdata))
880 os.environ['OMNIORB_CONFIG'] = omniorb_config
881 os.environ['NSPORT'] = "%s"%(NSPORT)
882 os.environ['NSHOST'] = "%s"%(hostname)
883 args['port'] = os.environ['NSPORT']
886 last_running_config = generateFileName(home, prefix="omniORB",
892 if sys.platform == "win32":
894 shutil.copyfile(omniorb_config, last_running_config)
897 os.remove(last_running_config)
900 os.symlink(omniorb_config, last_running_config)
909 msg += "Can't find a free port to launch omniNames\n"
910 msg += "Try to kill the running servers and then launch SALOME again.\n"
911 raise RuntimeError, msg
916 # -----------------------------------------------------------------------------
919 """Salome Launch, when embedded in other application"""
920 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
921 fenv=open(fileEnv,'r')
922 args, modules_list, modules_root_dir = pickle.load(fenv)
925 searchFreePort(args, 0)
926 clt = useSalome(args, modules_list, modules_root_dir)
929 # -----------------------------------------------------------------------------
932 """Salome launch as a main application"""
933 from salome_utils import getHostName
934 print "runSalome running on %s" % getHostName()
935 args, modules_list, modules_root_dir = setenv.get_config()
938 if args.has_key('save_config'):
939 save_config = args['save_config']
942 if args['wake_up_session']:
946 searchFreePort(args, save_config)
950 setenv.set_env(args, modules_list, modules_root_dir)
951 clt = useSalome(args, modules_list, modules_root_dir)
954 # -----------------------------------------------------------------------------
956 def foreGround(clt, args):
958 if "session_object" not in args:
960 session = args["session_object"]
962 # Wait until gui is arrived
971 status = session.GetStatSession()
972 gui_detected = status.activeGUI
977 from time import sleep
987 from salome_utils import getPortNumber
988 port = getPortNumber()
991 if sys.platform == "win32":
992 server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(os.getpid()), "%s"%(port)]
994 server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(os.getpid()), "%s"%(port)]
996 # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port))
1002 status = session.GetStatSession()
1003 assert status.activeGUI
1006 from time import sleep
1010 except KeyboardInterrupt:
1011 from killSalomeWithPort import killMyPort
1016 # -----------------------------------------------------------------------------
1018 if __name__ == "__main__":
1022 test = args['gui'] and args['session_gui']
1023 test = test or args['wake_up_session']
1025 # The next test covers the --pinter option or var PYTHONINSPECT setted
1027 test = test and not os.environ.get('PYTHONINSPECT')
1029 # The next test covers the python -i $KERNEL_ROOT_DIR/bin/salome/runSalome.py case
1032 from ctypes import POINTER, c_int, cast, pythonapi
1033 iflag_ptr = cast(pythonapi.Py_InteractiveFlag, POINTER(c_int))
1034 test = test and not iflag_ptr.contents.value
1038 test = test and os.getenv("SALOME_TEST_MODE", "0") != "1"
1039 test = test and args['foreground']
1042 foreGround(clt, args)