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