2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2011 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
33 from launchConfigureParser import verbose
34 from server import process_id
36 if sys.platform == "win32":
41 # -----------------------------------------------------------------------------
43 from killSalome import killAllPorts
47 kill servers from a previous SALOME exection, if needed,
48 on the CORBA port given in args of runSalome
51 from killSalomeWithPort import killMyPort
52 my_port=str(args['port'])
56 print "problem in killLocalPort()"
60 def givenPortKill(port):
62 kill servers from a previous SALOME exection, if needed,
63 on the same CORBA port
66 from killSalomeWithPort import killMyPort
71 print "problem in LocalPortKill(), killMyPort("<<port<<")"
75 def kill_salome(args):
77 Kill servers from previous SALOME executions, if needed;
78 depending on args 'killall' or 'portkill', kill all executions,
79 or only execution on the same CORBA port
84 elif args['portkill']:
85 givenPortKill(str(args['port']))
87 # -----------------------------------------------------------------------------
89 # Class definitions to launch CORBA Servers
92 class InterpServer(Server):
93 def __init__(self,args):
95 if sys.platform != "win32":
96 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
97 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
99 self.CMD=['cmd', '/c', 'start cmd.exe', '/K', 'python']
104 print "INTERPSERVER::command = ", command
105 if sys.platform == "win32":
107 pid = win32pm.spawnpid( string.join(command, " "),'-nc' )
109 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
110 process_id[pid]=self.CMD
115 def get_cata_path(list_modules,modules_root_dir):
116 """Build a list of catalog paths (cata_path) to initialize the ModuleCatalog server
121 for module in list_modules:
122 if modules_root_dir.has_key(module):
123 module_root_dir=modules_root_dir[module]
124 module_cata=module+"Catalog.xml"
125 cata_file=os.path.join(module_root_dir, "share",setenv.salome_subdir, "resources",module.lower(), module_cata)
127 if os.path.exists(cata_file):
128 cata_path.append(cata_file)
129 modules_cata[module]=cata_file
131 cata_file=os.path.join(module_root_dir, "share",setenv.salome_subdir, "resources", module_cata)
132 if os.path.exists(cata_file):
133 cata_path.append(cata_file)
134 modules_cata[module]=cata_file
136 for path in os.getenv("SALOME_CATALOGS_PATH","").split(SEP):
137 if os.path.exists(path):
138 for cata_file in glob.glob(os.path.join(path,"*Catalog.xml")):
139 module_name= os.path.basename(cata_file)[:-11]
140 if not modules_cata.has_key(module_name):
141 cata_path.append(cata_file)
142 modules_cata[module_name]=cata_file
148 class CatalogServer(Server):
149 def __init__(self,args):
152 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
154 home_dir=os.getenv('HOME')
155 if home_dir is not None:
156 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
158 def setpath(self,modules_list,modules_root_dir):
159 list_modules = modules_list[:]
160 list_modules.reverse()
161 if self.args["gui"] :
162 list_modules = ["KERNEL", "GUI"] + list_modules
164 list_modules = ["KERNEL"] + list_modules
166 cata_path=get_cata_path(list_modules,modules_root_dir)
168 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
172 class SalomeDSServer(Server):
173 def __init__(self,args):
176 self.CMD=['SALOMEDS_Server']
180 class ConnectionManagerServer(Server):
181 def __init__(self,args):
184 self.CMD=['SALOME_ConnectionManagerServer']
188 class RegistryServer(Server):
189 def __init__(self,args):
192 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
196 class ContainerCPPServer(Server):
197 def __init__(self,args):
200 self.CMD=['SALOME_Container','FactoryServer']
204 class ContainerPYServer(Server):
205 def __init__(self,args):
208 if sys.platform == "win32":
209 self.CMD=[os.environ["PYTHONBIN"], '\"'+os.environ["KERNEL_ROOT_DIR"] + '/bin/salome/SALOME_ContainerPy.py'+'\"','FactoryServerPy']
211 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
215 class LoggerServer(Server):
216 def __init__(self,args):
219 from salome_utils import generateFileName
220 if sys.platform == "win32": dirpath = os.environ["HOME"]
221 else: dirpath = "/tmp"
222 logfile = generateFileName( dirpath,
228 print "==========================================================="
229 print "Logger server: put log to the file:"
231 print "==========================================================="
232 self.CMD=['SALOME_Logger_Server', logfile]
234 pass # end of LoggerServer class
238 class SessionServer(Server):
239 def __init__(self,args,modules_list,modules_root_dir):
240 self.args = args.copy()
241 # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
242 #self.args['xterm']=0
245 self.SCMD1=['SALOME_Session_Server']
247 if 'registry' in self.args['embedded']:
248 self.SCMD1+=['--with','Registry',
249 '(','--salome_session','theSession',')']
250 if 'moduleCatalog' in self.args['embedded']:
251 self.SCMD1+=['--with','ModuleCatalog','(','-common']
252 home_dir=os.getenv('HOME')
253 if home_dir is not None:
254 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
256 if 'study' in self.args['embedded']:
257 self.SCMD2+=['--with','SALOMEDS','(',')']
258 if 'cppContainer' in self.args['embedded']:
259 self.SCMD2+=['--with','Container','(','FactoryServer',')']
260 if 'SalomeAppEngine' in self.args['embedded']:
261 self.SCMD2+=['--with','SalomeAppEngine','(',')']
263 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
265 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
269 if self.args.has_key('session_gui'):
270 session_gui = self.args['session_gui']
273 if self.args['splash']:
274 self.SCMD2+=['SPLASH']
276 if self.args['study_hdf'] is not None:
277 self.SCMD2+=['--study-hdf=%s'%self.args['study_hdf']]
281 if self.args['noexcepthandler']:
282 self.SCMD2+=['noexcepthandler']
283 if self.args.has_key('user_config'):
284 self.SCMD2+=['--resources=%s'%self.args['user_config']]
285 if self.args.has_key('modules'):
287 #keep only modules with GUI
288 for m in modules_list:
289 if m not in modules_root_dir:
290 list_modules.insert(0,m)
292 fr1 = os.path.join(modules_root_dir[m],"share","salome","resources",m.lower(),"SalomeApp.xml")
293 fr2 = os.path.join(modules_root_dir[m],"share","salome","resources","SalomeApp.xml")
294 if os.path.exists(fr1) or os.path.exists(fr2):
295 list_modules.insert(0,m)
296 list_modules.reverse()
297 self.SCMD2+=['--modules (%s)' % ":".join(list_modules)]
299 if self.args.has_key('pyscript') and len(self.args['pyscript']) > 0:
300 self.SCMD2+=['--pyscript=%s'%(",".join(self.args['pyscript']))]
302 def setpath(self,modules_list,modules_root_dir):
303 list_modules = modules_list[:]
304 list_modules.reverse()
305 if self.args["gui"] :
306 list_modules = ["KERNEL", "GUI"] + list_modules
308 list_modules = ["KERNEL"] + list_modules
310 cata_path=get_cata_path(list_modules,modules_root_dir)
312 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
313 #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform
314 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
316 self.CMD=self.SCMD1 + self.SCMD2
317 if self.args.has_key('test'):
318 self.CMD+=['-test'] + self.args['test']
319 elif self.args.has_key('play'):
320 self.CMD+=['-play'] + self.args['play']
322 if self.args["gdb_session"] or self.args["ddd_session"]:
323 f = open(".gdbinit4salome", "w")
325 args = " ".join(self.CMD[1:])
326 args = args.replace("(", "\(")
327 args = args.replace(")", "\)")
331 if self.args["ddd_session"]:
332 self.CMD = ["ddd", "--command=.gdbinit4salome", self.CMD[0]]
333 elif self.args["gdb_session"]:
334 self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]]
338 if self.args["valgrind_session"]:
340 val = os.getenv("VALGRIND_OPTIONS")
344 self.CMD = l + self.CMD
349 class LauncherServer(Server):
350 def __init__(self,args):
353 self.SCMD1=['SALOME_LauncherServer']
356 if 'registry' in self.args['embedded']:
357 self.SCMD1+=['--with','Registry',
358 '(','--salome_session','theSession',')']
359 if 'moduleCatalog' in self.args['embedded']:
360 self.SCMD1+=['--with','ModuleCatalog','(','-common']
361 self.SCMD2+=['-personal',
362 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
363 if 'study' in self.args['embedded']:
364 self.SCMD2+=['--with','SALOMEDS','(',')']
365 if 'cppContainer' in self.args['embedded']:
366 self.SCMD2+=['--with','Container','(','FactoryServer',')']
368 def setpath(self,modules_list,modules_root_dir):
369 list_modules = modules_list[:]
370 list_modules.reverse()
371 if self.args["gui"] :
372 list_modules = ["KERNEL", "GUI"] + list_modules
374 list_modules = ["KERNEL"] + list_modules
376 cata_path=get_cata_path(list_modules,modules_root_dir)
378 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
379 #Use '::' instead ":" because drive path with "D:\" is invalid on windows platform
380 self.CMD=self.SCMD1 + ['"' + string.join(cata_path,'"::"') + '"'] + self.SCMD2
382 self.CMD=self.SCMD1 + self.SCMD2
384 class NotifyServer(Server):
385 def __init__(self,args,modules_root_dir):
388 self.modules_root_dir=modules_root_dir
389 myLogName = os.environ["LOGNAME"]
390 self.CMD=['notifd','-c',
391 self.modules_root_dir["KERNEL"] +'/share/salome/resources/kernel/channel.cfg',
392 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
393 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
394 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
395 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
399 # -----------------------------------------------------------------------------
402 """Salome Session Graphic User Interface activation"""
406 import SALOME_ModuleCatalog
407 import SALOME_Session_idl
408 session=clt.waitNS("/Kernel/Session",SALOME.Session)
409 session.GetInterface()
411 # -----------------------------------------------------------------------------
413 def startSalome(args, modules_list, modules_root_dir):
414 """Launch all SALOME servers requested by args"""
415 init_time = os.times()
417 if verbose(): print "startSalome ", args
420 # Wake up session option
422 if args['wake_up_session']:
423 if "OMNIORB_CONFIG" not in os.environ:
424 from salome_utils import generateFileName
425 home = os.getenv("HOME")
426 appli = os.getenv("APPLI")
428 if appli is not None:
429 home = os.path.join(home, appli,"USERS")
430 kwargs["with_username"] = True
432 last_running_config = generateFileName(home, prefix="omniORB",
437 os.environ['OMNIORB_CONFIG'] = last_running_config
442 # Initialisation ORB and Naming Service
445 clt=orbmodule.client(args)
448 # Wake up session option
450 if args['wake_up_session']:
454 import SALOME_ModuleCatalog
455 import SALOME_Session_idl
456 session = clt.waitNS("/Kernel/Session",SALOME.Session)
457 status = session.GetStatSession()
459 from salome_utils import getPortNumber
460 port = getPortNumber()
463 msg += "Session GUI for port number %s is already active."%(port)
465 msg += "If you which to wake up another session,"
467 msg += "please use variable OMNIORB_CONFIG"
469 msg += "to get the correct session object in naming service."
470 sys.stdout.write(msg+"\n")
473 session.GetInterface()
474 args["session_object"] = session
477 # Save Naming service port name into
478 # the file args["ns_port_log_file"]
479 if args.has_key('ns_port_log_file'):
480 home = os.environ['HOME']
481 appli= os.environ.get("APPLI")
482 if appli is not None:
483 home = os.path.join(home, appli, "USERS")
484 file_name = os.path.join(home, args["ns_port_log_file"])
485 f = open(file_name, "w")
486 f.write(os.environ['NSPORT'])
489 # Launch Logger Server (optional)
490 # and wait until it is registered in naming service
494 myServer=LoggerServer(args)
496 clt.waitLogger("Logger")
498 # Notify Server launch
501 if sys.platform != "win32":
502 if verbose(): print "Notify Server to launch"
504 myServer=NotifyServer(args,modules_root_dir)
507 # Launch Session Server (to show splash ASAP)
511 mySessionServ = SessionServer(args,args['modules'],modules_root_dir)
512 mySessionServ.setpath(modules_list,modules_root_dir)
516 # Launch Registry Server,
517 # and wait until it is registered in naming service
520 if ('registry' not in args['embedded']) | (args["gui"] == 0) :
521 myServer=RegistryServer(args)
523 if sys.platform == "win32":
524 clt.waitNS("/Registry")
526 clt.waitNSPID("/Registry",myServer.PID)
529 # Launch Catalog Server,
530 # and wait until it is registered in naming service
533 if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
534 cataServer=CatalogServer(args)
535 cataServer.setpath(modules_list,modules_root_dir)
537 import SALOME_ModuleCatalog
538 if sys.platform == "win32":
539 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
541 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
544 # Launch SalomeDS Server,
545 # and wait until it is registered in naming service
548 #print "ARGS = ",args
549 if ('study' not in args['embedded']) | (args["gui"] == 0):
551 myServer=SalomeDSServer(args)
553 if sys.platform == "win32":
554 clt.waitNS("/myStudyManager")
556 clt.waitNSPID("/myStudyManager",myServer.PID)
559 # Launch LauncherServer
562 myCmServer = LauncherServer(args)
563 myCmServer.setpath(modules_list,modules_root_dir)
567 # Launch ConnectionManagerServer
570 myConnectionServer = ConnectionManagerServer(args)
571 myConnectionServer.run()
574 from Utils_Identity import getShortHostName
576 if os.getenv("HOSTNAME") == None:
577 if os.getenv("HOST") == None:
578 os.environ["HOSTNAME"]=getShortHostName()
580 os.environ["HOSTNAME"]=os.getenv("HOST")
582 theComputer = getShortHostName()
585 # Launch local C++ Container (FactoryServer),
586 # and wait until it is registered in naming service
589 if ('cppContainer' in args['standalone']) | (args["gui"] == 0) :
590 myServer=ContainerCPPServer(args)
592 if sys.platform == "win32":
593 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
595 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
598 # Launch local Python Container (FactoryServerPy),
599 # and wait until it is registered in naming service
602 if 'pyContainer' in args['standalone']:
603 myServer=ContainerPYServer(args)
605 if sys.platform == "win32":
606 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
608 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
611 # Wait until Session Server is registered in naming service
619 import SALOME_ModuleCatalog
620 import SALOME_Session_idl
621 if sys.platform == "win32":
622 session=clt.waitNS("/Kernel/Session",SALOME.Session)
624 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
625 args["session_object"] = session
626 end_time = os.times()
628 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
631 # ASV start GUI without Loader
633 # session.GetInterface()
636 # additionnal external python interpreters
642 nbaddi = args['interp']
645 traceback.print_exc()
646 print "-------------------------------------------------------------"
647 print "-- to get an external python interpreter:runSalome --interp=1"
648 print "-------------------------------------------------------------"
650 if verbose(): print "additional external python interpreters: ", nbaddi
652 for i in range(nbaddi):
654 anInterp=InterpServer(args)
657 # set PYTHONINSPECT variable (python interpreter in interactive mode)
659 os.environ["PYTHONINSPECT"]="1"
667 # -----------------------------------------------------------------------------
669 def useSalome(args, modules_list, modules_root_dir):
671 Launch all SALOME servers requested by args,
672 save list of process, give info to user,
673 show registered objects in Naming Service.
679 clt = startSalome(args, modules_list, modules_root_dir)
682 traceback.print_exc()
685 print "--- Error during Salome launch ---"
689 from addToKillList import addToKillList
690 from killSalomeWithPort import getPiDict
692 filedict = getPiDict(args['port'])
693 for pid, cmd in process_id.items():
694 addToKillList(pid, cmd, args['port'])
697 if verbose(): print """
698 Saving of the dictionary of Salome processes in %s
699 To kill SALOME processes from a console (kill all sessions from all ports):
701 To kill SALOME from the present interpreter, if it is not closed :
702 killLocalPort() --> kill this session
703 (use CORBA port from args of runSalome)
704 givenPortKill(port) --> kill a specific session with given CORBA port
705 killAllPorts() --> kill all sessions
707 runSalome, with --killall option, starts with killing
708 the processes resulting from the previous execution.
712 # Print Naming Service directory list
718 print " --- registered objects tree in Naming Service ---"
722 if not args['gui'] or not args['session_gui']:
723 if args['shutdown_servers']:
724 class __utils__(object):
725 def __init__(self, port):
727 import killSalomeWithPort
728 self.killSalomeWithPort = killSalomeWithPort
731 self.killSalomeWithPort.killMyPort(self.port)
734 args['shutdown_servers'] = __utils__(args['port'])
738 # run python scripts, passed via --execute option
740 if args.has_key('pyscript'):
741 if args.has_key('gui') and args.has_key('session_gui'):
742 if not args['gui'] or not args['session_gui']:
743 toimport = args['pyscript']
745 for srcname in toimport :
746 if srcname == 'killall':
751 if os.path.isabs(srcname):
752 if os.path.exists(srcname):
754 elif os.path.exists(srcname+".py"):
755 execScript(srcname+".py")
757 print "Can't execute file %s" % srcname
761 for path in [os.getcwd()] + sys.path:
762 if os.path.exists(os.path.join(path,srcname)):
763 execScript(os.path.join(path,srcname))
766 elif os.path.exists(os.path.join(path,srcname+".py")):
767 execScript(os.path.join(path,srcname+".py"))
772 print "Can't execute file %s" % srcname
780 def execScript(script_path):
781 print 'executing', script_path
782 sys.path.insert(0, os.path.dirname(script_path))
783 execfile(script_path,globals())
786 # -----------------------------------------------------------------------------
788 def registerEnv(args, modules_list, modules_root_dir):
790 Register args, modules_list, modules_root_dir in a file
791 for further use, when SALOME is launched embedded in an other application.
793 if sys.platform == "win32":
794 fileEnv = os.getenv('TEMP')
798 fileEnv += os.getenv('USER') + "_" + str(args['port']) \
799 + '_' + args['appname'].upper() + '_env'
800 fenv=open(fileEnv,'w')
801 pickle.dump((args, modules_list, modules_root_dir),fenv)
803 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
805 # -----------------------------------------------------------------------------
807 def searchFreePort(args, save_config=1):
808 print "Searching for a free port for naming service:",
810 if sys.platform == "win32":
811 tmp_file = os.getenv('TEMP');
814 tmp_file = os.path.join(tmp_file, '.netstat_%s'%os.getpid())
816 ###status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT))
817 os.system( "netstat -a -n > %s" % tmp_file );
818 f = open( tmp_file, 'r' );
819 ports = f.readlines();
821 os.remove( tmp_file );
823 def portIsUsed(port, data):
824 regObj = re.compile( ".*tcp.*:([0-9]+).*:.*listen", re.IGNORECASE );
827 p = int(regObj.match(item).group(1))
828 if p == port: return True
839 if not portIsUsed(NSPORT, ports):
840 print "%s - OK"%(NSPORT)
842 from salome_utils import generateFileName, getHostName
843 hostname = getHostName()
845 home = os.getenv("HOME")
846 appli = os.getenv("APPLI")
848 if appli is not None:
849 home = os.path.join(home, appli,"USERS")
850 kwargs["with_username"]=True
852 omniorb_config = generateFileName(home, prefix="omniORB",
859 initref = "NameService=corbaname::%s:%s"%(hostname, NSPORT)
860 from omniORB import CORBA
861 if CORBA.ORB_ID == "omniORB4":
862 orbdata.append("InitRef = %s"%(initref))
863 orbdata.append("giopMaxMsgSize = 2097152000 # 2 GBytes")
864 orbdata.append("traceLevel = 0 # critical errors only")
866 orbdata.append("ORBInitRef %s"%(initref))
867 orbdata.append("ORBgiopMaxMsgSize = 2097152000 # 2 GBytes")
868 orbdata.append("ORBtraceLevel = 0 # critical errors only")
871 f = open(omniorb_config, "w")
872 f.write("\n".join(orbdata))
875 os.environ['OMNIORB_CONFIG'] = omniorb_config
876 os.environ['NSPORT'] = "%s"%(NSPORT)
877 os.environ['NSHOST'] = "%s"%(hostname)
878 args['port'] = os.environ['NSPORT']
881 last_running_config = generateFileName(home, prefix="omniORB",
887 if sys.platform == "win32":
889 shutil.copyfile(omniorb_config, last_running_config)
892 os.remove(last_running_config)
895 os.symlink(omniorb_config, last_running_config)
904 msg += "Can't find a free port to launch omniNames\n"
905 msg += "Try to kill the running servers and then launch SALOME again.\n"
906 raise RuntimeError, msg
911 # -----------------------------------------------------------------------------
914 """Salome Launch, when embedded in other application"""
915 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
916 fenv=open(fileEnv,'r')
917 args, modules_list, modules_root_dir = pickle.load(fenv)
920 searchFreePort(args, 0)
921 clt = useSalome(args, modules_list, modules_root_dir)
924 # -----------------------------------------------------------------------------
927 """Salome launch as a main application"""
928 from salome_utils import getHostName
929 print "runSalome running on %s" % getHostName()
930 args, modules_list, modules_root_dir = setenv.get_config()
933 if args.has_key('save_config'):
934 save_config = args['save_config']
937 if args['wake_up_session']:
941 searchFreePort(args, save_config)
945 setenv.set_env(args, modules_list, modules_root_dir)
946 clt = useSalome(args, modules_list, modules_root_dir)
949 # -----------------------------------------------------------------------------
951 def foreGround(clt, args):
953 if "session_object" not in args:
955 session = args["session_object"]
957 # Wait until gui is arrived
966 status = session.GetStatSession()
967 gui_detected = status.activeGUI
972 from time import sleep
982 from salome_utils import getPortNumber
983 port = getPortNumber()
986 if sys.platform == "win32":
987 server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(os.getpid()), "%s"%(port)]
989 server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(os.getpid()), "%s"%(port)]
991 # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port))
997 status = session.GetStatSession()
998 assert status.activeGUI
1001 from time import sleep
1005 except KeyboardInterrupt:
1006 from killSalomeWithPort import killMyPort
1011 # -----------------------------------------------------------------------------
1013 if __name__ == "__main__":
1017 test = args['gui'] and args['session_gui']
1018 test = test or args['wake_up_session']
1020 # The next test covers the --pinter option or var PYTHONINSPECT setted
1022 test = test and not os.environ.get('PYTHONINSPECT')
1024 # The next test covers the python -i $KERNEL_ROOT_DIR/bin/salome/runSalome.py case
1027 from ctypes import POINTER, c_int, cast, pythonapi
1028 iflag_ptr = cast(pythonapi.Py_InteractiveFlag, POINTER(c_int))
1029 test = test and not iflag_ptr.contents.value
1033 test = test and os.getenv("SALOME_TEST_MODE", "0") != "1"
1034 test = test and args['foreground']
1037 foreGround(clt, args)