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
61 modules_list[:0] = ["GUI"]
62 modules_list[:0] = ["KERNEL"]
63 modules_list.reverse()
68 for module in modules_list :
69 module_variable=module+"_ROOT_DIR"
70 if not os.environ.has_key(module_variable):
71 print "*******************************************************"
73 print "* Environment variable",module_variable,"must be set"
74 print "* Module", module, "will be not available"
76 print "********************************************************"
77 to_remove_list.append(module)
80 module_root_dir = os.environ[module_variable]
81 modules_root_dir[module]=module_root_dir
83 for to_remove in to_remove_list:
84 modules_list.remove(to_remove)
86 while "KERNEL" in modules_list:
87 modules_list.remove("KERNEL")
90 while "GUI" in modules_list:
91 modules_list.remove("GUI")
94 if "SUPERV" in modules_list and not 'superv' in args['standalone']:
95 args['standalone'].append("superv")
98 return args, modules_list, modules_root_dir
100 # -----------------------------------------------------------------------------
102 def set_env(args, modules_list, modules_root_dir):
103 """Add to the PATH-variables modules specific paths"""
105 python_version="python%d.%d" % sys.version_info[0:2]
106 modules_root_dir_list = []
108 modules_list = modules_list[:] + ["GUI"]
109 modules_list = modules_list[:] + ["KERNEL"]
110 for module in modules_list :
111 if modules_root_dir.has_key(module):
112 module_root_dir = modules_root_dir[module]
113 modules_root_dir_list[:0] = [module_root_dir]
114 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
116 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
118 if os.path.exists(module_root_dir + "/examples") :
119 add_path(os.path.join(module_root_dir,"examples"),
122 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
124 add_path(os.path.join(module_root_dir,"lib",
125 python_version,"site-packages",
128 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
130 add_path(os.path.join(module_root_dir,"lib",
131 python_version,"site-packages",
139 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
141 # set trace environment variable
143 if not os.environ.has_key("SALOME_trace"):
144 os.environ["SALOME_trace"]="local"
146 os.environ["SALOME_trace"]="file:"+args['file'][0]
148 os.environ["SALOME_trace"]="with_logger"
150 # set environment for SMESH plugins
152 if "SMESH" in modules_list:
153 os.environ["SMESH_MeshersList"]="StdMeshers"
154 if not os.environ.has_key("SALOME_StdMeshersResources"):
155 os.environ["SALOME_StdMeshersResources"] \
156 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
158 if args.has_key("SMESH_plugins"):
159 for plugin in args["SMESH_plugins"]:
161 if os.environ.has_key(plugin+"_ROOT_DIR"):
162 plugin_root = os.environ[plugin+"_ROOT_DIR"]
164 # workaround to avoid modifications of existing environment
165 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
166 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
169 if plugin_root != "":
170 os.environ["SMESH_MeshersList"] \
171 = os.environ["SMESH_MeshersList"]+":"+plugin
172 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
173 os.environ["SALOME_"+plugin+"Resources"] \
174 = plugin_root+"/share/"+args["appname"]+"/resources"
175 add_path(os.path.join(plugin_root,"lib",python_version,
176 "site-packages",salome_subdir),
178 add_path(os.path.join(plugin_root,"lib",salome_subdir),
180 add_path(os.path.join(plugin_root,"lib",salome_subdir),
182 add_path(os.path.join(plugin_root,"bin",salome_subdir),
184 add_path(os.path.join(plugin_root,"bin",salome_subdir),
189 # set environment for SUPERV module
190 os.environ["ENABLE_MACRO_NODE"]="1"
191 # set resources variables if not yet set
192 # Done now by launchConfigureParser.py
193 #if os.getenv("GUI_ROOT_DIR"):
194 #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
195 #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
197 # set CSF_PluginDefaults variable only if it is not customized
199 if not os.getenv("CSF_PluginDefaults"):
200 os.environ["CSF_PluginDefaults"] \
201 = os.path.join(modules_root_dir["KERNEL"],"share",
202 salome_subdir,"resources")
203 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
204 = os.path.join(modules_root_dir["KERNEL"],"share",
205 salome_subdir,"resources")
207 if "GEOM" in modules_list:
208 print "GEOM OCAF Resources"
209 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
210 = os.path.join(modules_root_dir["GEOM"],"share",
211 salome_subdir,"resources")
212 print "GEOM Shape Healing Resources"
213 os.environ["CSF_ShHealingDefaults"] \
214 = os.path.join(modules_root_dir["GEOM"],"share",
215 salome_subdir,"resources")
217 # -----------------------------------------------------------------------------
219 from killSalome import killAllPorts
223 kill servers from a previous SALOME exection, if needed,
224 on the CORBA port given in args of runSalome
227 from killSalomeWithPort import killMyPort
228 my_port=str(args['port'])
232 print "problem in killLocalPort()"
236 def givenPortKill(port):
238 kill servers from a previous SALOME exection, if needed,
239 on the same CORBA port
242 from killSalomeWithPort import killMyPort
247 print "problem in LocalPortKill(), killMyPort("<<port<<")"
251 def kill_salome(args):
253 Kill servers from previous SALOME executions, if needed;
254 depending on args 'killall' or 'portkill', kill all executions,
255 or only execution on the same CORBA port
260 elif args['portkill']:
261 givenPortKill(str(args['port']))
263 # -----------------------------------------------------------------------------
265 # Definition des classes d'objets pour le lancement des Server CORBA
269 """Generic class for CORBA server launch"""
275 if self.args['xterm']:
276 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
278 def __init__(self,args):
286 if self.args['xterm']:
287 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
288 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
289 + os.getenv("LD_LIBRARY_PATH")]
290 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
291 command = myargs + self.CMD
292 print "command = ", command
293 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
294 process_id[pid]=self.CMD
298 class InterpServer(Server):
299 def __init__(self,args):
301 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
302 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
303 #self.CMD=['xterm', '-e', 'python']
308 #print "command = ", command
309 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
310 process_id[pid]=self.CMD
315 class CatalogServer(Server):
316 def __init__(self,args):
319 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
321 home_dir=os.getenv('HOME')
322 if home_dir is not None:
323 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
325 def setpath(self,modules_list,modules_root_dir):
327 list_modules = modules_list[:]
328 list_modules.reverse()
329 if self.args["gui"] :
330 list_modules = ["KERNEL", "GUI"] + list_modules
332 list_modules = ["KERNEL"] + list_modules
333 for module in list_modules:
334 if modules_root_dir.has_key(module):
335 module_root_dir=modules_root_dir[module]
336 module_cata=module+"Catalog.xml"
337 #print " ", module_cata
339 glob.glob(os.path.join(module_root_dir,
340 "share",salome_subdir,
341 "resources",module_cata)))
344 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
348 class SalomeDSServer(Server):
349 def __init__(self,args):
352 self.CMD=['SALOMEDS_Server']
356 class RegistryServer(Server):
357 def __init__(self,args):
360 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
364 class ContainerCPPServer(Server):
365 def __init__(self,args):
368 self.CMD=['SALOME_Container','FactoryServer']
372 class ContainerPYServer(Server):
373 def __init__(self,args):
376 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
380 class ContainerSUPERVServer(Server):
381 def __init__(self,args):
384 self.CMD=['SALOME_Container','SuperVisionContainer']
388 class LoggerServer(Server):
389 def __init__(self,args):
392 self.CMD=['SALOME_Logger_Server', 'logger.log']
396 class SessionServer(Server):
397 def __init__(self,args):
398 self.args = args.copy()
399 # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
403 self.SCMD1=['SALOME_Session_Server']
405 if 'registry' in self.args['embedded']:
406 self.SCMD1+=['--with','Registry',
407 '(','--salome_session','theSession',')']
408 if 'moduleCatalog' in self.args['embedded']:
409 self.SCMD1+=['--with','ModuleCatalog','(','-common']
410 home_dir=os.getenv('HOME')
411 if home_dir is not None:
412 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
414 if 'study' in self.args['embedded']:
415 self.SCMD2+=['--with','SALOMEDS','(',')']
416 if 'cppContainer' in self.args['embedded']:
417 self.SCMD2+=['--with','Container','(','FactoryServer',')']
418 if 'SalomeAppEngine' in self.args['embedded']:
419 self.SCMD2+=['--with','SalomeAppEngine','(',')']
421 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
423 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
425 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
426 self.SCMD2+=['SUPERV']
429 if self.args['splash'] and self.args['gui']:
430 self.SCMD2+=['SPLASH']
431 if self.args['noexcepthandler']:
432 self.SCMD2+=['noexcepthandler']
433 if self.args.has_key('modules'):
434 self.SCMD2+=['--modules (']
435 for mod in self.args['modules']:
436 self.SCMD2+=[mod + ':']
439 def setpath(self,modules_list,modules_root_dir):
441 list_modules = modules_list[:]
442 list_modules.reverse()
443 if self.args["gui"] :
444 list_modules = ["KERNEL", "GUI"] + list_modules
446 list_modules = ["KERNEL"] + list_modules
447 for module in list_modules:
448 module_root_dir=modules_root_dir[module]
449 module_cata=module+"Catalog.xml"
450 #print " ", module_cata
452 glob.glob(os.path.join(module_root_dir,"share",
453 salome_subdir,"resources",
455 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
456 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
458 self.CMD=self.SCMD1 + self.SCMD2
462 class ContainerManagerServer(Server):
463 def __init__(self,args):
466 self.SCMD1=['SALOME_ContainerManagerServer']
469 if 'registry' in self.args['embedded']:
470 self.SCMD1+=['--with','Registry',
471 '(','--salome_session','theSession',')']
472 if 'moduleCatalog' in self.args['embedded']:
473 self.SCMD1+=['--with','ModuleCatalog','(','-common']
474 self.SCMD2+=['-personal',
475 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
476 if 'study' in self.args['embedded']:
477 self.SCMD2+=['--with','SALOMEDS','(',')']
478 if 'cppContainer' in self.args['embedded']:
479 self.SCMD2+=['--with','Container','(','FactoryServer',')']
481 def setpath(self,modules_list,modules_root_dir):
483 list_modules = modules_list[:]
484 list_modules.reverse()
485 if self.args["gui"] :
486 list_modules = ["GUI"] + list_modules
487 for module in ["KERNEL"] + list_modules:
488 if modules_root_dir.has_key(module):
489 module_root_dir=modules_root_dir[module]
490 module_cata=module+"Catalog.xml"
491 #print " ", module_cata
493 glob.glob(os.path.join(module_root_dir,"share",
494 self.args['appname'],"resources",
498 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
499 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
501 self.CMD=self.SCMD1 + self.SCMD2
503 class NotifyServer(Server):
504 def __init__(self,args,modules_root_dir):
507 self.modules_root_dir=modules_root_dir
508 myLogName = os.environ["LOGNAME"]
509 self.CMD=['notifd','-c',
510 self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
511 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
512 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
513 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
514 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
518 # -----------------------------------------------------------------------------
521 """Salome Session Graphic User Interface activation"""
525 import SALOME_ModuleCatalog
529 import SALOME_Session_idl
530 session=clt.waitNS("/Kernel/Session",SALOME.Session)
531 session.GetInterface()
533 # -----------------------------------------------------------------------------
535 def startSalome(args, modules_list, modules_root_dir):
536 """Launch all SALOME servers requested by args"""
537 init_time = os.times()
539 print "startSalome ", args
542 # Initialisation ORB et Naming Service
545 clt=orbmodule.client()
547 # (non obligatoire) Lancement Logger Server
548 # et attente de sa disponibilite dans le naming service
552 myServer=LoggerServer(args)
554 clt.waitLogger("Logger")
556 # Notify Server launch
559 print "Notify Server to launch"
561 myServer=NotifyServer(args,modules_root_dir)
564 # Lancement Session Server (to show splash ASAP)
568 mySessionServ = SessionServer(args)
569 mySessionServ.setpath(modules_list,modules_root_dir)
573 # Lancement Registry Server,
574 # attente de la disponibilite du Registry dans le Naming Service
577 if ('registry' not in args['embedded']) | (args["gui"] == 0) :
578 myServer=RegistryServer(args)
580 clt.waitNSPID("/Registry",myServer.PID)
583 # Lancement Catalog Server,
584 # attente de la disponibilite du Catalog Server dans le Naming Service
588 if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
589 cataServer=CatalogServer(args)
590 cataServer.setpath(modules_list,modules_root_dir)
592 import SALOME_ModuleCatalog
593 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
596 # Lancement SalomeDS Server,
597 # attente de la disponibilite du SalomeDS dans le Naming Service
600 #print "ARGS = ",args
601 if ('study' not in args['embedded']) | (args["gui"] == 0):
603 myServer=SalomeDSServer(args)
605 clt.waitNSPID("/myStudyManager",myServer.PID)
608 # Lancement ContainerManagerServer
611 myCmServer = ContainerManagerServer(args)
612 myCmServer.setpath(modules_list,modules_root_dir)
616 from Utils_Identity import getShortHostName
618 if os.getenv("HOSTNAME") == None:
619 if os.getenv("HOST") == None:
620 os.environ["HOSTNAME"]=getShortHostName()
622 os.environ["HOSTNAME"]=os.getenv("HOST")
624 theComputer = getShortHostName()
627 # Lancement Container C++ local,
628 # attente de la disponibilite du Container C++ local dans le Naming Service
631 if 'cppContainer' in args['standalone']:
632 myServer=ContainerCPPServer(args)
634 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
637 # Lancement Container Python local,
638 # attente de la disponibilite du Container Python local
639 # dans le Naming Service
642 if 'pyContainer' in args['standalone']:
643 myServer=ContainerPYServer(args)
645 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
648 # Lancement Container Supervision local,
649 # attente de la disponibilite du Container Supervision local
650 # dans le Naming Service
653 if 'supervContainer' in args['standalone']:
654 myServer=ContainerSUPERVServer(args)
656 clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
659 # Attente de la disponibilite du Session Server dans le Naming Service
667 import SALOME_ModuleCatalog
671 import SALOME_Session_idl
672 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
674 end_time = os.times()
676 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
679 # ASV start GUI without Loader
681 # session.GetInterface()
684 # additionnal external python interpreters
691 nbaddi = int(args['interp'][0])
694 traceback.print_exc()
695 print "-------------------------------------------------------------"
696 print "-- to get an external python interpreter:runSalome --interp=1"
697 print "-------------------------------------------------------------"
699 print "additional external python interpreters: ", nbaddi
701 for i in range(nbaddi):
703 anInterp=InterpServer(args)
708 # -----------------------------------------------------------------------------
710 def useSalome(args, modules_list, modules_root_dir):
712 Launch all SALOME servers requested by args,
713 save list of process, give info to user,
714 show registered objects in Naming Service.
719 clt = startSalome(args, modules_list, modules_root_dir)
722 traceback.print_exc()
725 print "--- erreur au lancement Salome ---"
729 from killSalomeWithPort import getPiDict
730 filedict = getPiDict(args['port'])
734 fpid=open(filedict, 'r')
735 process_ids=pickle.load(fpid)
740 fpid=open(filedict, 'w')
741 process_ids.append(process_id)
742 pickle.dump(process_ids,fpid)
746 Saving of the dictionary of Salome processes in %s
747 To kill SALOME processes from a console (kill all sessions from all ports):
749 To kill SALOME from the present interpreter, if it is not closed :
750 killLocalPort() --> kill this session
751 (use CORBA port from args of runSalome)
752 givenPortKill(port) --> kill a specific session with given CORBA port
753 killAllPorts() --> kill all sessions
755 runSalome, with --killall option, starts with killing
756 the processes resulting from the previous execution.
760 # Impression arborescence Naming Service
765 print " --- registered objects tree in Naming Service ---"
770 # -----------------------------------------------------------------------------
772 def registerEnv(args, modules_list, modules_root_dir):
774 Register args, modules_list, modules_root_dir in a file
775 for further use, when SALOME is launched embedded in an other application.
777 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
778 + '_' + args['appname'].upper() + '_env'
779 fenv=open(fileEnv,'w')
780 pickle.dump((args, modules_list, modules_root_dir),fenv)
782 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
784 # -----------------------------------------------------------------------------
787 """Salome Launch, when embedded in other application"""
788 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
789 fenv=open(fileEnv,'r')
790 args, modules_list, modules_root_dir = pickle.load(fenv)
793 clt = useSalome(args, modules_list, modules_root_dir)
796 # -----------------------------------------------------------------------------
799 """Salome launch as a main application"""
800 args, modules_list, modules_root_dir = get_config()
802 set_env(args, modules_list, modules_root_dir)
803 clt = useSalome(args, modules_list, modules_root_dir)
806 # -----------------------------------------------------------------------------
808 if __name__ == "__main__":