Salome HOME
PR: merge from branch BR_3_1_0deb tag mergeto_trunk_22dec05
[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.upper()+"_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                 if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
159                     os.environ["SMESH_MeshersList"] \
160                     = os.environ["SMESH_MeshersList"]+":"+plugin
161                     plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
162                     if not os.environ.has_key("SALOME_"+plugin+"Resources"):
163                         os.environ["SALOME_"+plugin+"Resources"] \
164                         = plugin_root+"/share/"+args["appname"]+"/resources"
165                     add_path(os.path.join(plugin_root,"lib",python_version,
166                                           "site-packages",salome_subdir),
167                              "PYTHONPATH")
168                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
169                              "PYTHONPATH")
170                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
171                              "LD_LIBRARY_PATH")
172                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
173                              "PYTHONPATH")
174                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
175                              "PATH")
176             pass
177         pass
178
179     # set environment for SUPERV module
180     os.environ["ENABLE_MACRO_NODE"]="1"
181     # set resources variables if not yet set
182     if os.getenv("GUI_ROOT_DIR"):
183         if not os.getenv("SUITRoot"): os.environ["SUITRoot"] =  os.getenv("GUI_ROOT_DIR") + "/share/salome"
184         if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] =  os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
185         pass   
186
187     # set CSF_PluginDefaults variable only if it is not customized
188     # by the user
189     if not os.getenv("CSF_PluginDefaults"):
190         os.environ["CSF_PluginDefaults"] \
191         = os.path.join(modules_root_dir["KERNEL"],"share",
192                        salome_subdir,"resources")
193     os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
194     = os.path.join(modules_root_dir["KERNEL"],"share",
195                    salome_subdir,"resources")
196
197     if "GEOM" in modules_list:
198         print "GEOM OCAF Resources"
199         os.environ["CSF_GEOMDS_ResourcesDefaults"] \
200         = os.path.join(modules_root_dir["GEOM"],"share",
201                        salome_subdir,"resources")
202         print "GEOM Shape Healing Resources"
203         os.environ["CSF_ShHealingDefaults"] \
204         = os.path.join(modules_root_dir["GEOM"],"share",
205                        salome_subdir,"resources")
206
207 # -----------------------------------------------------------------------------
208
209 from killSalome import killAllPorts
210
211 def killLocalPort():
212     """
213     kill servers from a previous SALOME exection, if needed,
214     on the CORBA port given in args of runSalome
215     """
216     
217     from killSalomeWithPort import killMyPort
218     my_port=str(args['port'])
219     try:
220         killMyPort(my_port)
221     except:
222         print "problem in killLocalPort()"
223         pass
224     pass
225     
226 def givenPortKill(port):
227     """
228     kill servers from a previous SALOME exection, if needed,
229     on the same CORBA port
230     """
231     
232     from killSalomeWithPort import killMyPort
233     my_port=port
234     try:
235         killMyPort(my_port)
236     except:
237         print "problem in LocalPortKill(), killMyPort("<<port<<")"
238         pass
239     pass
240
241 def kill_salome(args):
242     """
243     Kill servers from previous SALOME executions, if needed;
244     depending on args 'killall' or 'portkill', kill all executions,
245     or only execution on the same CORBA port
246     """
247
248     if args['killall']:
249         killAllPorts()
250     elif args['portkill']:
251         givenPortKill(str(args['port']))
252         
253 # -----------------------------------------------------------------------------
254 #
255 # Definition des classes d'objets pour le lancement des Server CORBA
256 #
257
258 class Server:
259     """Generic class for CORBA server launch"""
260
261     def initArgs(self):
262         self.PID=None
263         self.CMD=[]
264         self.ARGS=[]    
265         if self.args['xterm']:
266             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
267
268     def __init__(self,args):
269         self.args=args
270         self.initArgs()
271
272
273     def run(self):
274         global process_id
275         myargs=self.ARGS
276         if self.args['xterm']:
277             # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
278             env_ld_library_path=['env', 'LD_LIBRARY_PATH='
279                                  + os.getenv("LD_LIBRARY_PATH")]
280             myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
281         command = myargs + self.CMD
282         print "command = ", command
283         pid = os.spawnvp(os.P_NOWAIT, command[0], command)
284         process_id[pid]=self.CMD
285         self.PID = pid
286
287
288 class InterpServer(Server):
289     def __init__(self,args):
290         self.args=args
291         env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
292         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
293         #self.CMD=['xterm', '-e', 'python']
294        
295     def run(self):
296         global process_id
297         command = self.CMD
298         #print "command = ", command
299         pid = os.spawnvp(os.P_NOWAIT, command[0], command)
300         process_id[pid]=self.CMD
301         self.PID = pid
302
303 # ---
304
305 class CatalogServer(Server):
306     def __init__(self,args):
307         self.args=args
308         self.initArgs()
309         self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
310         self.SCMD2=[]
311         home_dir=os.getenv('HOME')
312         if home_dir is not None:
313             self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] 
314
315     def setpath(self,modules_list,modules_root_dir):
316         cata_path=[]
317         list_modules = modules_list[:]
318         list_modules.reverse()
319         for module in ["KERNEL", "GUI"] + list_modules:
320             if modules_root_dir.has_key(module):
321                 module_root_dir=modules_root_dir[module]
322                 module_cata=module+"Catalog.xml"
323                 #print "   ", module_cata
324                 cata_path.extend(
325                     glob.glob(os.path.join(module_root_dir,
326                                            "share",salome_subdir,
327                                            "resources",module_cata)))
328                 pass
329             pass
330         self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
331
332 # ---
333
334 class SalomeDSServer(Server):
335     def __init__(self,args):
336         self.args=args
337         self.initArgs()
338         self.CMD=['SALOMEDS_Server']
339
340 # ---
341
342 class RegistryServer(Server):
343     def __init__(self,args):
344         self.args=args
345         self.initArgs()
346         self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
347
348 # ---
349
350 class ContainerCPPServer(Server):
351     def __init__(self,args):
352         self.args=args
353         self.initArgs()
354         self.CMD=['SALOME_Container','FactoryServer']
355
356 # ---
357
358 class ContainerPYServer(Server):
359     def __init__(self,args):
360         self.args=args
361         self.initArgs()
362         self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
363
364 # ---
365
366 class ContainerSUPERVServer(Server):
367     def __init__(self,args):
368         self.args=args
369         self.initArgs()
370         self.CMD=['SALOME_Container','SuperVisionContainer']
371
372 # ---
373
374 class LoggerServer(Server):
375     def __init__(self,args):
376         self.args=args
377         self.initArgs()
378         self.CMD=['SALOME_Logger_Server', 'logger.log']
379
380 # ---
381
382 class SessionServer(Server):
383     def __init__(self,args):
384         self.args=args
385         self.initArgs()
386         self.SCMD1=['SALOME_Session_Server']
387         self.SCMD2=[]
388         if 'registry' in self.args['embedded']:
389             self.SCMD1+=['--with','Registry',
390                          '(','--salome_session','theSession',')']
391         if 'moduleCatalog' in self.args['embedded']:
392             self.SCMD1+=['--with','ModuleCatalog','(','-common']
393             home_dir=os.getenv('HOME')
394             if home_dir is not None:
395                 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] 
396             self.SCMD2+=[')']
397         if 'study' in self.args['embedded']:
398             self.SCMD2+=['--with','SALOMEDS','(',')']
399         if 'cppContainer' in self.args['embedded']:
400             self.SCMD2+=['--with','Container','(','FactoryServer',')']
401         if 'SalomeAppEngine' in self.args['embedded']:
402             self.SCMD2+=['--with','SalomeAppEngine','(',')']
403             
404         if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
405             self.SCMD2+=['CPP']
406         if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
407             self.SCMD2+=['PY']
408         if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
409             self.SCMD2+=['SUPERV']
410         if self.args['gui']:
411             self.SCMD2+=['GUI']
412         if self.args['splash']:
413             self.SCMD2+=['SPLASH']
414         if self.args['noexcepthandler']:
415             self.SCMD2+=['noexcepthandler']
416         if self.args.has_key('modules'):
417             self.SCMD2+=['--modules (']
418             for mod in self.args['modules']:
419                 self.SCMD2+=[mod + ':']
420             self.SCMD2+=[')']    
421
422     def setpath(self,modules_list,modules_root_dir):
423         cata_path=[]
424         list_modules = modules_list[:]
425         list_modules.reverse()
426         for module in ["KERNEL", "GUI"] + list_modules:
427             module_root_dir=modules_root_dir[module]
428             module_cata=module+"Catalog.xml"
429             #print "   ", module_cata
430             cata_path.extend(
431                 glob.glob(os.path.join(module_root_dir,"share",
432                                        salome_subdir,"resources",
433                                        module_cata)))
434         if 'moduleCatalog' in self.args['embedded']:
435             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
436         else:
437             self.CMD=self.SCMD1 + self.SCMD2
438       
439 # ---
440
441 class ContainerManagerServer(Server):
442     def __init__(self,args):
443         self.args=args
444         self.initArgs()
445         self.SCMD1=['SALOME_ContainerManagerServer']
446         self.SCMD2=[]
447         if 'registry' in self.args['embedded']:
448             self.SCMD1+=['--with','Registry',
449                          '(','--salome_session','theSession',')']
450         if 'moduleCatalog' in self.args['embedded']:
451             self.SCMD1+=['--with','ModuleCatalog','(','-common']
452             self.SCMD2+=['-personal',
453                          '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
454         if 'study' in self.args['embedded']:
455             self.SCMD2+=['--with','SALOMEDS','(',')']
456         if 'cppContainer' in self.args['embedded']:
457             self.SCMD2+=['--with','Container','(','FactoryServer',')']
458         
459     def setpath(self,modules_list,modules_root_dir):
460         cata_path=[]
461         list_modules = modules_list[:]
462         list_modules.reverse()
463         for module in ["KERNEL", "GUI"] + list_modules:
464             if modules_root_dir.has_key(module):
465                 module_root_dir=modules_root_dir[module]
466                 module_cata=module+"Catalog.xml"
467                 #print "   ", module_cata
468                 cata_path.extend(
469                     glob.glob(os.path.join(module_root_dir,"share",
470                                            self.args['appname'],"resources",
471                                            module_cata)))
472                 pass
473             pass
474         if 'moduleCatalog' in self.args['embedded']:
475             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
476         else:
477             self.CMD=self.SCMD1 + self.SCMD2
478
479 class NotifyServer(Server):
480     def __init__(self,args,modules_root_dir):
481         self.args=args
482         self.initArgs()
483         self.modules_root_dir=modules_root_dir
484         myLogName = os.environ["LOGNAME"]
485         self.CMD=['notifd','-c',
486                   self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
487                   '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
488                   '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
489                   '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
490                   '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
491                   ]
492
493 #
494 # -----------------------------------------------------------------------------
495
496 def startGUI():
497     """Salome Session Graphic User Interface activation"""
498     import SALOME
499     import SALOME_Session_idl
500     session=clt.waitNS("/Kernel/Session",SALOME.Session)
501     session.GetInterface()
502   
503 # -----------------------------------------------------------------------------
504
505 def startSalome(args, modules_list, modules_root_dir):
506     """Launch all SALOME servers requested by args"""
507     init_time = os.times()
508
509     print "startSalome ", args
510     
511     #
512     # Initialisation ORB et Naming Service
513     #
514    
515     clt=orbmodule.client()
516
517     # (non obligatoire) Lancement Logger Server
518     # et attente de sa disponibilite dans le naming service
519     #
520
521     if args['logger']:
522         myServer=LoggerServer(args)
523         myServer.run()
524         clt.waitLogger("Logger")
525
526     # Notify Server launch
527     #
528
529     print "Notify Server to launch"
530
531     myServer=NotifyServer(args,modules_root_dir)
532     myServer.run()
533
534     #
535     # Lancement Registry Server,
536     # attente de la disponibilite du Registry dans le Naming Service
537     #
538
539     if 'registry' not in args['embedded']:
540         myServer=RegistryServer(args)
541         myServer.run()
542         clt.waitNSPID("/Registry",myServer.PID)
543
544     #
545     # Lancement Catalog Server,
546     # attente de la disponibilite du Catalog Server dans le Naming Service
547     #
548     
549
550     if 'moduleCatalog' not in args['embedded']:
551         cataServer=CatalogServer(args)
552         cataServer.setpath(modules_list,modules_root_dir)
553         cataServer.run()
554         import SALOME_ModuleCatalog
555         clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
556
557     #
558     # Lancement SalomeDS Server,
559     # attente de la disponibilite du SalomeDS dans le Naming Service
560     #
561
562     #print "ARGS = ",args
563     if 'study' not in args['embedded']:
564         print "RunStudy"
565         myServer=SalomeDSServer(args)
566         myServer.run()
567         clt.waitNSPID("/myStudyManager",myServer.PID)
568
569     #
570     # Lancement ContainerManagerServer
571     #
572     
573     myCmServer = ContainerManagerServer(args)
574     myCmServer.setpath(modules_list,modules_root_dir)
575     myCmServer.run()
576
577
578     from Utils_Identity import getShortHostName
579     
580     if os.getenv("HOSTNAME") == None:
581         if os.getenv("HOST") == None:
582             os.environ["HOSTNAME"]=getShortHostName()
583         else:
584             os.environ["HOSTNAME"]=os.getenv("HOST")
585
586     theComputer = getShortHostName()
587     
588     #
589     # Lancement Container C++ local,
590     # attente de la disponibilite du Container C++ local dans le Naming Service
591     #
592
593     if 'cppContainer' in args['standalone']:
594         myServer=ContainerCPPServer(args)
595         myServer.run()
596         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
597
598     #
599     # Lancement Container Python local,
600     # attente de la disponibilite du Container Python local
601     # dans le Naming Service
602     #
603
604     if 'pyContainer' in args['standalone']:
605         myServer=ContainerPYServer(args)
606         myServer.run()
607         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
608
609     #
610     # Lancement Container Supervision local,
611     # attente de la disponibilite du Container Supervision local
612     # dans le Naming Service
613     #
614
615     if 'supervContainer' in args['standalone']:
616         myServer=ContainerSUPERVServer(args)
617         myServer.run()
618         clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
619
620     #
621     # Lancement Session Server
622     #
623
624     mySessionServ = SessionServer(args)
625     mySessionServ.setpath(modules_list,modules_root_dir)
626     mySessionServ.run()
627 ##----------------        
628
629     # Attente de la disponibilite du Session Server dans le Naming Service
630     #
631
632     import SALOME
633     import SALOME_Session_idl
634     session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
635
636     end_time = os.times()
637     print
638     print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
639                                                          - init_time[4])
640
641     # ASV start GUI without Loader
642     #if args['gui']:
643     #    session.GetInterface()
644
645     #
646     # additionnal external python interpreters
647     #
648     nbaddi=0
649     
650     try:
651         if 'interp' in args:
652             if args['interp']:
653                 nbaddi = int(args['interp'][0])
654     except:
655         import traceback
656         traceback.print_exc()
657         print "-------------------------------------------------------------"
658         print "-- to get an external python interpreter:runSalome --interp=1"
659         print "-------------------------------------------------------------"
660         
661     print "additional external python interpreters: ", nbaddi
662     if nbaddi:
663         for i in range(nbaddi):
664             print "i=",i
665             anInterp=InterpServer(args)
666             anInterp.run()
667     
668     return clt
669
670 # -----------------------------------------------------------------------------
671
672 def useSalome(args, modules_list, modules_root_dir):
673     """
674     Launch all SALOME servers requested by args,
675     save list of process, give info to user,
676     show registered objects in Naming Service.
677     """
678     
679     clt=None
680     try:
681         clt = startSalome(args, modules_list, modules_root_dir)
682     except:
683         import traceback
684         traceback.print_exc()
685         print
686         print
687         print "--- erreur au lancement Salome ---"
688         
689     #print process_id
690
691     from killSalomeWithPort import getPiDict
692     filedict = getPiDict(args['port'])
693
694     process_ids = []
695     try:
696         fpid=open(filedict, 'r')
697         process_ids=pickle.load(fpid)
698         fpid.close()
699     except:
700         pass
701     
702     fpid=open(filedict, 'w')
703     process_ids.append(process_id)
704     pickle.dump(process_ids,fpid)
705     fpid.close()
706     
707     print """
708     Saving of the dictionary of Salome processes in %s
709     To kill SALOME processes from a console (kill all sessions from all ports):
710       python killSalome.py 
711     To kill SALOME from the present interpreter, if it is not closed :
712       killLocalPort()      --> kill this session
713                                (use CORBA port from args of runSalome)
714       givenPortKill(port)  --> kill a specific session with given CORBA port 
715       killAllPorts()       --> kill all sessions
716     
717     runSalome, with --killall option, starts with killing
718     the processes resulting from the previous execution.
719     """%filedict
720     
721     #
722     #  Impression arborescence Naming Service
723     #
724     
725     if clt != None:
726         print
727         print " --- registered objects tree in Naming Service ---"
728         clt.showNS()
729
730     return clt
731
732 # -----------------------------------------------------------------------------
733
734 def registerEnv(args, modules_list, modules_root_dir):
735     """
736     Register args, modules_list, modules_root_dir in a file
737     for further use, when SALOME is launched embedded in an other application.
738     """
739     fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
740             + '_' + args['appname'].upper() + '_env'
741     fenv=open(fileEnv,'w')
742     pickle.dump((args, modules_list, modules_root_dir),fenv)
743     fenv.close()
744     os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
745
746 # -----------------------------------------------------------------------------
747
748 def no_main():
749     """Salome Launch, when embedded in other application"""
750     fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
751     fenv=open(fileEnv,'r')
752     args, modules_list, modules_root_dir = pickle.load(fenv)
753     fenv.close()
754     kill_salome(args)
755     clt = useSalome(args, modules_list, modules_root_dir)
756     return clt
757
758 # -----------------------------------------------------------------------------
759
760 def main():
761     """Salome launch as a main application"""
762     args, modules_list, modules_root_dir = get_config()
763     kill_salome(args)
764     set_env(args, modules_list, modules_root_dir)
765     clt = useSalome(args, modules_list, modules_root_dir)
766     return clt,args
767
768 # -----------------------------------------------------------------------------
769
770 if __name__ == "__main__":
771    import user
772    clt,args = main()