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/kernel, 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/smesh"
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/"+plugin.lower()
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("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"
215 # set CSF_PluginDefaults variable only if it is not customized
217 if not os.getenv("CSF_PluginDefaults"):
218 os.environ["CSF_PluginDefaults"] \
219 = os.path.join(modules_root_dir["KERNEL"],"share",
220 salome_subdir,"resources","kernel")
221 os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
222 = os.path.join(modules_root_dir["KERNEL"],"share",
223 salome_subdir,"resources","kernel")
225 if "GEOM" in modules_list:
226 print "GEOM OCAF Resources"
227 os.environ["CSF_GEOMDS_ResourcesDefaults"] \
228 = os.path.join(modules_root_dir["GEOM"],"share",
229 salome_subdir,"resources","geom")
230 print "GEOM Shape Healing Resources"
231 os.environ["CSF_ShHealingDefaults"] \
232 = os.path.join(modules_root_dir["GEOM"],"share",
233 salome_subdir,"resources","geom")
235 # -----------------------------------------------------------------------------
237 from killSalome import killAllPorts
241 kill servers from a previous SALOME exection, if needed,
242 on the CORBA port given in args of runSalome
245 from killSalomeWithPort import killMyPort
246 my_port=str(args['port'])
250 print "problem in killLocalPort()"
254 def givenPortKill(port):
256 kill servers from a previous SALOME exection, if needed,
257 on the same CORBA port
260 from killSalomeWithPort import killMyPort
265 print "problem in LocalPortKill(), killMyPort("<<port<<")"
269 def kill_salome(args):
271 Kill servers from previous SALOME executions, if needed;
272 depending on args 'killall' or 'portkill', kill all executions,
273 or only execution on the same CORBA port
278 elif args['portkill']:
279 givenPortKill(str(args['port']))
281 # -----------------------------------------------------------------------------
283 # Definition des classes d'objets pour le lancement des Server CORBA
287 """Generic class for CORBA server launch"""
293 if self.args['xterm']:
294 self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
296 def __init__(self,args):
304 if self.args['xterm']:
305 # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
306 env_ld_library_path=['env', 'LD_LIBRARY_PATH='
307 + os.getenv("LD_LIBRARY_PATH")]
308 myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
309 command = myargs + self.CMD
310 print "command = ", command
311 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
312 process_id[pid]=self.CMD
316 class InterpServer(Server):
317 def __init__(self,args):
319 env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
320 self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
321 #self.CMD=['xterm', '-e', 'python']
326 #print "command = ", command
327 pid = os.spawnvp(os.P_NOWAIT, command[0], command)
328 process_id[pid]=self.CMD
333 class CatalogServer(Server):
334 def __init__(self,args):
337 self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
339 home_dir=os.getenv('HOME')
340 if home_dir is not None:
341 self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
343 def setpath(self,modules_list,modules_root_dir):
345 list_modules = modules_list[:]
346 list_modules.reverse()
347 if self.args["gui"] :
348 list_modules = ["KERNEL", "GUI"] + list_modules
350 list_modules = ["KERNEL"] + list_modules
351 for module in list_modules:
352 if modules_root_dir.has_key(module):
353 module_root_dir=modules_root_dir[module]
354 module_cata=module+"Catalog.xml"
355 #print " ", module_cata
356 if os.path.exists(os.path.join(module_root_dir,
357 "share",salome_subdir,
358 "resources",module.lower(),
361 glob.glob(os.path.join(module_root_dir,
362 "share",salome_subdir,
363 "resources",module.lower(),
367 glob.glob(os.path.join(module_root_dir,
368 "share",salome_subdir,
373 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
377 class SalomeDSServer(Server):
378 def __init__(self,args):
381 self.CMD=['SALOMEDS_Server']
385 class RegistryServer(Server):
386 def __init__(self,args):
389 self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
393 class ContainerCPPServer(Server):
394 def __init__(self,args):
397 self.CMD=['SALOME_Container','FactoryServer']
401 class ContainerPYServer(Server):
402 def __init__(self,args):
405 self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
409 class ContainerSUPERVServer(Server):
410 def __init__(self,args):
413 self.CMD=['SALOME_Container','SuperVisionContainer']
417 class LoggerServer(Server):
418 def __init__(self,args):
421 self.CMD=['SALOME_Logger_Server', 'logger.log']
425 class SessionServer(Server):
426 def __init__(self,args):
427 self.args = args.copy()
428 # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
432 self.SCMD1=['SALOME_Session_Server']
434 if 'registry' in self.args['embedded']:
435 self.SCMD1+=['--with','Registry',
436 '(','--salome_session','theSession',')']
437 if 'moduleCatalog' in self.args['embedded']:
438 self.SCMD1+=['--with','ModuleCatalog','(','-common']
439 home_dir=os.getenv('HOME')
440 if home_dir is not None:
441 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')]
443 if 'study' in self.args['embedded']:
444 self.SCMD2+=['--with','SALOMEDS','(',')']
445 if 'cppContainer' in self.args['embedded']:
446 self.SCMD2+=['--with','Container','(','FactoryServer',')']
447 if 'SalomeAppEngine' in self.args['embedded']:
448 self.SCMD2+=['--with','SalomeAppEngine','(',')']
450 if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
452 if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
454 if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
455 self.SCMD2+=['SUPERV']
458 if self.args['splash'] and self.args['gui']:
459 self.SCMD2+=['SPLASH']
460 if self.args['noexcepthandler']:
461 self.SCMD2+=['noexcepthandler']
462 if self.args.has_key('modules'):
463 self.SCMD2+=['--modules (']
464 for mod in self.args['modules']:
465 self.SCMD2+=[mod + ':']
468 def setpath(self,modules_list,modules_root_dir):
470 list_modules = modules_list[:]
471 list_modules.reverse()
472 if self.args["gui"] :
473 list_modules = ["KERNEL", "GUI"] + list_modules
475 list_modules = ["KERNEL"] + list_modules
476 for module in list_modules:
477 module_root_dir=modules_root_dir[module]
478 module_cata=module+"Catalog.xml"
479 #print " ", module_cata
480 if os.path.exists(os.path.join(module_root_dir,
481 "share",salome_subdir,
482 "resources",module.lower(),
485 glob.glob(os.path.join(module_root_dir,"share",
486 salome_subdir,"resources",
487 module.lower(),module_cata)))
490 glob.glob(os.path.join(module_root_dir,"share",
491 salome_subdir,"resources",
494 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
495 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
497 self.CMD=self.SCMD1 + self.SCMD2
501 class ContainerManagerServer(Server):
502 def __init__(self,args):
505 self.SCMD1=['SALOME_ContainerManagerServer']
508 if 'registry' in self.args['embedded']:
509 self.SCMD1+=['--with','Registry',
510 '(','--salome_session','theSession',')']
511 if 'moduleCatalog' in self.args['embedded']:
512 self.SCMD1+=['--with','ModuleCatalog','(','-common']
513 self.SCMD2+=['-personal',
514 '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
515 if 'study' in self.args['embedded']:
516 self.SCMD2+=['--with','SALOMEDS','(',')']
517 if 'cppContainer' in self.args['embedded']:
518 self.SCMD2+=['--with','Container','(','FactoryServer',')']
520 def setpath(self,modules_list,modules_root_dir):
522 list_modules = modules_list[:]
523 list_modules.reverse()
524 if self.args["gui"] :
525 list_modules = ["GUI"] + list_modules
526 for module in ["KERNEL"] + list_modules:
527 if modules_root_dir.has_key(module):
528 module_root_dir=modules_root_dir[module]
529 module_cata=module+"Catalog.xml"
530 #print " ", module_cata
531 if os.path.exists(os.path.join(module_root_dir,
532 "share",salome_subdir,
533 "resources",module.lower(),
536 glob.glob(os.path.join(module_root_dir,"share",
537 self.args['appname'],"resources",
538 module.lower(),module_cata)))
541 glob.glob(os.path.join(module_root_dir,"share",
542 self.args['appname'],"resources",
546 if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
547 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
549 self.CMD=self.SCMD1 + self.SCMD2
551 class NotifyServer(Server):
552 def __init__(self,args,modules_root_dir):
555 self.modules_root_dir=modules_root_dir
556 myLogName = os.environ["LOGNAME"]
557 self.CMD=['notifd','-c',
558 self.modules_root_dir["KERNEL"] +'/share/salome/resources/kernel/channel.cfg',
559 '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
560 '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
561 '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
562 '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
566 # -----------------------------------------------------------------------------
569 """Salome Session Graphic User Interface activation"""
573 import SALOME_ModuleCatalog
577 import SALOME_Session_idl
578 session=clt.waitNS("/Kernel/Session",SALOME.Session)
579 session.GetInterface()
581 # -----------------------------------------------------------------------------
583 def startSalome(args, modules_list, modules_root_dir):
584 """Launch all SALOME servers requested by args"""
585 init_time = os.times()
587 print "startSalome ", args
590 # Initialisation ORB et Naming Service
593 clt=orbmodule.client()
595 # (non obligatoire) Lancement Logger Server
596 # et attente de sa disponibilite dans le naming service
600 myServer=LoggerServer(args)
602 clt.waitLogger("Logger")
604 # Notify Server launch
607 print "Notify Server to launch"
609 myServer=NotifyServer(args,modules_root_dir)
612 # Lancement Session Server (to show splash ASAP)
616 mySessionServ = SessionServer(args)
617 mySessionServ.setpath(modules_list,modules_root_dir)
621 # Lancement Registry Server,
622 # attente de la disponibilite du Registry dans le Naming Service
625 if ('registry' not in args['embedded']) | (args["gui"] == 0) :
626 myServer=RegistryServer(args)
628 clt.waitNSPID("/Registry",myServer.PID)
631 # Lancement Catalog Server,
632 # attente de la disponibilite du Catalog Server dans le Naming Service
636 if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
637 cataServer=CatalogServer(args)
638 cataServer.setpath(modules_list,modules_root_dir)
640 import SALOME_ModuleCatalog
641 clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
644 # Lancement SalomeDS Server,
645 # attente de la disponibilite du SalomeDS dans le Naming Service
648 #print "ARGS = ",args
649 if ('study' not in args['embedded']) | (args["gui"] == 0):
651 myServer=SalomeDSServer(args)
653 clt.waitNSPID("/myStudyManager",myServer.PID)
656 # Lancement ContainerManagerServer
659 myCmServer = ContainerManagerServer(args)
660 myCmServer.setpath(modules_list,modules_root_dir)
664 from Utils_Identity import getShortHostName
666 if os.getenv("HOSTNAME") == None:
667 if os.getenv("HOST") == None:
668 os.environ["HOSTNAME"]=getShortHostName()
670 os.environ["HOSTNAME"]=os.getenv("HOST")
672 theComputer = getShortHostName()
675 # Lancement Container C++ local,
676 # attente de la disponibilite du Container C++ local dans le Naming Service
679 if 'cppContainer' in args['standalone']:
680 myServer=ContainerCPPServer(args)
682 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
685 # Lancement Container Python local,
686 # attente de la disponibilite du Container Python local
687 # dans le Naming Service
690 if 'pyContainer' in args['standalone']:
691 myServer=ContainerPYServer(args)
693 clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
696 # Lancement Container Supervision local,
697 # attente de la disponibilite du Container Supervision local
698 # dans le Naming Service
701 if 'supervContainer' in args['standalone']:
702 myServer=ContainerSUPERVServer(args)
704 clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
707 # Attente de la disponibilite du Session Server dans le Naming Service
715 import SALOME_ModuleCatalog
719 import SALOME_Session_idl
720 session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
722 end_time = os.times()
724 print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
727 # ASV start GUI without Loader
729 # session.GetInterface()
732 # additionnal external python interpreters
739 nbaddi = int(args['interp'][0])
742 traceback.print_exc()
743 print "-------------------------------------------------------------"
744 print "-- to get an external python interpreter:runSalome --interp=1"
745 print "-------------------------------------------------------------"
747 print "additional external python interpreters: ", nbaddi
749 for i in range(nbaddi):
751 anInterp=InterpServer(args)
756 # -----------------------------------------------------------------------------
758 def useSalome(args, modules_list, modules_root_dir):
760 Launch all SALOME servers requested by args,
761 save list of process, give info to user,
762 show registered objects in Naming Service.
767 clt = startSalome(args, modules_list, modules_root_dir)
770 traceback.print_exc()
773 print "--- erreur au lancement Salome ---"
777 from killSalomeWithPort import getPiDict
778 filedict = getPiDict(args['port'])
782 fpid=open(filedict, 'r')
783 process_ids=pickle.load(fpid)
788 fpid=open(filedict, 'w')
789 process_ids.append(process_id)
790 pickle.dump(process_ids,fpid)
794 Saving of the dictionary of Salome processes in %s
795 To kill SALOME processes from a console (kill all sessions from all ports):
797 To kill SALOME from the present interpreter, if it is not closed :
798 killLocalPort() --> kill this session
799 (use CORBA port from args of runSalome)
800 givenPortKill(port) --> kill a specific session with given CORBA port
801 killAllPorts() --> kill all sessions
803 runSalome, with --killall option, starts with killing
804 the processes resulting from the previous execution.
808 # Impression arborescence Naming Service
813 print " --- registered objects tree in Naming Service ---"
818 # -----------------------------------------------------------------------------
820 def registerEnv(args, modules_list, modules_root_dir):
822 Register args, modules_list, modules_root_dir in a file
823 for further use, when SALOME is launched embedded in an other application.
825 fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
826 + '_' + args['appname'].upper() + '_env'
827 fenv=open(fileEnv,'w')
828 pickle.dump((args, modules_list, modules_root_dir),fenv)
830 os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
832 # -----------------------------------------------------------------------------
835 """Salome Launch, when embedded in other application"""
836 fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
837 fenv=open(fileEnv,'r')
838 args, modules_list, modules_root_dir = pickle.load(fenv)
841 clt = useSalome(args, modules_list, modules_root_dir)
844 # -----------------------------------------------------------------------------
847 """Salome launch as a main application"""
848 args, modules_list, modules_root_dir = get_config()
850 set_env(args, modules_list, modules_root_dir)
851 clt = useSalome(args, modules_list, modules_root_dir)
854 # -----------------------------------------------------------------------------
856 if __name__ == "__main__":