3 import sys, os, string, glob, time, pickle
8 # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc.
9 # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used.
10 # but after - 'appname' = "SalomeApp", so using it in making the subdirectory is an error.
11 salome_subdir = "salome"
13 # -----------------------------------------------------------------------------
15 def add_path(directory, variable_name):
16 """Function helper to add environment variables"""
17 if not os.environ.has_key(variable_name):
18 os.environ[variable_name] = ""
20 if os.path.exists(directory):
22 for _dir in os.environ[variable_name].split(":"):
23 if os.path.exists(_dir):
24 if not os.path.samefile(_dir, directory):
27 if os.path.abspath(_dir) != os.path.abspath(directory):
31 newpath[:0] = [ directory ]
32 newpath = string.join(newpath,":")
33 os.environ[variable_name] = newpath
34 if variable_name == "PYTHONPATH":
35 sys.path[:0] = [directory]
37 # -----------------------------------------------------------------------------
41 Get list of modules, paths.
43 Read args from launch configure xml file and command line options.
44 Check variables <module>_ROOT_DIR and set list of used modules.
45 Return args, modules_list, modules_root_dir
48 # read args from launch configure xml file and command line options
50 import launchConfigureParser
51 args = launchConfigureParser.args
53 # Check variables <module>_ROOT_DIR
54 # and set list of used modules (without KERNEL)
57 if args.has_key("modules"):
58 modules_list += args["modules"]
59 # KERNEL must be last in the list to locate it at the first place in PATH
60 modules_list[:0] = ["GUI"]
61 modules_list[:0] = ["KERNEL"]
62 modules_list.reverse()
67 for module in modules_list :
68 module_variable=module.upper()+"_ROOT_DIR"
69 if not os.environ.has_key(module_variable):
70 print "*******************************************************"
72 print "* Environment variable",module_variable,"must be set"
73 print "* Module", module, "will be not available"
75 print "********************************************************"
76 to_remove_list.append(module)
79 module_root_dir = os.environ[module_variable]
80 modules_root_dir[module]=module_root_dir
82 for to_remove in to_remove_list:
83 modules_list.remove(to_remove)
85 while "KERNEL" in modules_list:
86 modules_list.remove("KERNEL")
89 while "GUI" in modules_list:
90 modules_list.remove("GUI")
93 if "SUPERV" in modules_list and not 'superv' in args['standalone']:
94 args['standalone'].append("superv")
97 return args, modules_list, modules_root_dir
99 # -----------------------------------------------------------------------------
101 def set_env(args, modules_list, modules_root_dir):
102 """Add to the PATH-variables modules specific paths"""
104 python_version="python%d.%d" % sys.version_info[0:2]
105 modules_root_dir_list = []
106 modules_list = modules_list[:] + ["GUI"]
107 modules_list = modules_list[:] + ["KERNEL"]
108 for module in modules_list :
109 if modules_root_dir.has_key(module):
110 module_root_dir = modules_root_dir[module]
111 modules_root_dir_list[:0] = [module_root_dir]
112 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
114 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
116 if os.path.exists(module_root_dir + "/examples") :
117 add_path(os.path.join(module_root_dir,"examples"),
120 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
122 add_path(os.path.join(module_root_dir,"lib",
123 python_version,"site-packages",
126 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
128 add_path(os.path.join(module_root_dir,"lib",
129 python_version,"site-packages",
137 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
139 # set trace environment variable
141 if not os.environ.has_key("SALOME_trace"):
142 os.environ["SALOME_trace"]="local"
144 os.environ["SALOME_trace"]="file:"+args['file'][0]
146 os.environ["SALOME_trace"]="with_logger"
148 # set environment for SMESH plugins
150 if "SMESH" in modules_list:
151 os.environ["SMESH_MeshersList"]="StdMeshers"
152 if not os.environ.has_key("SALOME_StdMeshersResources"):
153 os.environ["SALOME_StdMeshersResources"] \
154 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
156 if args.has_key("SMESH_plugins"):
157 for plugin in args["SMESH_plugins"]:
158 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
159 os.environ["SMESH_MeshersList"] \
160 = os.environ["SMESH_MeshersList"]+":"+plugin
161 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
162 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
163 os.environ["SALOME_"+plugin+"Resources"] \
164 = plugin_root+"/share/"+args["appname"]+"/resources"
165 add_path(os.path.join(plugin_root,"lib",python_version,
166 "site-packages",salome_subdir),
168 add_path(os.path.join(plugin_root,"lib",salome_subdir),
170 add_path(os.path.join(plugin_root,"lib",salome_subdir),
172 add_path(os.path.join(plugin_root,"bin",salome_subdir),
174 add_path(os.path.join(plugin_root,"bin",salome_subdir),
179 # set environment for SUPERV module
180 os.environ["ENABLE_MACRO_NODE"]="1"
181 # set resources variables if not yet set
182 if os.getenv("GUI_ROOT_DIR"):
183 if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
184 if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
187 os.environ["CSF_PluginDefaults"] \
188 = os.path.join(modules_root_dir["KERNEL"],"share",
189 salome_subdir,"resources")
190 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
191 = os.path.join(modules_root_dir["KERNEL"],"share",
192 salome_subdir,"resources")
194 if "GEOM" in modules_list:
195 print "GEOM OCAF Resources"
196 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
197 = os.path.join(modules_root_dir["GEOM"],"share",
198 salome_subdir,"resources")
199 print "GEOM Shape Healing Resources"
200 os.environ["CSF_ShHealingDefaults"] \
201 = os.path.join(modules_root_dir["GEOM"],"share",
202 salome_subdir,"resources")
204 # -----------------------------------------------------------------------------
206 from killSalome import killAllPorts
210 kill servers from a previous SALOME exection, if needed,
211 on the CORBA port given in args of runSalome
214 from killSalomeWithPort import killMyPort
215 my_port=str(args['port'])
219 print "problem in killLocalPort()"
223 def givenPortKill(port):
225 kill servers from a previous SALOME exection, if needed,
226 on the same CORBA port
229 from killSalomeWithPort import killMyPort
234 print "problem in LocalPortKill(), killMyPort("<<port<<")"
238 def kill_salome(args):
240 Kill servers from previous SALOME executions, if needed;
241 depending on args 'killall' or 'portkill', kill all executions,
242 or only execution on the same CORBA port
247 elif args['portkill']:
248 givenPortKill(str(args['port']))
250 # -----------------------------------------------------------------------------
252 # Definition des classes d'objets pour le lancement des Server CORBA
256 """Generic class for CORBA server launch"""
262 if self.args['xterm']:
263 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
265 def __init__(self,args):
273 if self.args['xterm']:
274 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
275 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
276 + os.getenv("LD_LIBRARY_PATH")]
277 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
278 command = myargs + self.CMD
279 print "command = ", command
280 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
281 process_id[pid]=self.CMD
285 class InterpServer(Server):
286 def __init__(self,args):
288 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
289 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
290 #self.CMD=['xterm', '-e', 'python']
295 #print "command = ", command
296 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
297 process_id[pid]=self.CMD
302 class CatalogServer(Server):
303 def __init__(self,args):
306 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
308 home_dir=os.getenv('HOME')
309 if home_dir is not None:
310 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
312 def setpath(self,modules_list,modules_root_dir):
314 list_modules = modules_list[:]
315 list_modules.reverse()
316 for module in ["KERNEL", "GUI"] + list_modules:
317 if modules_root_dir.has_key(module):
318 module_root_dir=modules_root_dir[module]
319 module_cata=module+"Catalog.xml"
320 #print " ", module_cata
322 glob.glob(os.path.join(module_root_dir,
323 "share",salome_subdir,
324 "resources",module_cata)))
327 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
331 class SalomeDSServer(Server):
332 def __init__(self,args):
335 self.CMD=['SALOMEDS_Server']
339 class RegistryServer(Server):
340 def __init__(self,args):
343 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
347 class ContainerCPPServer(Server):
348 def __init__(self,args):
351 self.CMD=['SALOME_Container','FactoryServer']
355 class ContainerPYServer(Server):
356 def __init__(self,args):
359 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
363 class ContainerSUPERVServer(Server):
364 def __init__(self,args):
367 self.CMD=['SALOME_Container','SuperVisionContainer']
371 class LoggerServer(Server):
372 def __init__(self,args):
375 self.CMD=['SALOME_Logger_Server', 'logger.log']
379 class SessionServer(Server):
380 def __init__(self,args):
383 self.SCMD1=['SALOME_Session_Server']
385 if 'registry' in self.args['embedded']:
386 self.SCMD1+=['--with','Registry',
387 '(','--salome_session','theSession',')']
388 if 'moduleCatalog' in self.args['embedded']:
389 self.SCMD1+=['--with','ModuleCatalog','(','-common']
390 home_dir=os.getenv('HOME')
391 if home_dir is not None:
392 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
394 if 'study' in self.args['embedded']:
395 self.SCMD2+=['--with','SALOMEDS','(',')']
396 if 'cppContainer' in self.args['embedded']:
397 self.SCMD2+=['--with','Container','(','FactoryServer',')']
398 if 'SalomeAppEngine' in self.args['embedded']:
399 self.SCMD2+=['--with','SalomeAppEngine','(',')']
401 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
403 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
405 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
406 self.SCMD2+=['SUPERV']
409 if self.args['splash']:
410 self.SCMD2+=['SPLASH']
411 if self.args.has_key('modules'):
412 self.SCMD2+=['--modules (']
413 for mod in self.args['modules']:
414 self.SCMD2+=[mod + ':']
417 def setpath(self,modules_list,modules_root_dir):
419 list_modules = modules_list[:]
420 list_modules.reverse()
421 for module in ["KERNEL", "GUI"] + list_modules:
422 module_root_dir=modules_root_dir[module]
423 module_cata=module+"Catalog.xml"
424 #print " ", module_cata
426 glob.glob(os.path.join(module_root_dir,"share",
427 salome_subdir,"resources",
429 if 'moduleCatalog' in self.args['embedded']:
430 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
432 self.CMD=self.SCMD1 + self.SCMD2
436 class ContainerManagerServer(Server):
437 def __init__(self,args):
440 self.SCMD1=['SALOME_ContainerManagerServer']
442 if 'registry' in self.args['embedded']:
443 self.SCMD1+=['--with','Registry',
444 '(','--salome_session','theSession',')']
445 if 'moduleCatalog' in self.args['embedded']:
446 self.SCMD1+=['--with','ModuleCatalog','(','-common']
447 self.SCMD2+=['-personal',
448 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
449 if 'study' in self.args['embedded']:
450 self.SCMD2+=['--with','SALOMEDS','(',')']
451 if 'cppContainer' in self.args['embedded']:
452 self.SCMD2+=['--with','Container','(','FactoryServer',')']
454 def setpath(self,modules_list,modules_root_dir):
456 list_modules = modules_list[:]
457 list_modules.reverse()
458 for module in ["KERNEL", "GUI"] + list_modules:
459 if modules_root_dir.has_key(module):
460 module_root_dir=modules_root_dir[module]
461 module_cata=module+"Catalog.xml"
462 #print " ", module_cata
464 glob.glob(os.path.join(module_root_dir,"share",
465 self.args['appname'],"resources",
469 if 'moduleCatalog' in self.args['embedded']:
470 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
472 self.CMD=self.SCMD1 + self.SCMD2
474 class NotifyServer(Server):
475 def __init__(self,args,modules_root_dir):
478 self.modules_root_dir=modules_root_dir
479 myLogName = os.environ["LOGNAME"]
480 self.CMD=['notifd','-c',
481 self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
482 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
483 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
484 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
485 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
489 # -----------------------------------------------------------------------------
492 """Salome Session Graphic User Interface activation"""
494 import SALOME_Session_idl
495 session=clt.waitNS("/Kernel/Session",SALOME.Session)
496 session.GetInterface()
498 # -----------------------------------------------------------------------------
500 def startSalome(args, modules_list, modules_root_dir):
501 """Launch all SALOME servers requested by args"""
502 init_time = os.times()
504 print "startSalome ", args
507 # Initialisation ORB et Naming Service
510 clt=orbmodule.client()
512 # (non obligatoire) Lancement Logger Server
513 # et attente de sa disponibilite dans le naming service
517 myServer=LoggerServer(args)
519 clt.waitLogger("Logger")
521 # Notify Server launch
524 print "Notify Server to launch"
526 myServer=NotifyServer(args,modules_root_dir)
530 # Lancement Registry Server,
531 # attente de la disponibilite du Registry dans le Naming Service
534 if 'registry' not in args['embedded']:
535 myServer=RegistryServer(args)
537 clt.waitNSPID("/Registry",myServer.PID)
540 # Lancement Catalog Server,
541 # attente de la disponibilite du Catalog Server dans le Naming Service
545 if 'moduleCatalog' not in args['embedded']:
546 cataServer=CatalogServer(args)
547 cataServer.setpath(modules_list,modules_root_dir)
549 import SALOME_ModuleCatalog
550 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
553 # Lancement SalomeDS Server,
554 # attente de la disponibilite du SalomeDS dans le Naming Service
557 #print "ARGS = ",args
558 if 'study' not in args['embedded']:
560 myServer=SalomeDSServer(args)
562 clt.waitNSPID("/myStudyManager",myServer.PID)
565 # Lancement ContainerManagerServer
568 myCmServer = ContainerManagerServer(args)
569 myCmServer.setpath(modules_list,modules_root_dir)
573 from Utils_Identity import getShortHostName
575 if os.getenv("HOSTNAME") == None:
576 if os.getenv("HOST") == None:
577 os.environ["HOSTNAME"]=getShortHostName()
579 os.environ["HOSTNAME"]=os.getenv("HOST")
581 theComputer = getShortHostName()
584 # Lancement Container C++ local,
585 # attente de la disponibilite du Container C++ local dans le Naming Service
588 if 'cppContainer' in args['standalone']:
589 myServer=ContainerCPPServer(args)
591 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
594 # Lancement Container Python local,
595 # attente de la disponibilite du Container Python local
596 # dans le Naming Service
599 if 'pyContainer' in args['standalone']:
600 myServer=ContainerPYServer(args)
602 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
605 # Lancement Container Supervision local,
606 # attente de la disponibilite du Container Supervision local
607 # dans le Naming Service
610 if 'supervContainer' in args['standalone']:
611 myServer=ContainerSUPERVServer(args)
613 clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
616 # Lancement Session Server
619 mySessionServ = SessionServer(args)
620 mySessionServ.setpath(modules_list,modules_root_dir)
624 # Attente de la disponibilite du Session Server dans le Naming Service
628 import SALOME_Session_idl
629 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.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
648 nbaddi = int(args['interp'][0])
651 traceback.print_exc()
652 print "-------------------------------------------------------------"
653 print "-- to get an external python interpreter:runSalome --interp=1"
654 print "-------------------------------------------------------------"
656 print "additional external python interpreters: ", nbaddi
658 for i in range(nbaddi):
660 anInterp=InterpServer(args)
665 # -----------------------------------------------------------------------------
667 def useSalome(args, modules_list, modules_root_dir):
669 Launch all SALOME servers requested by args,
670 save list of process, give info to user,
671 show registered objects in Naming Service.
676 clt = startSalome(args, modules_list, modules_root_dir)
679 traceback.print_exc()
682 print "--- erreur au lancement Salome ---"
686 from killSalomeWithPort import getPiDict
687 filedict = getPiDict(args['port'])
691 fpid=open(filedict, 'r')
692 process_ids=pickle.load(fpid)
697 fpid=open(filedict, 'w')
698 process_ids.append(process_id)
699 pickle.dump(process_ids,fpid)
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 # Impression arborescence Naming Service
722 print " --- registered objects tree in Naming Service ---"
727 # -----------------------------------------------------------------------------
729 def registerEnv(args, modules_list, modules_root_dir):
731 Register args, modules_list, modules_root_dir in a file
732 for further use, when SALOME is launched embedded in an other application.
734 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
735 + '_' + args['appname'].upper() + '_env'
736 fenv=open(fileEnv,'w')
737 pickle.dump((args, modules_list, modules_root_dir),fenv)
739 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
741 # -----------------------------------------------------------------------------
744 """Salome Launch, when embedded in other application"""
745 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
746 fenv=open(fileEnv,'r')
747 args, modules_list, modules_root_dir = pickle.load(fenv)
750 clt = useSalome(args, modules_list, modules_root_dir)
753 # -----------------------------------------------------------------------------
756 """Salome launch as a main application"""
757 args, modules_list, modules_root_dir = get_config()
759 set_env(args, modules_list, modules_root_dir)
760 clt = useSalome(args, modules_list, modules_root_dir)
763 # -----------------------------------------------------------------------------
765 if __name__ == "__main__":