3 usage="""USAGE: runSalome.py [options]
5 [command line options] :
6 --help : affichage de l'aide
7 --gui : lancement du GUI
8 --logger : redirection des messages dans un fichier
9 --xterm : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre
10 --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue
11 --containers=cpp,python,superv: lancement des containers cpp, python et de supervision
12 --killall : arrêt des serveurs de salome
14 La variable d'environnement <modulen>_ROOT_DIR doit etre préalablement
15 positionnée (modulen doit etre en majuscule).
16 KERNEL_ROOT_DIR est obligatoire.
19 # -----------------------------------------------------------------------------
21 # Fonction d'arrêt de salome
25 print "arret des serveurs SALOME"
26 for pid, cmd in process_id.items():
27 print "arret du process %s : %s"% (pid, cmd[0])
29 os.kill(pid,signal.SIGKILL)
31 print " ------------------ process %s : %s inexistant"% (pid, cmd[0])
32 print "arret du naming service"
33 os.system("killall -9 omniNames")
35 # -----------------------------------------------------------------------------
40 def message(code, msg=''):
44 import sys,os,string,glob,time,signal,pickle,getopt
47 opts, args=getopt.getopt(sys.argv[1:], 'hmglxck:', ['help','modules=','gui','logger','xterm','containers=','killall'])
57 with_container_python=0
58 with_container_superv=0
62 if o in ('-h', '--help'):
65 elif o in ('-g', '--gui'):
67 elif o in ('-l', '--logger'):
69 elif o in ('-x', '--xterm'):
71 elif o in ('-m', '--modules'):
72 liste_modules = [x.upper() for x in a.split(',')]
73 elif o in ('-c', '--containers'):
74 liste_containers = [x.lower() for x in a.split(',')]
75 for r in liste_containers:
76 if r not in ('cpp', 'python', 'superv'):
77 message(1, 'Invalid -c/--containers option: %s' % a)
78 if 'cpp' in liste_containers:
82 if 'python' in liste_containers:
83 with_container_python=1
85 with_container_python=0
86 if 'superv' in liste_containers:
87 with_container_superv=1
89 with_container_superv=0
90 elif o in ('-k', '--killall'):
91 filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
92 #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
95 fpid=open(filedict, 'r')
98 print "le fichier %s des process SALOME n'est pas accessible"% filedict
101 process_id=pickle.load(fpid)
107 except getopt.error, msg:
111 # -----------------------------------------------------------------------------
113 # Vérification des variables d'environnement
116 kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
117 modules_root_dir["KERNEL"]=kernel_root_dir
122 for module in liste_modules :
124 module=module.upper()
125 module_root_dir=os.environ[module +"_ROOT_DIR"]
126 modules_root_dir[module]=module_root_dir
131 # il faut KERNEL en premier dans la liste des modules
132 # - l'ordre des modules dans le catalogue sera identique
133 # - la liste des modules presents dans le catalogue est exploitée pour charger les modules CORBA python,
134 # il faut charger les modules python du KERNEL en premier
136 if "KERNEL" in liste_modules:liste_modules.remove("KERNEL")
137 liste_modules[:0]=["KERNEL"]
139 #print modules_root_dir
141 os.environ["SALOMEPATH"]=":".join(modules_root_dir.values())
142 if "SUPERV" in liste_modules:with_container_superv=1
145 # -----------------------------------------------------------------------------
147 # Définition des classes d'objets pour le lancement des Server CORBA
153 ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-e']
158 args = self.ARGS+self.CMD
159 #print "args = ", args
160 pid = os.spawnvp(os.P_NOWAIT, args[0], args)
161 process_id[pid]=self.CMD
163 class CatalogServer(Server):
164 SCMD1=['SALOME_ModuleCatalog_Server','-common']
165 SCMD2=['-personal','${HOME}/Salome/resources/CatalogModulePersonnel.xml']
167 def setpath(self,liste_modules):
169 for module in liste_modules:
170 module_root_dir=modules_root_dir[module]
171 module_cata=module+"Catalog.xml"
172 print " ", module_cata
173 cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata)))
174 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
176 class SalomeDSServer(Server):
177 CMD=['SALOMEDS_Server']
179 class RegistryServer(Server):
180 CMD=['SALOME_Registry_Server', '--salome_session','theSession']
182 class ContainerCPPServer(Server):
183 CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost']
185 class ContainerPYServer(Server):
186 CMD=['SALOME_ContainerPy.py','FactoryServerPy','-ORBInitRef','NameService=corbaname::localhost']
188 class ContainerSUPERVServer(Server):
189 CMD=['SALOME_Container','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost']
191 class LoggerServer(Server):
192 CMD=['SALOME_Logger_Server', 'logger.log']
194 class SessionLoader(Server):
195 CMD=['SALOME_Session_Loader']
196 if with_container_cpp:
198 if with_container_python:
200 if with_container_superv:
205 class SessionServer(Server):
206 CMD=['SALOME_Session_Server']
208 class NotifyServer(Server):
209 CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior']
211 # -----------------------------------------------------------------------------
217 # create an LifeCycleCORBA instance
218 import LifeCycleCORBA
219 lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb)
220 med = lcc.FindOrLoadComponent("FactoryServer", "MED")
221 #pycalc = lcc.FindOrLoadComponent("FactoryServerPy", "CalculatorPy")
223 # -----------------------------------------------------------------------------
225 # Fonctions helper pour ajouter des variables d'environnement
228 def add_path(directory):
229 os.environ["PATH"]=directory + ":" + os.environ["PATH"]
231 def add_ld_library_path(directory):
232 os.environ["LD_LIBRARY_PATH"]=directory + ":" + os.environ["LD_LIBRARY_PATH"]
234 def add_python_path(directory):
235 os.environ["PYTHONPATH"]=directory + ":" + os.environ["PYTHONPATH"]
236 sys.path[:0]=[directory]
238 # -----------------------------------------------------------------------------
240 # initialisation des variables d'environnement
243 python_version="python%d.%d" % sys.version_info[0:2]
246 # Ajout du chemin d'acces aux executables de KERNEL dans le PATH
249 add_path(os.path.join(kernel_root_dir,"bin","salome"))
250 #print "PATH=",os.environ["PATH"]
253 # Ajout des modules dans le LD_LIBRARY_PATH
255 for module in liste_modules:
256 module_root_dir=modules_root_dir[module]
257 add_ld_library_path(os.path.join(module_root_dir,"lib","salome"))
259 os.environ["SALOME_trace"]="local"
261 os.environ["SALOME_trace"]="with_logger"
262 locdir=os.environ['PWD']
263 libtracedir=os.path.join(locdir,"libSalomeTrace")
264 libtrace = os.path.join(kernel_root_dir,"lib","salome","libSALOMELoggerClient.so.0.0.0")
265 libtraceln = os.path.join(libtracedir,"libSALOMELocalTrace.so")
266 aCommand = 'rm -rf ' + libtracedir + "; "
267 aCommand += 'mkdir ' + libtracedir + "; "
268 aCommand += 'ln -s ' + libtrace + " " + libtraceln + "; "
269 aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0; "
270 aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0.0.0; "
272 add_ld_library_path(libtracedir)
274 #print "LD_LIBRARY_PATH=",os.environ["LD_LIBRARY_PATH"]
277 # Ajout des modules dans le PYTHONPATH (KERNEL prioritaire, donc en dernier)
280 liste_modules_reverse=liste_modules[:]
281 liste_modules_reverse.reverse()
283 #print liste_modules_reverse
284 for module in liste_modules_reverse:
285 module_root_dir=modules_root_dir[module]
286 add_python_path(os.path.join(module_root_dir,"bin","salome"))
287 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome"))
288 add_python_path(os.path.join(module_root_dir,"lib","salome"))
289 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome","shared_modules"))
291 #print "PYTHONPATH=",sys.path
296 # -----------------------------------------------------------------------------
301 session=clt.waitNS("/Kernel/Session",SALOME.Session)
304 # Activation du GUI de Session Server
307 session.GetInterface()
310 # -----------------------------------------------------------------------------
316 # Lancement Session Loader
320 SessionLoader().run()
323 # Initialisation ORB et Naming Service
326 clt=orbmodule.client()
328 # (non obligatoire) Lancement Logger Server et attente de sa disponibilite dans le naming service
333 clt.waitLogger("Logger")
337 # Lancement Registry Server
340 RegistryServer().run()
343 # Attente de la disponibilité du Registry dans le Naming Service
346 clt.waitNS("/Registry")
349 # Lancement Catalog Server
352 cataServer=CatalogServer()
353 cataServer.setpath(liste_modules)
357 # Attente de la disponibilité du Catalog Server dans le Naming Service
360 import SALOME_ModuleCatalog
361 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
364 # Lancement SalomeDS Server
367 os.environ["CSF_PluginDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
368 os.environ["CSF_SALOMEDS_ResourcesDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
369 SalomeDSServer().run()
371 if "GEOM" in liste_modules:
372 print "GEOM OCAF Resources"
373 os.environ["CSF_GEOMDS_ResourcesDefaults"]=os.path.join(modules_root_dir["GEOM"],"share","salome","resources")
377 # Attente de la disponibilité du SalomeDS dans le Naming Service
380 clt.waitNS("/myStudyManager")
383 # Lancement Session Server
386 SessionServer().run()
389 # Attente de la disponibilité du Session Server dans le Naming Service
393 session=clt.waitNS("/Kernel/Session",SALOME.Session)
395 if os.getenv("HOSTNAME") == None:
396 if os.getenv("HOST") == None:
397 os.environ["HOSTNAME"]="localhost"
399 os.environ["HOSTNAME"]=os.getenv("HOST")
401 theComputer = os.getenv("HOSTNAME")
402 computerSplitName = theComputer.split('.')
403 theComputer = computerSplitName[0]
406 # Lancement Container C++ local
408 if with_container_cpp:
409 ContainerCPPServer().run()
412 # Attente de la disponibilité du Container C++ local dans le Naming Service
415 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
418 # Lancement Container Python local
421 if with_container_python:
422 ContainerPYServer().run()
425 # Attente de la disponibilité du Container Python local dans le Naming Service
428 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
430 if with_container_superv:
433 # Lancement Container Supervision local
436 ContainerSUPERVServer().run()
439 # Attente de la disponibilité du Container Supervision local dans le Naming Service
442 clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
446 # Activation du GUI de Session Server
449 #session.GetInterface()
451 end_time = os.times()
453 print "Start SALOME, elpased time : %5.1f seconds"% (end_time[4] - init_time[4])
458 # -----------------------------------------------------------------------------
461 if __name__ == "__main__":
468 print "--- erreur au lancement Salome ---"
473 filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
474 #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
476 fpid=open(filedict, 'w')
477 pickle.dump(process_id,fpid)
481 print "Sauvegarde du dictionnaire des process dans ", filedict
482 print "Pour tuer les process SALOME, executer : python killSalome.py depuis"
483 print "une console, ou bien killSalome() depuis le present interpreteur,"
484 print "s'il n'est pas fermé."
486 print "runSalome, avec l'option --killall, commence par tuer les process restants d'une execution précédente."
488 print "Pour lancer uniquement le GUI, executer startGUI() depuis le present interpreteur,"
489 print "s'il n'est pas fermé."
492 # Impression arborescence Naming Service
497 print " --- registered objects tree in Naming Service ---"