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 module_root_dir = modules_root_dir[module]
110 modules_root_dir_list[:0] = [module_root_dir]
111 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
113 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
115 if os.path.exists(module_root_dir + "/examples") :
116 add_path(os.path.join(module_root_dir,"examples"),
118 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
120 add_path(os.path.join(module_root_dir,"lib",
121 python_version,"site-packages",salome_subdir),
123 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
125 add_path(os.path.join(module_root_dir,"lib",
126 python_version,"site-packages",salome_subdir,
130 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
132 # set trace environment variable
134 if not os.environ.has_key("SALOME_trace"):
135 os.environ["SALOME_trace"]="local"
137 os.environ["SALOME_trace"]="file:"+args['file'][0]
139 os.environ["SALOME_trace"]="with_logger"
141 # set environment for SMESH plugins
143 if "SMESH" in modules_list:
144 os.environ["SMESH_MeshersList"]="StdMeshers"
145 if not os.environ.has_key("SALOME_StdMeshersResources"):
146 os.environ["SALOME_StdMeshersResources"] \
147 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
149 if args.has_key("SMESH_plugins"):
150 for plugin in args["SMESH_plugins"]:
151 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
152 os.environ["SMESH_MeshersList"] \
153 = os.environ["SMESH_MeshersList"]+":"+plugin
154 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
155 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
156 os.environ["SALOME_"+plugin+"Resources"] \
157 = plugin_root+"/share/"+args["appname"]+"/resources"
158 add_path(os.path.join(plugin_root,"lib",python_version,
159 "site-packages",salome_subdir),
161 add_path(os.path.join(plugin_root,"lib",salome_subdir),
163 add_path(os.path.join(plugin_root,"lib",salome_subdir),
165 add_path(os.path.join(plugin_root,"bin",salome_subdir),
167 add_path(os.path.join(plugin_root,"bin",salome_subdir),
172 # set environment for SUPERV module
173 os.environ["ENABLE_MACRO_NODE"]="1"
174 # set resources variables if not yet set
175 if os.getenv("GUI_ROOT_DIR"):
176 if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
177 if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
180 os.environ["CSF_PluginDefaults"] \
181 = os.path.join(modules_root_dir["KERNEL"],"share",
182 salome_subdir,"resources")
183 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
184 = os.path.join(modules_root_dir["KERNEL"],"share",
185 salome_subdir,"resources")
187 if "GEOM" in modules_list:
188 print "GEOM OCAF Resources"
189 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
190 = os.path.join(modules_root_dir["GEOM"],"share",
191 salome_subdir,"resources")
192 print "GEOM Shape Healing Resources"
193 os.environ["CSF_ShHealingDefaults"] \
194 = os.path.join(modules_root_dir["GEOM"],"share",
195 salome_subdir,"resources")
197 # -----------------------------------------------------------------------------
199 from killSalome import killAllPorts
203 kill servers from a previous SALOME exection, if needed,
204 on the CORBA port given in args of runSalome
207 from killSalomeWithPort import killMyPort
208 my_port=str(args['port'])
212 print "problem in killLocalPort()"
216 def givenPortKill(port):
218 kill servers from a previous SALOME exection, if needed,
219 on the same CORBA port
222 from killSalomeWithPort import killMyPort
227 print "problem in LocalPortKill(), killMyPort("<<port<<")"
231 def kill_salome(args):
233 Kill servers from previous SALOME executions, if needed;
234 depending on args 'killall' or 'portkill', kill all executions,
235 or only execution on the same CORBA port
240 elif args['portkill']:
241 givenPortKill(str(args['port']))
243 # -----------------------------------------------------------------------------
245 # Definition des classes d'objets pour le lancement des Server CORBA
249 """Generic class for CORBA server launch"""
254 if self.args['xterm']:
255 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
257 def __init__(self,args):
265 if self.args['xterm']:
266 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
267 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
268 + os.getenv("LD_LIBRARY_PATH")]
269 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
270 command = myargs + self.CMD
271 print "command = ", command
272 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
273 process_id[pid]=self.CMD
276 class InterpServer(Server):
277 def __init__(self,args):
279 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
280 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
281 #self.CMD=['xterm', '-e', 'python']
286 #print "command = ", command
287 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
288 process_id[pid]=self.CMD
292 class CatalogServer(Server):
293 def __init__(self,args):
296 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
298 home_dir=os.getenv('HOME')
299 if home_dir is not None:
300 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
302 def setpath(self,modules_list,modules_root_dir):
304 list_modules = modules_list[:]
305 list_modules.reverse()
306 for module in ["KERNEL", "GUI"] + list_modules:
307 module_root_dir=modules_root_dir[module]
308 module_cata=module+"Catalog.xml"
309 #print " ", module_cata
311 glob.glob(os.path.join(module_root_dir,
312 "share",salome_subdir,
313 "resources",module_cata)))
314 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
318 class SalomeDSServer(Server):
319 def __init__(self,args):
322 self.CMD=['SALOMEDS_Server']
326 class RegistryServer(Server):
327 def __init__(self,args):
330 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
334 class ContainerCPPServer(Server):
335 def __init__(self,args):
338 self.CMD=['SALOME_Container','FactoryServer']
342 class ContainerPYServer(Server):
343 def __init__(self,args):
346 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
350 class ContainerSUPERVServer(Server):
351 def __init__(self,args):
354 self.CMD=['SALOME_Container','SuperVisionContainer']
358 class LoggerServer(Server):
359 def __init__(self,args):
362 self.CMD=['SALOME_Logger_Server', 'logger.log']
366 class SessionServer(Server):
367 def __init__(self,args):
370 self.SCMD1=['SALOME_Session_Server']
372 if 'registry' in self.args['embedded']:
373 self.SCMD1+=['--with','Registry',
374 '(','--salome_session','theSession',')']
375 if 'moduleCatalog' in self.args['embedded']:
376 self.SCMD1+=['--with','ModuleCatalog','(','-common']
377 home_dir=os.getenv('HOME')
378 if home_dir is not None:
379 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
381 if 'study' in self.args['embedded']:
382 self.SCMD2+=['--with','SALOMEDS','(',')']
383 if 'cppContainer' in self.args['embedded']:
384 self.SCMD2+=['--with','Container','(','FactoryServer',')']
385 if 'SalomeAppEngine' in self.args['embedded']:
386 self.SCMD2+=['--with','SalomeAppEngine','(',')']
388 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
390 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
392 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
393 self.SCMD2+=['SUPERV']
396 if self.args['splash']:
397 self.SCMD2+=['SPLASH']
399 def setpath(self,modules_list,modules_root_dir):
401 list_modules = modules_list[:]
402 list_modules.reverse()
403 for module in ["KERNEL", "GUI"] + list_modules:
404 module_root_dir=modules_root_dir[module]
405 module_cata=module+"Catalog.xml"
406 #print " ", module_cata
408 glob.glob(os.path.join(module_root_dir,"share",
409 salome_subdir,"resources",
411 if 'moduleCatalog' in self.args['embedded']:
412 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
414 self.CMD=self.SCMD1 + self.SCMD2
418 class ContainerManagerServer(Server):
419 def __init__(self,args):
422 self.SCMD1=['SALOME_ContainerManagerServer']
424 if 'registry' in self.args['embedded']:
425 self.SCMD1+=['--with','Registry',
426 '(','--salome_session','theSession',')']
427 if 'moduleCatalog' in self.args['embedded']:
428 self.SCMD1+=['--with','ModuleCatalog','(','-common']
429 self.SCMD2+=['-personal',
430 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
431 if 'study' in self.args['embedded']:
432 self.SCMD2+=['--with','SALOMEDS','(',')']
433 if 'cppContainer' in self.args['embedded']:
434 self.SCMD2+=['--with','Container','(','FactoryServer',')']
436 def setpath(self,modules_list,modules_root_dir):
438 list_modules = modules_list[:]
439 list_modules.reverse()
440 for module in ["KERNEL", "GUI"] + list_modules:
441 module_root_dir=modules_root_dir[module]
442 module_cata=module+"Catalog.xml"
443 #print " ", module_cata
445 glob.glob(os.path.join(module_root_dir,"share",
446 self.args['appname'],"resources",
448 if 'moduleCatalog' in self.args['embedded']:
449 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
451 self.CMD=self.SCMD1 + self.SCMD2
453 class NotifyServer(Server):
454 def __init__(self,args,modules_root_dir):
457 self.modules_root_dir=modules_root_dir
458 myLogName = os.environ["LOGNAME"]
459 self.CMD=['notifd','-c',
460 self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
461 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
462 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
463 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
464 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
468 # -----------------------------------------------------------------------------
471 """Salome Session Graphic User Interface activation"""
473 import SALOME_Session_idl
474 session=clt.waitNS("/Kernel/Session",SALOME.Session)
475 session.GetInterface()
477 # -----------------------------------------------------------------------------
479 def startSalome(args, modules_list, modules_root_dir):
480 """Launch all SALOME servers requested by args"""
481 init_time = os.times()
483 print "startSalome ", args
486 # Initialisation ORB et Naming Service
489 clt=orbmodule.client()
491 # (non obligatoire) Lancement Logger Server
492 # et attente de sa disponibilite dans le naming service
496 myServer=LoggerServer(args)
498 clt.waitLogger("Logger")
500 # Notify Server launch
503 print "Notify Server to launch"
505 myServer=NotifyServer(args,modules_root_dir)
509 # Lancement Registry Server,
510 # attente de la disponibilite du Registry dans le Naming Service
513 if 'registry' not in args['embedded']:
514 myServer=RegistryServer(args)
516 clt.waitNS("/Registry")
519 # Lancement Catalog Server,
520 # attente de la disponibilite du Catalog Server dans le Naming Service
524 if 'moduleCatalog' not in args['embedded']:
525 cataServer=CatalogServer(args)
526 cataServer.setpath(modules_list,modules_root_dir)
528 import SALOME_ModuleCatalog
529 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
532 # Lancement SalomeDS Server,
533 # attente de la disponibilite du SalomeDS dans le Naming Service
536 #print "ARGS = ",args
537 if 'study' not in args['embedded']:
539 myServer=SalomeDSServer(args)
541 clt.waitNS("/myStudyManager")
544 # Lancement ContainerManagerServer
547 myCmServer = ContainerManagerServer(args)
548 myCmServer.setpath(modules_list,modules_root_dir)
552 from Utils_Identity import getShortHostName
554 if os.getenv("HOSTNAME") == None:
555 if os.getenv("HOST") == None:
556 os.environ["HOSTNAME"]=getShortHostName()
558 os.environ["HOSTNAME"]=os.getenv("HOST")
560 theComputer = getShortHostName()
563 # Lancement Container C++ local,
564 # attente de la disponibilite du Container C++ local dans le Naming Service
567 if 'cppContainer' in args['standalone']:
568 myServer=ContainerCPPServer(args)
570 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
573 # Lancement Container Python local,
574 # attente de la disponibilite du Container Python local
575 # dans le Naming Service
578 if 'pyContainer' in args['standalone']:
579 myServer=ContainerPYServer(args)
581 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
584 # Lancement Container Supervision local,
585 # attente de la disponibilite du Container Supervision local
586 # dans le Naming Service
589 if 'supervContainer' in args['standalone']:
590 myServer=ContainerSUPERVServer(args)
592 clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
595 # Lancement Session Server
597 mySessionServ = SessionServer(args)
598 mySessionServ.setpath(modules_list,modules_root_dir)
602 # Attente de la disponibilite du Session Server dans le Naming Service
606 import SALOME_Session_idl
607 session=clt.waitNS("/Kernel/Session",SALOME.Session)
609 end_time = os.times()
611 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
614 # ASV start GUI without Loader
616 # session.GetInterface()
619 # additionnal external python interpreters
626 nbaddi = int(args['interp'][0])
629 traceback.print_exc()
630 print "-------------------------------------------------------------"
631 print "-- to get an external python interpreter:runSalome --interp=1"
632 print "-------------------------------------------------------------"
634 print "additional external python interpreters: ", nbaddi
636 for i in range(nbaddi):
638 anInterp=InterpServer(args)
643 # -----------------------------------------------------------------------------
645 def useSalome(args, modules_list, modules_root_dir):
647 Launch all SALOME servers requested by args,
648 save list of process, give info to user,
649 show registered objects in Naming Service.
654 clt = startSalome(args, modules_list, modules_root_dir)
657 traceback.print_exc()
660 print "--- erreur au lancement Salome ---"
664 from killSalomeWithPort import getPiDict
665 filedict = getPiDict(args['port'])
669 fpid=open(filedict, 'r')
670 process_ids=pickle.load(fpid)
675 fpid=open(filedict, 'w')
676 process_ids.append(process_id)
677 pickle.dump(process_ids,fpid)
681 Saving of the dictionary of Salome processes in %s
682 To kill SALOME processes from a console (kill all sessions from all ports):
684 To kill SALOME from the present interpreter, if it is not closed :
685 killLocalPort() --> kill this session
686 (use CORBA port from args of runSalome)
687 givenPortKill(port) --> kill a specific session with given CORBA port
688 killAllPorts() --> kill all sessions
690 runSalome, with --killall option, starts with killing
691 the processes resulting from the previous execution.
695 # Impression arborescence Naming Service
700 print " --- registered objects tree in Naming Service ---"
705 # -----------------------------------------------------------------------------
707 def registerEnv(args, modules_list, modules_root_dir):
709 Register args, modules_list, modules_root_dir in a file
710 for further use, when SALOME is launched embedded in an other application.
712 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
713 + '_' + args['appname'].upper() + '_env'
714 fenv=open(fileEnv,'w')
715 pickle.dump((args, modules_list, modules_root_dir),fenv)
717 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
719 # -----------------------------------------------------------------------------
722 """Salome Launch, when embedded in other application"""
723 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
724 fenv=open(fileEnv,'r')
725 args, modules_list, modules_root_dir = pickle.load(fenv)
728 clt = useSalome(args, modules_list, modules_root_dir)
731 # -----------------------------------------------------------------------------
734 """Salome launch as a main application"""
735 args, modules_list, modules_root_dir = get_config()
737 set_env(args, modules_list, modules_root_dir)
738 clt = useSalome(args, modules_list, modules_root_dir)
741 # -----------------------------------------------------------------------------
743 if __name__ == "__main__":