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+"_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"]:
159 if os.environ.has_key(plugin+"_ROOT_DIR"):
160 plugin_root = os.environ[plugin+"_ROOT_DIR"]
162 # workaround to avoid modifications of existing environment
163 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
164 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
167 if plugin_root != "":
168 os.environ["SMESH_MeshersList"] \
169 = os.environ["SMESH_MeshersList"]+":"+plugin
170 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
171 os.environ["SALOME_"+plugin+"Resources"] \
172 = plugin_root+"/share/"+args["appname"]+"/resources"
173 add_path(os.path.join(plugin_root,"lib",python_version,
174 "site-packages",salome_subdir),
176 add_path(os.path.join(plugin_root,"lib",salome_subdir),
178 add_path(os.path.join(plugin_root,"lib",salome_subdir),
180 add_path(os.path.join(plugin_root,"bin",salome_subdir),
182 add_path(os.path.join(plugin_root,"bin",salome_subdir),
187 # set environment for SUPERV module
188 os.environ["ENABLE_MACRO_NODE"]="1"
189 # set resources variables if not yet set
190 if os.getenv("GUI_ROOT_DIR"):
191 if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
192 if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
195 # set CSF_PluginDefaults variable only if it is not customized
197 if not os.getenv("CSF_PluginDefaults"):
198 os.environ["CSF_PluginDefaults"] \
199 = os.path.join(modules_root_dir["KERNEL"],"share",
200 salome_subdir,"resources")
201 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
202 = os.path.join(modules_root_dir["KERNEL"],"share",
203 salome_subdir,"resources")
205 if "GEOM" in modules_list:
206 print "GEOM OCAF Resources"
207 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
208 = os.path.join(modules_root_dir["GEOM"],"share",
209 salome_subdir,"resources")
210 print "GEOM Shape Healing Resources"
211 os.environ["CSF_ShHealingDefaults"] \
212 = os.path.join(modules_root_dir["GEOM"],"share",
213 salome_subdir,"resources")
215 # -----------------------------------------------------------------------------
217 from killSalome import killAllPorts
221 kill servers from a previous SALOME exection, if needed,
222 on the CORBA port given in args of runSalome
225 from killSalomeWithPort import killMyPort
226 my_port=str(args['port'])
230 print "problem in killLocalPort()"
234 def givenPortKill(port):
236 kill servers from a previous SALOME exection, if needed,
237 on the same CORBA port
240 from killSalomeWithPort import killMyPort
245 print "problem in LocalPortKill(), killMyPort("<<port<<")"
249 def kill_salome(args):
251 Kill servers from previous SALOME executions, if needed;
252 depending on args 'killall' or 'portkill', kill all executions,
253 or only execution on the same CORBA port
258 elif args['portkill']:
259 givenPortKill(str(args['port']))
261 # -----------------------------------------------------------------------------
263 # Definition des classes d'objets pour le lancement des Server CORBA
267 """Generic class for CORBA server launch"""
273 if self.args['xterm']:
274 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
276 def __init__(self,args):
284 if self.args['xterm']:
285 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
286 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
287 + os.getenv("LD_LIBRARY_PATH")]
288 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
289 command = myargs + self.CMD
290 print "command = ", command
291 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
292 process_id[pid]=self.CMD
296 class InterpServer(Server):
297 def __init__(self,args):
299 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
300 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
301 #self.CMD=['xterm', '-e', 'python']
306 #print "command = ", command
307 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
308 process_id[pid]=self.CMD
313 class CatalogServer(Server):
314 def __init__(self,args):
317 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
319 home_dir=os.getenv('HOME')
320 if home_dir is not None:
321 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
323 def setpath(self,modules_list,modules_root_dir):
325 list_modules = modules_list[:]
326 list_modules.reverse()
327 for module in ["KERNEL", "GUI"] + list_modules:
328 if modules_root_dir.has_key(module):
329 module_root_dir=modules_root_dir[module]
330 module_cata=module+"Catalog.xml"
331 #print " ", module_cata
333 glob.glob(os.path.join(module_root_dir,
334 "share",salome_subdir,
335 "resources",module_cata)))
338 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
342 class SalomeDSServer(Server):
343 def __init__(self,args):
346 self.CMD=['SALOMEDS_Server']
350 class RegistryServer(Server):
351 def __init__(self,args):
354 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
358 class ContainerCPPServer(Server):
359 def __init__(self,args):
362 self.CMD=['SALOME_Container','FactoryServer']
366 class ContainerPYServer(Server):
367 def __init__(self,args):
370 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
374 class ContainerSUPERVServer(Server):
375 def __init__(self,args):
378 self.CMD=['SALOME_Container','SuperVisionContainer']
382 class LoggerServer(Server):
383 def __init__(self,args):
386 self.CMD=['SALOME_Logger_Server', 'logger.log']
390 class SessionServer(Server):
391 def __init__(self,args):
394 self.SCMD1=['SALOME_Session_Server']
396 if 'registry' in self.args['embedded']:
397 self.SCMD1+=['--with','Registry',
398 '(','--salome_session','theSession',')']
399 if 'moduleCatalog' in self.args['embedded']:
400 self.SCMD1+=['--with','ModuleCatalog','(','-common']
401 home_dir=os.getenv('HOME')
402 if home_dir is not None:
403 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
405 if 'study' in self.args['embedded']:
406 self.SCMD2+=['--with','SALOMEDS','(',')']
407 if 'cppContainer' in self.args['embedded']:
408 self.SCMD2+=['--with','Container','(','FactoryServer',')']
409 if 'SalomeAppEngine' in self.args['embedded']:
410 self.SCMD2+=['--with','SalomeAppEngine','(',')']
412 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
414 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
416 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
417 self.SCMD2+=['SUPERV']
420 if self.args['splash']:
421 self.SCMD2+=['SPLASH']
422 if self.args['noexcepthandler']:
423 self.SCMD2+=['noexcepthandler']
424 if self.args.has_key('modules'):
425 self.SCMD2+=['--modules (']
426 for mod in self.args['modules']:
427 self.SCMD2+=[mod + ':']
430 def setpath(self,modules_list,modules_root_dir):
432 list_modules = modules_list[:]
433 list_modules.reverse()
434 for module in ["KERNEL", "GUI"] + list_modules:
435 module_root_dir=modules_root_dir[module]
436 module_cata=module+"Catalog.xml"
437 #print " ", module_cata
439 glob.glob(os.path.join(module_root_dir,"share",
440 salome_subdir,"resources",
442 if 'moduleCatalog' in self.args['embedded']:
443 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
445 self.CMD=self.SCMD1 + self.SCMD2
449 class ContainerManagerServer(Server):
450 def __init__(self,args):
453 self.SCMD1=['SALOME_ContainerManagerServer']
455 if 'registry' in self.args['embedded']:
456 self.SCMD1+=['--with','Registry',
457 '(','--salome_session','theSession',')']
458 if 'moduleCatalog' in self.args['embedded']:
459 self.SCMD1+=['--with','ModuleCatalog','(','-common']
460 self.SCMD2+=['-personal',
461 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
462 if 'study' in self.args['embedded']:
463 self.SCMD2+=['--with','SALOMEDS','(',')']
464 if 'cppContainer' in self.args['embedded']:
465 self.SCMD2+=['--with','Container','(','FactoryServer',')']
467 def setpath(self,modules_list,modules_root_dir):
469 list_modules = modules_list[:]
470 list_modules.reverse()
471 for module in ["KERNEL", "GUI"] + list_modules:
472 if modules_root_dir.has_key(module):
473 module_root_dir=modules_root_dir[module]
474 module_cata=module+"Catalog.xml"
475 #print " ", module_cata
477 glob.glob(os.path.join(module_root_dir,"share",
478 self.args['appname'],"resources",
482 if 'moduleCatalog' in self.args['embedded']:
483 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
485 self.CMD=self.SCMD1 + self.SCMD2
487 class NotifyServer(Server):
488 def __init__(self,args,modules_root_dir):
491 self.modules_root_dir=modules_root_dir
492 myLogName = os.environ["LOGNAME"]
493 self.CMD=['notifd','-c',
494 self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
495 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
496 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
497 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
498 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
502 # -----------------------------------------------------------------------------
505 """Salome Session Graphic User Interface activation"""
507 import SALOME_Session_idl
508 session=clt.waitNS("/Kernel/Session",SALOME.Session)
509 session.GetInterface()
511 # -----------------------------------------------------------------------------
513 def startSalome(args, modules_list, modules_root_dir):
514 """Launch all SALOME servers requested by args"""
515 init_time = os.times()
517 print "startSalome ", args
520 # Initialisation ORB et Naming Service
523 clt=orbmodule.client()
525 # (non obligatoire) Lancement Logger Server
526 # et attente de sa disponibilite dans le naming service
530 myServer=LoggerServer(args)
532 clt.waitLogger("Logger")
534 # Notify Server launch
537 print "Notify Server to launch"
539 myServer=NotifyServer(args,modules_root_dir)
543 # Lancement Registry Server,
544 # attente de la disponibilite du Registry dans le Naming Service
547 if 'registry' not in args['embedded']:
548 myServer=RegistryServer(args)
550 clt.waitNSPID("/Registry",myServer.PID)
553 # Lancement Catalog Server,
554 # attente de la disponibilite du Catalog Server dans le Naming Service
558 if 'moduleCatalog' not in args['embedded']:
559 cataServer=CatalogServer(args)
560 cataServer.setpath(modules_list,modules_root_dir)
562 import SALOME_ModuleCatalog
563 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
566 # Lancement SalomeDS Server,
567 # attente de la disponibilite du SalomeDS dans le Naming Service
570 #print "ARGS = ",args
571 if 'study' not in args['embedded']:
573 myServer=SalomeDSServer(args)
575 clt.waitNSPID("/myStudyManager",myServer.PID)
578 # Lancement ContainerManagerServer
581 myCmServer = ContainerManagerServer(args)
582 myCmServer.setpath(modules_list,modules_root_dir)
586 from Utils_Identity import getShortHostName
588 if os.getenv("HOSTNAME") == None:
589 if os.getenv("HOST") == None:
590 os.environ["HOSTNAME"]=getShortHostName()
592 os.environ["HOSTNAME"]=os.getenv("HOST")
594 theComputer = getShortHostName()
597 # Lancement Container C++ local,
598 # attente de la disponibilite du Container C++ local dans le Naming Service
601 if 'cppContainer' in args['standalone']:
602 myServer=ContainerCPPServer(args)
604 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
607 # Lancement Container Python local,
608 # attente de la disponibilite du Container Python local
609 # dans le Naming Service
612 if 'pyContainer' in args['standalone']:
613 myServer=ContainerPYServer(args)
615 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
618 # Lancement Container Supervision local,
619 # attente de la disponibilite du Container Supervision local
620 # dans le Naming Service
623 if 'supervContainer' in args['standalone']:
624 myServer=ContainerSUPERVServer(args)
626 clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
629 # Lancement Session Server
632 mySessionServ = SessionServer(args)
633 mySessionServ.setpath(modules_list,modules_root_dir)
637 # Attente de la disponibilite du Session Server dans le Naming Service
641 import SALOME_Session_idl
642 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
644 end_time = os.times()
646 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
649 # ASV start GUI without Loader
651 # session.GetInterface()
654 # additionnal external python interpreters
661 nbaddi = int(args['interp'][0])
664 traceback.print_exc()
665 print "-------------------------------------------------------------"
666 print "-- to get an external python interpreter:runSalome --interp=1"
667 print "-------------------------------------------------------------"
669 print "additional external python interpreters: ", nbaddi
671 for i in range(nbaddi):
673 anInterp=InterpServer(args)
678 # -----------------------------------------------------------------------------
680 def useSalome(args, modules_list, modules_root_dir):
682 Launch all SALOME servers requested by args,
683 save list of process, give info to user,
684 show registered objects in Naming Service.
689 clt = startSalome(args, modules_list, modules_root_dir)
692 traceback.print_exc()
695 print "--- erreur au lancement Salome ---"
699 from killSalomeWithPort import getPiDict
700 filedict = getPiDict(args['port'])
704 fpid=open(filedict, 'r')
705 process_ids=pickle.load(fpid)
710 fpid=open(filedict, 'w')
711 process_ids.append(process_id)
712 pickle.dump(process_ids,fpid)
716 Saving of the dictionary of Salome processes in %s
717 To kill SALOME processes from a console (kill all sessions from all ports):
719 To kill SALOME from the present interpreter, if it is not closed :
720 killLocalPort() --> kill this session
721 (use CORBA port from args of runSalome)
722 givenPortKill(port) --> kill a specific session with given CORBA port
723 killAllPorts() --> kill all sessions
725 runSalome, with --killall option, starts with killing
726 the processes resulting from the previous execution.
730 # Impression arborescence Naming Service
735 print " --- registered objects tree in Naming Service ---"
740 # -----------------------------------------------------------------------------
742 def registerEnv(args, modules_list, modules_root_dir):
744 Register args, modules_list, modules_root_dir in a file
745 for further use, when SALOME is launched embedded in an other application.
747 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
748 + '_' + args['appname'].upper() + '_env'
749 fenv=open(fileEnv,'w')
750 pickle.dump((args, modules_list, modules_root_dir),fenv)
752 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
754 # -----------------------------------------------------------------------------
757 """Salome Launch, when embedded in other application"""
758 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
759 fenv=open(fileEnv,'r')
760 args, modules_list, modules_root_dir = pickle.load(fenv)
763 clt = useSalome(args, modules_list, modules_root_dir)
766 # -----------------------------------------------------------------------------
769 """Salome launch as a main application"""
770 args, modules_list, modules_root_dir = get_config()
772 set_env(args, modules_list, modules_root_dir)
773 clt = useSalome(args, modules_list, modules_root_dir)
776 # -----------------------------------------------------------------------------
778 if __name__ == "__main__":