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