Salome HOME
PR: mergefrom branch BR_V3_1_0_PR tag mergeto_trunk_02feb06
[modules/kernel.git] / bin / runSalome.py
1 #!/usr/bin/env python
2
3 import sys, os, string, glob, time, pickle
4 import orbmodule
5
6 process_id = {}
7
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"
12
13 # -----------------------------------------------------------------------------
14
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] = ""
19         pass
20     if os.path.exists(directory):
21         newpath=[]
22         for _dir in os.environ[variable_name].split(":"):
23             if os.path.exists(_dir):
24                 if not os.path.samefile(_dir, directory):
25                   newpath.append(_dir)
26             else:
27                 if os.path.abspath(_dir) != os.path.abspath(directory):
28                   newpath.append(_dir)
29             pass
30         import string
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]
36
37 # -----------------------------------------------------------------------------
38
39 def get_config():
40     """
41     Get list of modules, paths.
42     
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    
46     """
47     
48     # read args from launch configure xml file and command line options
49     
50     import launchConfigureParser
51     args = launchConfigureParser.args
52     
53     # Check variables <module>_ROOT_DIR
54     # and set list of used modules (without KERNEL)
55
56     modules_list = []
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()
63
64     modules_root_dir = {}
65
66     to_remove_list=[]
67     for module in modules_list :
68         module_variable=module+"_ROOT_DIR"
69         if not os.environ.has_key(module_variable):
70             print "*******************************************************"
71             print "*"
72             print "* Environment variable",module_variable,"must be set"
73             print "* Module", module, "will be not available"
74             print "*"
75             print "********************************************************"
76             to_remove_list.append(module)
77             continue
78             pass
79         module_root_dir = os.environ[module_variable]
80         modules_root_dir[module]=module_root_dir
81
82     for to_remove in to_remove_list:
83         modules_list.remove(to_remove)
84
85     while "KERNEL" in modules_list:
86         modules_list.remove("KERNEL")
87         pass
88
89     while "GUI" in modules_list:
90         modules_list.remove("GUI")
91         pass
92
93     if "SUPERV" in modules_list and not 'superv' in args['standalone']:
94         args['standalone'].append("superv")
95         pass
96    
97     return args, modules_list, modules_root_dir
98
99 # -----------------------------------------------------------------------------
100
101 def set_env(args, modules_list, modules_root_dir):
102     """Add to the PATH-variables modules specific paths"""
103     
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),
113                      "LD_LIBRARY_PATH")
114             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
115                      "PATH")
116             if os.path.exists(module_root_dir + "/examples") :
117                 add_path(os.path.join(module_root_dir,"examples"),
118                          "PYTHONPATH")
119                 pass
120             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
121                      "PYTHONPATH")
122             add_path(os.path.join(module_root_dir,"lib",
123                                   python_version,"site-packages",
124                                   salome_subdir),
125                      "PYTHONPATH")
126             add_path(os.path.join(module_root_dir,"lib",salome_subdir),
127                      "PYTHONPATH")
128             add_path(os.path.join(module_root_dir,"lib",
129                                   python_version,"site-packages",
130                                   salome_subdir,
131                                   "shared_modules"),
132                      "PYTHONPATH")
133             pass
134         pass
135
136
137     os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
138     
139     # set trace environment variable
140     
141     if not os.environ.has_key("SALOME_trace"):
142         os.environ["SALOME_trace"]="local"
143     if args['file']:
144         os.environ["SALOME_trace"]="file:"+args['file'][0]
145     if args['logger']:
146         os.environ["SALOME_trace"]="with_logger"
147
148     # set environment for SMESH plugins
149
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"
155             pass
156         if args.has_key("SMESH_plugins"):
157             for plugin in args["SMESH_plugins"]:
158                 plugin_root = ""
159                 if os.environ.has_key(plugin+"_ROOT_DIR"):
160                     plugin_root = os.environ[plugin+"_ROOT_DIR"]
161                 else:
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"]
165                         pass
166                     pass
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),
175                              "PYTHONPATH")
176                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
177                              "PYTHONPATH")
178                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
179                              "LD_LIBRARY_PATH")
180                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
181                              "PYTHONPATH")
182                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
183                              "PATH")
184             pass
185         pass
186
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"
193         pass   
194
195     # set CSF_PluginDefaults variable only if it is not customized
196     # by the user
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")
204
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")
214
215 # -----------------------------------------------------------------------------
216
217 from killSalome import killAllPorts
218
219 def killLocalPort():
220     """
221     kill servers from a previous SALOME exection, if needed,
222     on the CORBA port given in args of runSalome
223     """
224     
225     from killSalomeWithPort import killMyPort
226     my_port=str(args['port'])
227     try:
228         killMyPort(my_port)
229     except:
230         print "problem in killLocalPort()"
231         pass
232     pass
233     
234 def givenPortKill(port):
235     """
236     kill servers from a previous SALOME exection, if needed,
237     on the same CORBA port
238     """
239     
240     from killSalomeWithPort import killMyPort
241     my_port=port
242     try:
243         killMyPort(my_port)
244     except:
245         print "problem in LocalPortKill(), killMyPort("<<port<<")"
246         pass
247     pass
248
249 def kill_salome(args):
250     """
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
254     """
255
256     if args['killall']:
257         killAllPorts()
258     elif args['portkill']:
259         givenPortKill(str(args['port']))
260         
261 # -----------------------------------------------------------------------------
262 #
263 # Definition des classes d'objets pour le lancement des Server CORBA
264 #
265
266 class Server:
267     """Generic class for CORBA server launch"""
268
269     def initArgs(self):
270         self.PID=None
271         self.CMD=[]
272         self.ARGS=[]    
273         if self.args['xterm']:
274             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
275
276     def __init__(self,args):
277         self.args=args
278         self.initArgs()
279
280
281     def run(self):
282         global process_id
283         myargs=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
293         self.PID = pid
294
295
296 class InterpServer(Server):
297     def __init__(self,args):
298         self.args=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']
302        
303     def run(self):
304         global process_id
305         command = self.CMD
306         #print "command = ", command
307         pid = os.spawnvp(os.P_NOWAIT, command[0], command)
308         process_id[pid]=self.CMD
309         self.PID = pid
310
311 # ---
312
313 class CatalogServer(Server):
314     def __init__(self,args):
315         self.args=args
316         self.initArgs()
317         self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
318         self.SCMD2=[]
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')] 
322
323     def setpath(self,modules_list,modules_root_dir):
324         cata_path=[]
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
332                 cata_path.extend(
333                     glob.glob(os.path.join(module_root_dir,
334                                            "share",salome_subdir,
335                                            "resources",module_cata)))
336                 pass
337             pass
338         self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
339
340 # ---
341
342 class SalomeDSServer(Server):
343     def __init__(self,args):
344         self.args=args
345         self.initArgs()
346         self.CMD=['SALOMEDS_Server']
347
348 # ---
349
350 class RegistryServer(Server):
351     def __init__(self,args):
352         self.args=args
353         self.initArgs()
354         self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
355
356 # ---
357
358 class ContainerCPPServer(Server):
359     def __init__(self,args):
360         self.args=args
361         self.initArgs()
362         self.CMD=['SALOME_Container','FactoryServer']
363
364 # ---
365
366 class ContainerPYServer(Server):
367     def __init__(self,args):
368         self.args=args
369         self.initArgs()
370         self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
371
372 # ---
373
374 class ContainerSUPERVServer(Server):
375     def __init__(self,args):
376         self.args=args
377         self.initArgs()
378         self.CMD=['SALOME_Container','SuperVisionContainer']
379
380 # ---
381
382 class LoggerServer(Server):
383     def __init__(self,args):
384         self.args=args
385         self.initArgs()
386         self.CMD=['SALOME_Logger_Server', 'logger.log']
387
388 # ---
389
390 class SessionServer(Server):
391     def __init__(self,args):
392         self.args=args
393         self.initArgs()
394         self.SCMD1=['SALOME_Session_Server']
395         self.SCMD2=[]
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')] 
404             self.SCMD2+=[')']
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','(',')']
411             
412         if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
413             self.SCMD2+=['CPP']
414         if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
415             self.SCMD2+=['PY']
416         if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
417             self.SCMD2+=['SUPERV']
418         if self.args['gui']:
419             self.SCMD2+=['GUI']
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 + ':']
428             self.SCMD2+=[')']    
429
430     def setpath(self,modules_list,modules_root_dir):
431         cata_path=[]
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
438             cata_path.extend(
439                 glob.glob(os.path.join(module_root_dir,"share",
440                                        salome_subdir,"resources",
441                                        module_cata)))
442         if 'moduleCatalog' in self.args['embedded']:
443             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
444         else:
445             self.CMD=self.SCMD1 + self.SCMD2
446       
447 # ---
448
449 class ContainerManagerServer(Server):
450     def __init__(self,args):
451         self.args=args
452         self.initArgs()
453         self.SCMD1=['SALOME_ContainerManagerServer']
454         self.SCMD2=[]
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',')']
466         
467     def setpath(self,modules_list,modules_root_dir):
468         cata_path=[]
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
476                 cata_path.extend(
477                     glob.glob(os.path.join(module_root_dir,"share",
478                                            self.args['appname'],"resources",
479                                            module_cata)))
480                 pass
481             pass
482         if 'moduleCatalog' in self.args['embedded']:
483             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
484         else:
485             self.CMD=self.SCMD1 + self.SCMD2
486
487 class NotifyServer(Server):
488     def __init__(self,args,modules_root_dir):
489         self.args=args
490         self.initArgs()
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',
499                   ]
500
501 #
502 # -----------------------------------------------------------------------------
503
504 def startGUI():
505     """Salome Session Graphic User Interface activation"""
506     import SALOME
507     import SALOME_Session_idl
508     session=clt.waitNS("/Kernel/Session",SALOME.Session)
509     session.GetInterface()
510   
511 # -----------------------------------------------------------------------------
512
513 def startSalome(args, modules_list, modules_root_dir):
514     """Launch all SALOME servers requested by args"""
515     init_time = os.times()
516
517     print "startSalome ", args
518     
519     #
520     # Initialisation ORB et Naming Service
521     #
522    
523     clt=orbmodule.client()
524
525     # (non obligatoire) Lancement Logger Server
526     # et attente de sa disponibilite dans le naming service
527     #
528
529     if args['logger']:
530         myServer=LoggerServer(args)
531         myServer.run()
532         clt.waitLogger("Logger")
533
534     # Notify Server launch
535     #
536
537     print "Notify Server to launch"
538
539     myServer=NotifyServer(args,modules_root_dir)
540     myServer.run()
541
542     #
543     # Lancement Registry Server,
544     # attente de la disponibilite du Registry dans le Naming Service
545     #
546
547     if 'registry' not in args['embedded']:
548         myServer=RegistryServer(args)
549         myServer.run()
550         clt.waitNSPID("/Registry",myServer.PID)
551
552     #
553     # Lancement Catalog Server,
554     # attente de la disponibilite du Catalog Server dans le Naming Service
555     #
556     
557
558     if 'moduleCatalog' not in args['embedded']:
559         cataServer=CatalogServer(args)
560         cataServer.setpath(modules_list,modules_root_dir)
561         cataServer.run()
562         import SALOME_ModuleCatalog
563         clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
564
565     #
566     # Lancement SalomeDS Server,
567     # attente de la disponibilite du SalomeDS dans le Naming Service
568     #
569
570     #print "ARGS = ",args
571     if 'study' not in args['embedded']:
572         print "RunStudy"
573         myServer=SalomeDSServer(args)
574         myServer.run()
575         clt.waitNSPID("/myStudyManager",myServer.PID)
576
577     #
578     # Lancement ContainerManagerServer
579     #
580     
581     myCmServer = ContainerManagerServer(args)
582     myCmServer.setpath(modules_list,modules_root_dir)
583     myCmServer.run()
584
585
586     from Utils_Identity import getShortHostName
587     
588     if os.getenv("HOSTNAME") == None:
589         if os.getenv("HOST") == None:
590             os.environ["HOSTNAME"]=getShortHostName()
591         else:
592             os.environ["HOSTNAME"]=os.getenv("HOST")
593
594     theComputer = getShortHostName()
595     
596     #
597     # Lancement Container C++ local,
598     # attente de la disponibilite du Container C++ local dans le Naming Service
599     #
600
601     if 'cppContainer' in args['standalone']:
602         myServer=ContainerCPPServer(args)
603         myServer.run()
604         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
605
606     #
607     # Lancement Container Python local,
608     # attente de la disponibilite du Container Python local
609     # dans le Naming Service
610     #
611
612     if 'pyContainer' in args['standalone']:
613         myServer=ContainerPYServer(args)
614         myServer.run()
615         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
616
617     #
618     # Lancement Container Supervision local,
619     # attente de la disponibilite du Container Supervision local
620     # dans le Naming Service
621     #
622
623     if 'supervContainer' in args['standalone']:
624         myServer=ContainerSUPERVServer(args)
625         myServer.run()
626         clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
627
628     #
629     # Lancement Session Server
630     #
631
632     mySessionServ = SessionServer(args)
633     mySessionServ.setpath(modules_list,modules_root_dir)
634     mySessionServ.run()
635 ##----------------        
636
637     # Attente de la disponibilite du Session Server dans le Naming Service
638     #
639
640     import SALOME
641     import SALOME_Session_idl
642     session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
643
644     end_time = os.times()
645     print
646     print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
647                                                          - init_time[4])
648
649     # ASV start GUI without Loader
650     #if args['gui']:
651     #    session.GetInterface()
652
653     #
654     # additionnal external python interpreters
655     #
656     nbaddi=0
657     
658     try:
659         if 'interp' in args:
660             if args['interp']:
661                 nbaddi = int(args['interp'][0])
662     except:
663         import traceback
664         traceback.print_exc()
665         print "-------------------------------------------------------------"
666         print "-- to get an external python interpreter:runSalome --interp=1"
667         print "-------------------------------------------------------------"
668         
669     print "additional external python interpreters: ", nbaddi
670     if nbaddi:
671         for i in range(nbaddi):
672             print "i=",i
673             anInterp=InterpServer(args)
674             anInterp.run()
675     
676     return clt
677
678 # -----------------------------------------------------------------------------
679
680 def useSalome(args, modules_list, modules_root_dir):
681     """
682     Launch all SALOME servers requested by args,
683     save list of process, give info to user,
684     show registered objects in Naming Service.
685     """
686     
687     clt=None
688     try:
689         clt = startSalome(args, modules_list, modules_root_dir)
690     except:
691         import traceback
692         traceback.print_exc()
693         print
694         print
695         print "--- erreur au lancement Salome ---"
696         
697     #print process_id
698
699     from killSalomeWithPort import getPiDict
700     filedict = getPiDict(args['port'])
701
702     process_ids = []
703     try:
704         fpid=open(filedict, 'r')
705         process_ids=pickle.load(fpid)
706         fpid.close()
707     except:
708         pass
709     
710     fpid=open(filedict, 'w')
711     process_ids.append(process_id)
712     pickle.dump(process_ids,fpid)
713     fpid.close()
714     
715     print """
716     Saving of the dictionary of Salome processes in %s
717     To kill SALOME processes from a console (kill all sessions from all ports):
718       python killSalome.py 
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
724     
725     runSalome, with --killall option, starts with killing
726     the processes resulting from the previous execution.
727     """%filedict
728     
729     #
730     #  Impression arborescence Naming Service
731     #
732     
733     if clt != None:
734         print
735         print " --- registered objects tree in Naming Service ---"
736         clt.showNS()
737
738     return clt
739
740 # -----------------------------------------------------------------------------
741
742 def registerEnv(args, modules_list, modules_root_dir):
743     """
744     Register args, modules_list, modules_root_dir in a file
745     for further use, when SALOME is launched embedded in an other application.
746     """
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)
751     fenv.close()
752     os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
753
754 # -----------------------------------------------------------------------------
755
756 def no_main():
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)
761     fenv.close()
762     kill_salome(args)
763     clt = useSalome(args, modules_list, modules_root_dir)
764     return clt
765
766 # -----------------------------------------------------------------------------
767
768 def main():
769     """Salome launch as a main application"""
770     args, modules_list, modules_root_dir = get_config()
771     kill_salome(args)
772     set_env(args, modules_list, modules_root_dir)
773     clt = useSalome(args, modules_list, modules_root_dir)
774     return clt,args
775
776 # -----------------------------------------------------------------------------
777
778 if __name__ == "__main__":
779    import user
780    clt,args = main()