3 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
4 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import sys, os, string, glob, time, pickle
27 # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc.
28 # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used.
29 # but after - 'appname' = "SalomeApp", so using it in making the subdirectory is an error.
30 salome_subdir = "salome"
32 # -----------------------------------------------------------------------------
34 def add_path(directory, variable_name):
35 """Function helper to add environment variables"""
36 if not os.environ.has_key(variable_name):
37 os.environ[variable_name] = ""
39 if os.path.exists(directory):
41 for _dir in os.environ[variable_name].split(":"):
42 if os.path.exists(_dir):
43 if not os.path.samefile(_dir, directory):
46 if os.path.abspath(_dir) != os.path.abspath(directory):
50 newpath[:0] = [ directory ]
51 newpath = string.join(newpath,":")
52 os.environ[variable_name] = newpath
53 if variable_name == "PYTHONPATH":
54 sys.path[:0] = [directory]
56 # -----------------------------------------------------------------------------
60 Get list of modules, paths.
62 Read args from launch configure xml file and command line options.
63 Check variables <module>_ROOT_DIR and set list of used modules.
64 Return args, modules_list, modules_root_dir
67 # read args from launch configure xml file and command line options
69 import launchConfigureParser
70 args = launchConfigureParser.args
72 # Check variables <module>_ROOT_DIR
73 # and set list of used modules (without KERNEL)
76 if args.has_key("modules"):
77 modules_list += args["modules"]
78 # KERNEL must be last in the list to locate it at the first place in PATH
80 modules_list[:0] = ["GUI"]
81 modules_list[:0] = ["KERNEL"]
82 modules_list.reverse()
87 for module in modules_list :
88 module_variable=module+"_ROOT_DIR"
89 if not os.environ.has_key(module_variable):
90 print "*******************************************************"
92 print "* Environment variable",module_variable,"must be set"
93 print "* Module", module, "will be not available"
95 print "********************************************************"
96 to_remove_list.append(module)
99 module_root_dir = os.environ[module_variable]
100 modules_root_dir[module]=module_root_dir
102 for to_remove in to_remove_list:
103 modules_list.remove(to_remove)
105 while "KERNEL" in modules_list:
106 modules_list.remove("KERNEL")
109 while "GUI" in modules_list:
110 modules_list.remove("GUI")
113 if "SUPERV" in modules_list and not 'superv' in args['standalone']:
114 args['standalone'].append("superv")
117 return args, modules_list, modules_root_dir
119 # -----------------------------------------------------------------------------
121 def set_env(args, modules_list, modules_root_dir):
122 """Add to the PATH-variables modules specific paths"""
124 python_version="python%d.%d" % sys.version_info[0:2]
125 modules_root_dir_list = []
127 modules_list = modules_list[:] + ["GUI"]
128 modules_list = modules_list[:] + ["KERNEL"]
129 for module in modules_list :
130 if modules_root_dir.has_key(module):
131 module_root_dir = modules_root_dir[module]
132 modules_root_dir_list[:0] = [module_root_dir]
133 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
135 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
137 if os.path.exists(module_root_dir + "/examples") :
138 add_path(os.path.join(module_root_dir,"examples"),
141 add_path(os.path.join(module_root_dir,"bin",salome_subdir),
143 add_path(os.path.join(module_root_dir,"lib",
144 python_version,"site-packages",
147 add_path(os.path.join(module_root_dir,"lib",salome_subdir),
149 add_path(os.path.join(module_root_dir,"lib",
150 python_version,"site-packages",
158 os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
160 # set trace environment variable
162 if not os.environ.has_key("SALOME_trace"):
163 os.environ["SALOME_trace"]="local"
165 os.environ["SALOME_trace"]="file:"+args['file'][0]
167 os.environ["SALOME_trace"]="with_logger"
169 # set environment for SMESH plugins
171 if "SMESH" in modules_list:
172 os.environ["SMESH_MeshersList"]="StdMeshers"
173 if not os.environ.has_key("SALOME_StdMeshersResources"):
174 os.environ["SALOME_StdMeshersResources"] \
175 = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
177 if args.has_key("SMESH_plugins"):
178 for plugin in args["SMESH_plugins"]:
180 if os.environ.has_key(plugin+"_ROOT_DIR"):
181 plugin_root = os.environ[plugin+"_ROOT_DIR"]
183 # workaround to avoid modifications of existing environment
184 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
185 plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
188 if plugin_root != "":
189 os.environ["SMESH_MeshersList"] \
190 = os.environ["SMESH_MeshersList"]+":"+plugin
191 if not os.environ.has_key("SALOME_"+plugin+"Resources"):
192 os.environ["SALOME_"+plugin+"Resources"] \
193 = plugin_root+"/share/"+args["appname"]+"/resources"
194 add_path(os.path.join(plugin_root,"lib",python_version,
195 "site-packages",salome_subdir),
197 add_path(os.path.join(plugin_root,"lib",salome_subdir),
199 add_path(os.path.join(plugin_root,"lib",salome_subdir),
201 add_path(os.path.join(plugin_root,"bin",salome_subdir),
203 add_path(os.path.join(plugin_root,"bin",salome_subdir),
208 # set environment for SUPERV module
209 os.environ["ENABLE_MACRO_NODE"]="1"
210 # set resources variables if not yet set
211 # Done now by launchConfigureParser.py
212 #if os.getenv("GUI_ROOT_DIR"):
213 #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
214 #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
216 # set CSF_PluginDefaults variable only if it is not customized
218 if not os.getenv("CSF_PluginDefaults"):
219 os.environ["CSF_PluginDefaults"] \
220 = os.path.join(modules_root_dir["KERNEL"],"share",
221 salome_subdir,"resources")
222 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
223 = os.path.join(modules_root_dir["KERNEL"],"share",
224 salome_subdir,"resources")
226 if "GEOM" in modules_list:
227 print "GEOM OCAF Resources"
228 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
229 = os.path.join(modules_root_dir["GEOM"],"share",
230 salome_subdir,"resources")
231 print "GEOM Shape Healing Resources"
232 os.environ["CSF_ShHealingDefaults"] \
233 = os.path.join(modules_root_dir["GEOM"],"share",
234 salome_subdir,"resources")
236 # -----------------------------------------------------------------------------
238 from killSalome import killAllPorts
242 kill servers from a previous SALOME exection, if needed,
243 on the CORBA port given in args of runSalome
246 from killSalomeWithPort import killMyPort
247 my_port=str(args['port'])
251 print "problem in killLocalPort()"
255 def givenPortKill(port):
257 kill servers from a previous SALOME exection, if needed,
258 on the same CORBA port
261 from killSalomeWithPort import killMyPort
266 print "problem in LocalPortKill(), killMyPort("<<port<<")"
270 def kill_salome(args):
272 Kill servers from previous SALOME executions, if needed;
273 depending on args 'killall' or 'portkill', kill all executions,
274 or only execution on the same CORBA port
279 elif args['portkill']:
280 givenPortKill(str(args['port']))
282 # -----------------------------------------------------------------------------
284 # Definition des classes d'objets pour le lancement des Server CORBA
288 """Generic class for CORBA server launch"""
294 if self.args['xterm']:
295 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
297 def __init__(self,args):
305 if self.args['xterm']:
306 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
307 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
308 + os.getenv("LD_LIBRARY_PATH")]
309 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
310 command = myargs + self.CMD
311 print "command = ", command
312 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
313 process_id[pid]=self.CMD
317 class InterpServer(Server):
318 def __init__(self,args):
320 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
321 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
322 #self.CMD=['xterm', '-e', 'python']
327 #print "command = ", command
328 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
329 process_id[pid]=self.CMD
334 class CatalogServer(Server):
335 def __init__(self,args):
338 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
340 home_dir=os.getenv('HOME')
341 if home_dir is not None:
342 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
344 def setpath(self,modules_list,modules_root_dir):
346 list_modules = modules_list[:]
347 list_modules.reverse()
348 if self.args["gui"] :
349 list_modules = ["KERNEL", "GUI"] + list_modules
351 list_modules = ["KERNEL"] + list_modules
352 for module in list_modules:
353 if modules_root_dir.has_key(module):
354 module_root_dir=modules_root_dir[module]
355 module_cata=module+"Catalog.xml"
356 #print " ", module_cata
358 glob.glob(os.path.join(module_root_dir,
359 "share",salome_subdir,
360 "resources",module_cata)))
363 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
367 class SalomeDSServer(Server):
368 def __init__(self,args):
371 self.CMD=['SALOMEDS_Server']
375 class RegistryServer(Server):
376 def __init__(self,args):
379 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
383 class ContainerCPPServer(Server):
384 def __init__(self,args):
387 self.CMD=['SALOME_Container','FactoryServer']
391 class ContainerPYServer(Server):
392 def __init__(self,args):
395 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
399 class ContainerSUPERVServer(Server):
400 def __init__(self,args):
403 self.CMD=['SALOME_Container','SuperVisionContainer']
407 class LoggerServer(Server):
408 def __init__(self,args):
411 self.CMD=['SALOME_Logger_Server', 'logger.log']
415 class SessionServer(Server):
416 def __init__(self,args):
417 self.args = args.copy()
418 # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
422 self.SCMD1=['SALOME_Session_Server']
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 home_dir=os.getenv('HOME')
430 if home_dir is not None:
431 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
433 if 'study' in self.args['embedded']:
434 self.SCMD2+=['--with','SALOMEDS','(',')']
435 if 'cppContainer' in self.args['embedded']:
436 self.SCMD2+=['--with','Container','(','FactoryServer',')']
437 if 'SalomeAppEngine' in self.args['embedded']:
438 self.SCMD2+=['--with','SalomeAppEngine','(',')']
440 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
442 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
444 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
445 self.SCMD2+=['SUPERV']
448 if self.args['splash'] and self.args['gui']:
449 self.SCMD2+=['SPLASH']
450 if self.args['noexcepthandler']:
451 self.SCMD2+=['noexcepthandler']
452 if self.args.has_key('modules'):
453 self.SCMD2+=['--modules (']
454 for mod in self.args['modules']:
455 self.SCMD2+=[mod + ':']
458 def setpath(self,modules_list,modules_root_dir):
460 list_modules = modules_list[:]
461 list_modules.reverse()
462 if self.args["gui"] :
463 list_modules = ["KERNEL", "GUI"] + list_modules
465 list_modules = ["KERNEL"] + list_modules
466 for module in list_modules:
467 module_root_dir=modules_root_dir[module]
468 module_cata=module+"Catalog.xml"
469 #print " ", module_cata
471 glob.glob(os.path.join(module_root_dir,"share",
472 salome_subdir,"resources",
474 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
475 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
477 self.CMD=self.SCMD1 + self.SCMD2
481 class ContainerManagerServer(Server):
482 def __init__(self,args):
485 self.SCMD1=['SALOME_ContainerManagerServer']
488 if 'registry' in self.args['embedded']:
489 self.SCMD1+=['--with','Registry',
490 '(','--salome_session','theSession',')']
491 if 'moduleCatalog' in self.args['embedded']:
492 self.SCMD1+=['--with','ModuleCatalog','(','-common']
493 self.SCMD2+=['-personal',
494 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
495 if 'study' in self.args['embedded']:
496 self.SCMD2+=['--with','SALOMEDS','(',')']
497 if 'cppContainer' in self.args['embedded']:
498 self.SCMD2+=['--with','Container','(','FactoryServer',')']
500 def setpath(self,modules_list,modules_root_dir):
502 list_modules = modules_list[:]
503 list_modules.reverse()
504 if self.args["gui"] :
505 list_modules = ["GUI"] + list_modules
506 for module in ["KERNEL"] + list_modules:
507 if modules_root_dir.has_key(module):
508 module_root_dir=modules_root_dir[module]
509 module_cata=module+"Catalog.xml"
510 #print " ", module_cata
512 glob.glob(os.path.join(module_root_dir,"share",
513 self.args['appname'],"resources",
517 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
518 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
520 self.CMD=self.SCMD1 + self.SCMD2
522 class NotifyServer(Server):
523 def __init__(self,args,modules_root_dir):
526 self.modules_root_dir=modules_root_dir
527 myLogName = os.environ["LOGNAME"]
528 self.CMD=['notifd','-c',
529 self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
530 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
531 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
532 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
533 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
537 # -----------------------------------------------------------------------------
540 """Salome Session Graphic User Interface activation"""
544 import SALOME_ModuleCatalog
548 import SALOME_Session_idl
549 session=clt.waitNS("/Kernel/Session",SALOME.Session)
550 session.GetInterface()
552 # -----------------------------------------------------------------------------
554 def startSalome(args, modules_list, modules_root_dir):
555 """Launch all SALOME servers requested by args"""
556 init_time = os.times()
558 print "startSalome ", args
561 # Initialisation ORB et Naming Service
564 clt=orbmodule.client()
566 # (non obligatoire) Lancement Logger Server
567 # et attente de sa disponibilite dans le naming service
571 myServer=LoggerServer(args)
573 clt.waitLogger("Logger")
575 # Notify Server launch
578 print "Notify Server to launch"
580 myServer=NotifyServer(args,modules_root_dir)
583 # Lancement Session Server (to show splash ASAP)
587 mySessionServ = SessionServer(args)
588 mySessionServ.setpath(modules_list,modules_root_dir)
592 # Lancement Registry Server,
593 # attente de la disponibilite du Registry dans le Naming Service
596 if ('registry' not in args['embedded']) | (args["gui"] == 0) :
597 myServer=RegistryServer(args)
599 clt.waitNSPID("/Registry",myServer.PID)
602 # Lancement Catalog Server,
603 # attente de la disponibilite du Catalog Server dans le Naming Service
607 if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
608 cataServer=CatalogServer(args)
609 cataServer.setpath(modules_list,modules_root_dir)
611 import SALOME_ModuleCatalog
612 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
615 # Lancement SalomeDS Server,
616 # attente de la disponibilite du SalomeDS dans le Naming Service
619 #print "ARGS = ",args
620 if ('study' not in args['embedded']) | (args["gui"] == 0):
622 myServer=SalomeDSServer(args)
624 clt.waitNSPID("/myStudyManager",myServer.PID)
627 # Lancement ContainerManagerServer
630 myCmServer = ContainerManagerServer(args)
631 myCmServer.setpath(modules_list,modules_root_dir)
635 from Utils_Identity import getShortHostName
637 if os.getenv("HOSTNAME") == None:
638 if os.getenv("HOST") == None:
639 os.environ["HOSTNAME"]=getShortHostName()
641 os.environ["HOSTNAME"]=os.getenv("HOST")
643 theComputer = getShortHostName()
646 # Lancement Container C++ local,
647 # attente de la disponibilite du Container C++ local dans le Naming Service
650 if 'cppContainer' in args['standalone']:
651 myServer=ContainerCPPServer(args)
653 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
656 # Lancement Container Python local,
657 # attente de la disponibilite du Container Python local
658 # dans le Naming Service
661 if 'pyContainer' in args['standalone']:
662 myServer=ContainerPYServer(args)
664 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
667 # Lancement Container Supervision local,
668 # attente de la disponibilite du Container Supervision local
669 # dans le Naming Service
672 if 'supervContainer' in args['standalone']:
673 myServer=ContainerSUPERVServer(args)
675 clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
678 # Attente de la disponibilite du Session Server dans le Naming Service
686 import SALOME_ModuleCatalog
690 import SALOME_Session_idl
691 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
693 end_time = os.times()
695 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
698 # ASV start GUI without Loader
700 # session.GetInterface()
703 # additionnal external python interpreters
710 nbaddi = int(args['interp'][0])
713 traceback.print_exc()
714 print "-------------------------------------------------------------"
715 print "-- to get an external python interpreter:runSalome --interp=1"
716 print "-------------------------------------------------------------"
718 print "additional external python interpreters: ", nbaddi
720 for i in range(nbaddi):
722 anInterp=InterpServer(args)
727 # -----------------------------------------------------------------------------
729 def useSalome(args, modules_list, modules_root_dir):
731 Launch all SALOME servers requested by args,
732 save list of process, give info to user,
733 show registered objects in Naming Service.
738 clt = startSalome(args, modules_list, modules_root_dir)
741 traceback.print_exc()
744 print "--- erreur au lancement Salome ---"
748 from killSalomeWithPort import getPiDict
749 filedict = getPiDict(args['port'])
753 fpid=open(filedict, 'r')
754 process_ids=pickle.load(fpid)
759 fpid=open(filedict, 'w')
760 process_ids.append(process_id)
761 pickle.dump(process_ids,fpid)
765 Saving of the dictionary of Salome processes in %s
766 To kill SALOME processes from a console (kill all sessions from all ports):
768 To kill SALOME from the present interpreter, if it is not closed :
769 killLocalPort() --> kill this session
770 (use CORBA port from args of runSalome)
771 givenPortKill(port) --> kill a specific session with given CORBA port
772 killAllPorts() --> kill all sessions
774 runSalome, with --killall option, starts with killing
775 the processes resulting from the previous execution.
779 # Impression arborescence Naming Service
784 print " --- registered objects tree in Naming Service ---"
789 # -----------------------------------------------------------------------------
791 def registerEnv(args, modules_list, modules_root_dir):
793 Register args, modules_list, modules_root_dir in a file
794 for further use, when SALOME is launched embedded in an other application.
796 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
797 + '_' + args['appname'].upper() + '_env'
798 fenv=open(fileEnv,'w')
799 pickle.dump((args, modules_list, modules_root_dir),fenv)
801 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
803 # -----------------------------------------------------------------------------
806 """Salome Launch, when embedded in other application"""
807 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
808 fenv=open(fileEnv,'r')
809 args, modules_list, modules_root_dir = pickle.load(fenv)
812 clt = useSalome(args, modules_list, modules_root_dir)
815 # -----------------------------------------------------------------------------
818 """Salome launch as a main application"""
819 args, modules_list, modules_root_dir = get_config()
821 set_env(args, modules_list, modules_root_dir)
822 clt = useSalome(args, modules_list, modules_root_dir)
825 # -----------------------------------------------------------------------------
827 if __name__ == "__main__":