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