Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/yacs.git] / bin / runSalome.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
4 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either 
8 # version 2.1 of the License.
9
10 # This library is distributed in the hope that it will be useful 
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public  
16 # License along with this library; if not, write to the Free Software 
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20
21
22 import sys, os, string, glob, time, pickle
23 import orbmodule
24
25 process_id = {}
26
27 # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc.
28 # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used.
29 # but after - 'appname'  = "SalomeApp", so using it in making the subdirectory is an error.
30 salome_subdir = "salome"
31
32 # -----------------------------------------------------------------------------
33
34 def add_path(directory, variable_name):
35     """Function helper to add environment variables"""
36     if not os.environ.has_key(variable_name):
37         os.environ[variable_name] = ""
38         pass
39     if os.path.exists(directory):
40         newpath=[]
41         for _dir in os.environ[variable_name].split(":"):
42             if os.path.exists(_dir):
43                 if not os.path.samefile(_dir, directory):
44                   newpath.append(_dir)
45             else:
46                 if os.path.abspath(_dir) != os.path.abspath(directory):
47                   newpath.append(_dir)
48             pass
49         import string
50         newpath[:0] = [ directory ]
51         newpath = string.join(newpath,":")
52         os.environ[variable_name] = newpath
53         if variable_name == "PYTHONPATH":
54             sys.path[:0] = [directory]
55
56 # -----------------------------------------------------------------------------
57
58 def get_config():
59     """
60     Get list of modules, paths.
61     
62     Read args from launch configure xml file and command line options.
63     Check variables <module>_ROOT_DIR and set list of used modules.
64     Return args, modules_list, modules_root_dir    
65     """
66     
67     # read args from launch configure xml file and command line options
68     
69     import launchConfigureParser
70     args = launchConfigureParser.args
71     
72     # Check variables <module>_ROOT_DIR
73     # and set list of used modules (without KERNEL)
74
75     modules_list = []
76     if args.has_key("modules"):
77         modules_list += args["modules"]
78     # KERNEL must be last in the list to locate it at the first place in PATH
79     if args["gui"] :
80         modules_list[:0] = ["GUI"]
81     modules_list[:0] = ["KERNEL"]
82     modules_list.reverse()
83
84     modules_root_dir = {}
85
86     to_remove_list=[]
87     for module in modules_list :
88         module_variable=module+"_ROOT_DIR"
89         if not os.environ.has_key(module_variable):
90             print "*******************************************************"
91             print "*"
92             print "* Environment variable",module_variable,"must be set"
93             print "* Module", module, "will be not available"
94             print "*"
95             print "********************************************************"
96             to_remove_list.append(module)
97             continue
98             pass
99         module_root_dir = os.environ[module_variable]
100         modules_root_dir[module]=module_root_dir
101
102     for to_remove in to_remove_list:
103         modules_list.remove(to_remove)
104
105     while "KERNEL" in modules_list:
106         modules_list.remove("KERNEL")
107         pass
108
109     while "GUI" in modules_list:
110         modules_list.remove("GUI")
111         pass
112
113     if "SUPERV" in modules_list and not 'superv' in args['standalone']:
114         args['standalone'].append("superv")
115         pass
116    
117     return args, modules_list, modules_root_dir
118
119 # -----------------------------------------------------------------------------
120
121 def set_env(args, modules_list, modules_root_dir):
122     """Add to the PATH-variables modules specific paths"""
123     
124     python_version="python%d.%d" % sys.version_info[0:2]
125     modules_root_dir_list = []
126     if args["gui"] :
127         modules_list = modules_list[:] + ["GUI"] 
128     modules_list = modules_list[:] + ["KERNEL"] 
129     for module in modules_list :
130         if modules_root_dir.has_key(module):
131             module_root_dir = modules_root_dir[module]
132             modules_root_dir_list[:0] = [module_root_dir]
133             add_path(os.path.join(module_root_dir,"lib",salome_subdir),
134                      "LD_LIBRARY_PATH")
135             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
136                      "PATH")
137             if os.path.exists(module_root_dir + "/examples") :
138                 add_path(os.path.join(module_root_dir,"examples"),
139                          "PYTHONPATH")
140                 pass
141             add_path(os.path.join(module_root_dir,"bin",salome_subdir),
142                      "PYTHONPATH")
143             add_path(os.path.join(module_root_dir,"lib",
144                                   python_version,"site-packages",
145                                   salome_subdir),
146                      "PYTHONPATH")
147             add_path(os.path.join(module_root_dir,"lib",salome_subdir),
148                      "PYTHONPATH")
149             add_path(os.path.join(module_root_dir,"lib",
150                                   python_version,"site-packages",
151                                   salome_subdir,
152                                   "shared_modules"),
153                      "PYTHONPATH")
154             pass
155         pass
156
157
158     os.environ["SALOMEPATH"]=":".join(modules_root_dir_list)
159     
160     # set trace environment variable
161     
162     if not os.environ.has_key("SALOME_trace"):
163         os.environ["SALOME_trace"]="local"
164     if args['file']:
165         os.environ["SALOME_trace"]="file:"+args['file'][0]
166     if args['logger']:
167         os.environ["SALOME_trace"]="with_logger"
168
169     # set environment for SMESH plugins
170
171     if "SMESH" in modules_list:
172         os.environ["SMESH_MeshersList"]="StdMeshers"
173         if not os.environ.has_key("SALOME_StdMeshersResources"):
174             os.environ["SALOME_StdMeshersResources"] \
175             = modules_root_dir["SMESH"]+"/share/"+args["appname"]+"/resources"
176             pass
177         if args.has_key("SMESH_plugins"):
178             for plugin in args["SMESH_plugins"]:
179                 plugin_root = ""
180                 if os.environ.has_key(plugin+"_ROOT_DIR"):
181                     plugin_root = os.environ[plugin+"_ROOT_DIR"]
182                 else:
183                     # workaround to avoid modifications of existing environment
184                     if os.environ.has_key(plugin.upper()+"_ROOT_DIR"):
185                         plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"]
186                         pass
187                     pass
188                 if plugin_root != "":
189                     os.environ["SMESH_MeshersList"] \
190                     = os.environ["SMESH_MeshersList"]+":"+plugin
191                     if not os.environ.has_key("SALOME_"+plugin+"Resources"):
192                         os.environ["SALOME_"+plugin+"Resources"] \
193                         = plugin_root+"/share/"+args["appname"]+"/resources"
194                     add_path(os.path.join(plugin_root,"lib",python_version,
195                                           "site-packages",salome_subdir),
196                              "PYTHONPATH")
197                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
198                              "PYTHONPATH")
199                     add_path(os.path.join(plugin_root,"lib",salome_subdir),
200                              "LD_LIBRARY_PATH")
201                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
202                              "PYTHONPATH")
203                     add_path(os.path.join(plugin_root,"bin",salome_subdir),
204                              "PATH")
205             pass
206         pass
207
208     # set environment for SUPERV module
209     os.environ["ENABLE_MACRO_NODE"]="1"
210     # set resources variables if not yet set
211     # Done now by launchConfigureParser.py
212     #if os.getenv("GUI_ROOT_DIR"):
213         #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] =  os.getenv("GUI_ROOT_DIR") + "/share/salome"
214         #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] =  os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
215
216     # set CSF_PluginDefaults variable only if it is not customized
217     # by the user
218     if not os.getenv("CSF_PluginDefaults"):
219         os.environ["CSF_PluginDefaults"] \
220         = os.path.join(modules_root_dir["KERNEL"],"share",
221                        salome_subdir,"resources")
222     os.environ["CSF_SALOMEDS_ResourcesDefaults"] \
223     = os.path.join(modules_root_dir["KERNEL"],"share",
224                    salome_subdir,"resources")
225
226     if "GEOM" in modules_list:
227         print "GEOM OCAF Resources"
228         os.environ["CSF_GEOMDS_ResourcesDefaults"] \
229         = os.path.join(modules_root_dir["GEOM"],"share",
230                        salome_subdir,"resources")
231         print "GEOM Shape Healing Resources"
232         os.environ["CSF_ShHealingDefaults"] \
233         = os.path.join(modules_root_dir["GEOM"],"share",
234                        salome_subdir,"resources")
235
236 # -----------------------------------------------------------------------------
237
238 from killSalome import killAllPorts
239
240 def killLocalPort():
241     """
242     kill servers from a previous SALOME exection, if needed,
243     on the CORBA port given in args of runSalome
244     """
245     
246     from killSalomeWithPort import killMyPort
247     my_port=str(args['port'])
248     try:
249         killMyPort(my_port)
250     except:
251         print "problem in killLocalPort()"
252         pass
253     pass
254     
255 def givenPortKill(port):
256     """
257     kill servers from a previous SALOME exection, if needed,
258     on the same CORBA port
259     """
260     
261     from killSalomeWithPort import killMyPort
262     my_port=port
263     try:
264         killMyPort(my_port)
265     except:
266         print "problem in LocalPortKill(), killMyPort("<<port<<")"
267         pass
268     pass
269
270 def kill_salome(args):
271     """
272     Kill servers from previous SALOME executions, if needed;
273     depending on args 'killall' or 'portkill', kill all executions,
274     or only execution on the same CORBA port
275     """
276
277     if args['killall']:
278         killAllPorts()
279     elif args['portkill']:
280         givenPortKill(str(args['port']))
281         
282 # -----------------------------------------------------------------------------
283 #
284 # Definition des classes d'objets pour le lancement des Server CORBA
285 #
286
287 class Server:
288     """Generic class for CORBA server launch"""
289
290     def initArgs(self):
291         self.PID=None
292         self.CMD=[]
293         self.ARGS=[]    
294         if self.args['xterm']:
295             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
296
297     def __init__(self,args):
298         self.args=args
299         self.initArgs()
300
301
302     def run(self):
303         global process_id
304         myargs=self.ARGS
305         if self.args['xterm']:
306             # (Debian) send LD_LIBRARY_PATH to children shells (xterm)
307             env_ld_library_path=['env', 'LD_LIBRARY_PATH='
308                                  + os.getenv("LD_LIBRARY_PATH")]
309             myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
310         command = myargs + self.CMD
311         print "command = ", command
312         pid = os.spawnvp(os.P_NOWAIT, command[0], command)
313         process_id[pid]=self.CMD
314         self.PID = pid
315
316
317 class InterpServer(Server):
318     def __init__(self,args):
319         self.args=args
320         env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
321         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
322         #self.CMD=['xterm', '-e', 'python']
323        
324     def run(self):
325         global process_id
326         command = self.CMD
327         #print "command = ", command
328         pid = os.spawnvp(os.P_NOWAIT, command[0], command)
329         process_id[pid]=self.CMD
330         self.PID = pid
331
332 # ---
333
334 class CatalogServer(Server):
335     def __init__(self,args):
336         self.args=args
337         self.initArgs()
338         self.SCMD1=['SALOME_ModuleCatalog_Server','-common']
339         self.SCMD2=[]
340         home_dir=os.getenv('HOME')
341         if home_dir is not None:
342             self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] 
343
344     def setpath(self,modules_list,modules_root_dir):
345         cata_path=[]
346         list_modules = modules_list[:]
347         list_modules.reverse()
348         if self.args["gui"] :
349             list_modules = ["KERNEL", "GUI"] + list_modules
350         else :
351             list_modules = ["KERNEL"] + list_modules
352         for module in list_modules:
353             if modules_root_dir.has_key(module):
354                 module_root_dir=modules_root_dir[module]
355                 module_cata=module+"Catalog.xml"
356                 #print "   ", module_cata
357                 cata_path.extend(
358                     glob.glob(os.path.join(module_root_dir,
359                                            "share",salome_subdir,
360                                            "resources",module_cata)))
361                 pass
362             pass
363         self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
364
365 # ---
366
367 class SalomeDSServer(Server):
368     def __init__(self,args):
369         self.args=args
370         self.initArgs()
371         self.CMD=['SALOMEDS_Server']
372
373 # ---
374
375 class RegistryServer(Server):
376     def __init__(self,args):
377         self.args=args
378         self.initArgs()
379         self.CMD=['SALOME_Registry_Server', '--salome_session','theSession']
380
381 # ---
382
383 class ContainerCPPServer(Server):
384     def __init__(self,args):
385         self.args=args
386         self.initArgs()
387         self.CMD=['SALOME_Container','FactoryServer']
388
389 # ---
390
391 class ContainerPYServer(Server):
392     def __init__(self,args):
393         self.args=args
394         self.initArgs()
395         self.CMD=['SALOME_ContainerPy.py','FactoryServerPy']
396
397 # ---
398
399 class ContainerSUPERVServer(Server):
400     def __init__(self,args):
401         self.args=args
402         self.initArgs()
403         self.CMD=['SALOME_Container','SuperVisionContainer']
404
405 # ---
406
407 class LoggerServer(Server):
408     def __init__(self,args):
409         self.args=args
410         self.initArgs()
411         self.CMD=['SALOME_Logger_Server', 'logger.log']
412
413 # ---
414
415 class SessionServer(Server):
416     def __init__(self,args):
417         self.args = args.copy()
418         # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge)
419         self.args['xterm']=0
420         #
421         self.initArgs()
422         self.SCMD1=['SALOME_Session_Server']
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             home_dir=os.getenv('HOME')
430             if home_dir is not None:
431                 self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] 
432             self.SCMD2+=[')']
433         if 'study' in self.args['embedded']:
434             self.SCMD2+=['--with','SALOMEDS','(',')']
435         if 'cppContainer' in self.args['embedded']:
436             self.SCMD2+=['--with','Container','(','FactoryServer',')']
437         if 'SalomeAppEngine' in self.args['embedded']:
438             self.SCMD2+=['--with','SalomeAppEngine','(',')']
439             
440         if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']:
441             self.SCMD2+=['CPP']
442         if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']:
443             self.SCMD2+=['PY']
444         if 'supervContainer' in self.args['containers'] or 'supervContainer' in self.args['standalone']:
445             self.SCMD2+=['SUPERV']
446         if self.args['gui']:
447             self.SCMD2+=['GUI']
448         if self.args['splash'] and self.args['gui']:
449             self.SCMD2+=['SPLASH']
450         if self.args['noexcepthandler']:
451             self.SCMD2+=['noexcepthandler']
452         if self.args.has_key('modules'):
453             self.SCMD2+=['--modules (']
454             for mod in self.args['modules']:
455                 self.SCMD2+=[mod + ':']
456             self.SCMD2+=[')']    
457
458     def setpath(self,modules_list,modules_root_dir):
459         cata_path=[]
460         list_modules = modules_list[:]
461         list_modules.reverse()
462         if self.args["gui"] :
463             list_modules = ["KERNEL", "GUI"] + list_modules
464         else :
465             list_modules = ["KERNEL"] + list_modules
466         for module in list_modules:
467             module_root_dir=modules_root_dir[module]
468             module_cata=module+"Catalog.xml"
469             #print "   ", module_cata
470             cata_path.extend(
471                 glob.glob(os.path.join(module_root_dir,"share",
472                                        salome_subdir,"resources",
473                                        module_cata)))
474         if (self.args["gui"]) & ('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 # ---
480
481 class ContainerManagerServer(Server):
482     def __init__(self,args):
483         self.args=args
484         self.initArgs()
485         self.SCMD1=['SALOME_ContainerManagerServer']
486         self.SCMD2=[]
487         if args["gui"] :
488             if 'registry' in self.args['embedded']:
489                 self.SCMD1+=['--with','Registry',
490                              '(','--salome_session','theSession',')']
491             if 'moduleCatalog' in self.args['embedded']:
492                 self.SCMD1+=['--with','ModuleCatalog','(','-common']
493                 self.SCMD2+=['-personal',
494                              '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')']
495             if 'study' in self.args['embedded']:
496                 self.SCMD2+=['--with','SALOMEDS','(',')']
497             if 'cppContainer' in self.args['embedded']:
498                 self.SCMD2+=['--with','Container','(','FactoryServer',')']
499         
500     def setpath(self,modules_list,modules_root_dir):
501         cata_path=[]
502         list_modules = modules_list[:]
503         list_modules.reverse()
504         if self.args["gui"] :
505             list_modules = ["GUI"] + list_modules
506         for module in ["KERNEL"] + list_modules:
507             if modules_root_dir.has_key(module):
508                 module_root_dir=modules_root_dir[module]
509                 module_cata=module+"Catalog.xml"
510                 #print "   ", module_cata
511                 cata_path.extend(
512                     glob.glob(os.path.join(module_root_dir,"share",
513                                            self.args['appname'],"resources",
514                                            module_cata)))
515                 pass
516             pass
517         if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']):
518             self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
519         else:
520             self.CMD=self.SCMD1 + self.SCMD2
521
522 class NotifyServer(Server):
523     def __init__(self,args,modules_root_dir):
524         self.args=args
525         self.initArgs()
526         self.modules_root_dir=modules_root_dir
527         myLogName = os.environ["LOGNAME"]
528         self.CMD=['notifd','-c',
529                   self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
530                   '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
531                   '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
532                   '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
533                   '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
534                   ]
535
536 #
537 # -----------------------------------------------------------------------------
538
539 def startGUI():
540     """Salome Session Graphic User Interface activation"""
541     import Engines
542     import SALOME
543     import SALOMEDS
544     import SALOME_ModuleCatalog
545     reload(Engines)
546     reload(SALOME)
547     reload(SALOMEDS)
548     import SALOME_Session_idl
549     session=clt.waitNS("/Kernel/Session",SALOME.Session)
550     session.GetInterface()
551   
552 # -----------------------------------------------------------------------------
553
554 def startSalome(args, modules_list, modules_root_dir):
555     """Launch all SALOME servers requested by args"""
556     init_time = os.times()
557
558     print "startSalome ", args
559     
560     #
561     # Initialisation ORB et Naming Service
562     #
563    
564     clt=orbmodule.client()
565
566     # (non obligatoire) Lancement Logger Server
567     # et attente de sa disponibilite dans le naming service
568     #
569
570     if args['logger']:
571         myServer=LoggerServer(args)
572         myServer.run()
573         clt.waitLogger("Logger")
574
575     # Notify Server launch
576     #
577
578     print "Notify Server to launch"
579
580     myServer=NotifyServer(args,modules_root_dir)
581     myServer.run()
582
583     # Lancement Session Server (to show splash ASAP)
584     #
585
586     if args["gui"]:
587         mySessionServ = SessionServer(args)
588         mySessionServ.setpath(modules_list,modules_root_dir)
589         mySessionServ.run()
590
591     #
592     # Lancement Registry Server,
593     # attente de la disponibilite du Registry dans le Naming Service
594     #
595
596     if ('registry' not in args['embedded']) | (args["gui"] == 0) :
597         myServer=RegistryServer(args)
598         myServer.run()
599         clt.waitNSPID("/Registry",myServer.PID)
600
601     #
602     # Lancement Catalog Server,
603     # attente de la disponibilite du Catalog Server dans le Naming Service
604     #
605     
606
607     if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0):
608         cataServer=CatalogServer(args)
609         cataServer.setpath(modules_list,modules_root_dir)
610         cataServer.run()
611         import SALOME_ModuleCatalog
612         clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
613
614     #
615     # Lancement SalomeDS Server,
616     # attente de la disponibilite du SalomeDS dans le Naming Service
617     #
618
619     #print "ARGS = ",args
620     if ('study' not in args['embedded']) | (args["gui"] == 0):
621         print "RunStudy"
622         myServer=SalomeDSServer(args)
623         myServer.run()
624         clt.waitNSPID("/myStudyManager",myServer.PID)
625
626     #
627     # Lancement ContainerManagerServer
628     #
629     
630     myCmServer = ContainerManagerServer(args)
631     myCmServer.setpath(modules_list,modules_root_dir)
632     myCmServer.run()
633
634
635     from Utils_Identity import getShortHostName
636     
637     if os.getenv("HOSTNAME") == None:
638         if os.getenv("HOST") == None:
639             os.environ["HOSTNAME"]=getShortHostName()
640         else:
641             os.environ["HOSTNAME"]=os.getenv("HOST")
642
643     theComputer = getShortHostName()
644     
645     #
646     # Lancement Container C++ local,
647     # attente de la disponibilite du Container C++ local dans le Naming Service
648     #
649
650     if 'cppContainer' in args['standalone']:
651         myServer=ContainerCPPServer(args)
652         myServer.run()
653         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
654
655     #
656     # Lancement Container Python local,
657     # attente de la disponibilite du Container Python local
658     # dans le Naming Service
659     #
660
661     if 'pyContainer' in args['standalone']:
662         myServer=ContainerPYServer(args)
663         myServer.run()
664         clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID)
665
666     #
667     # Lancement Container Supervision local,
668     # attente de la disponibilite du Container Supervision local
669     # dans le Naming Service
670     #
671
672     if 'supervContainer' in args['standalone']:
673         myServer=ContainerSUPERVServer(args)
674         myServer.run()
675         clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID)
676
677     #
678     # Attente de la disponibilite du Session Server dans le Naming Service
679     #
680     
681     if args["gui"]:
682 ##----------------        
683         import Engines
684         import SALOME
685         import SALOMEDS
686         import SALOME_ModuleCatalog
687         reload(Engines)
688         reload(SALOME)
689         reload(SALOMEDS)
690         import SALOME_Session_idl
691         session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session)
692
693     end_time = os.times()
694     print
695     print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
696                                                          - init_time[4])
697
698     # ASV start GUI without Loader
699     #if args['gui']:
700     #    session.GetInterface()
701
702     #
703     # additionnal external python interpreters
704     #
705     nbaddi=0
706     
707     try:
708         if 'interp' in args:
709             if args['interp']:
710                 nbaddi = int(args['interp'][0])
711     except:
712         import traceback
713         traceback.print_exc()
714         print "-------------------------------------------------------------"
715         print "-- to get an external python interpreter:runSalome --interp=1"
716         print "-------------------------------------------------------------"
717         
718     print "additional external python interpreters: ", nbaddi
719     if nbaddi:
720         for i in range(nbaddi):
721             print "i=",i
722             anInterp=InterpServer(args)
723             anInterp.run()
724     
725     return clt
726
727 # -----------------------------------------------------------------------------
728
729 def useSalome(args, modules_list, modules_root_dir):
730     """
731     Launch all SALOME servers requested by args,
732     save list of process, give info to user,
733     show registered objects in Naming Service.
734     """
735     
736     clt=None
737     try:
738         clt = startSalome(args, modules_list, modules_root_dir)
739     except:
740         import traceback
741         traceback.print_exc()
742         print
743         print
744         print "--- erreur au lancement Salome ---"
745         
746     #print process_id
747
748     from killSalomeWithPort import getPiDict
749     filedict = getPiDict(args['port'])
750
751     process_ids = []
752     try:
753         fpid=open(filedict, 'r')
754         process_ids=pickle.load(fpid)
755         fpid.close()
756     except:
757         pass
758     
759     fpid=open(filedict, 'w')
760     process_ids.append(process_id)
761     pickle.dump(process_ids,fpid)
762     fpid.close()
763     
764     print """
765     Saving of the dictionary of Salome processes in %s
766     To kill SALOME processes from a console (kill all sessions from all ports):
767       python killSalome.py 
768     To kill SALOME from the present interpreter, if it is not closed :
769       killLocalPort()      --> kill this session
770                                (use CORBA port from args of runSalome)
771       givenPortKill(port)  --> kill a specific session with given CORBA port 
772       killAllPorts()       --> kill all sessions
773     
774     runSalome, with --killall option, starts with killing
775     the processes resulting from the previous execution.
776     """%filedict
777     
778     #
779     #  Impression arborescence Naming Service
780     #
781     
782     if clt != None:
783         print
784         print " --- registered objects tree in Naming Service ---"
785         clt.showNS()
786
787     return clt
788
789 # -----------------------------------------------------------------------------
790
791 def registerEnv(args, modules_list, modules_root_dir):
792     """
793     Register args, modules_list, modules_root_dir in a file
794     for further use, when SALOME is launched embedded in an other application.
795     """
796     fileEnv = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \
797             + '_' + args['appname'].upper() + '_env'
798     fenv=open(fileEnv,'w')
799     pickle.dump((args, modules_list, modules_root_dir),fenv)
800     fenv.close()
801     os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
802
803 # -----------------------------------------------------------------------------
804
805 def no_main():
806     """Salome Launch, when embedded in other application"""
807     fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
808     fenv=open(fileEnv,'r')
809     args, modules_list, modules_root_dir = pickle.load(fenv)
810     fenv.close()
811     kill_salome(args)
812     clt = useSalome(args, modules_list, modules_root_dir)
813     return clt
814
815 # -----------------------------------------------------------------------------
816
817 def main():
818     """Salome launch as a main application"""
819     args, modules_list, modules_root_dir = get_config()
820     kill_salome(args)
821     set_env(args, modules_list, modules_root_dir)
822     clt = useSalome(args, modules_list, modules_root_dir)
823     return clt,args
824
825 # -----------------------------------------------------------------------------
826
827 if __name__ == "__main__":
828    import user
829    clt,args = main()