2 # Copyright (C) 2011-2013 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 usage="""USAGE: runSalome.py [options]
23 [command line options] :
24 --help : affichage de l'aide
25 --gui : lancement du GUI
26 --logger : redirection des messages dans un fichier
27 --xterm : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre
28 --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue
29 --containers=cpp,python,superv: lancement des containers cpp, python et de supervision
30 --killall : arrêt des serveurs de salome
32 La variable d'environnement <modulen>_ROOT_DIR doit etre préalablement
33 positionnée (modulen doit etre en majuscule).
34 KERNEL_ROOT_DIR est obligatoire.
37 # -----------------------------------------------------------------------------
39 # Fonction d'arrêt de salome
43 print "arret des serveurs SALOME"
44 for pid, cmd in process_id.items():
45 print "arret du process %s : %s"% (pid, cmd[0])
47 os.kill(pid,signal.SIGKILL)
49 print " ------------------ process %s : %s inexistant"% (pid, cmd[0])
50 print "arret du naming service"
51 os.system("killall -9 omniNames")
53 # -----------------------------------------------------------------------------
58 def message(code, msg=''):
62 import sys,os,string,glob,time,signal,pickle,getopt
65 opts, args=getopt.getopt(sys.argv[1:], 'hmglxck:', ['help','modules=','gui','logger','xterm','containers=','killall'])
75 with_container_python=0
76 with_container_superv=0
80 if o in ('-h', '--help'):
83 elif o in ('-g', '--gui'):
85 elif o in ('-l', '--logger'):
87 elif o in ('-x', '--xterm'):
89 elif o in ('-m', '--modules'):
90 liste_modules = [x.upper() for x in a.split(',')]
91 elif o in ('-c', '--containers'):
92 liste_containers = [x.lower() for x in a.split(',')]
93 for r in liste_containers:
94 if r not in ('cpp', 'python', 'superv'):
95 message(1, 'Invalid -c/--containers option: %s' % a)
96 if 'cpp' in liste_containers:
100 if 'python' in liste_containers:
101 with_container_python=1
103 with_container_python=0
104 if 'superv' in liste_containers:
105 with_container_superv=1
107 with_container_superv=0
108 elif o in ('-k', '--killall'):
109 filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
110 #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
113 fpid=open(filedict, 'r')
116 print "le fichier %s des process SALOME n'est pas accessible"% filedict
119 process_id=pickle.load(fpid)
125 except getopt.error, msg:
129 # -----------------------------------------------------------------------------
131 # Vérification des variables d'environnement
134 kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
135 modules_root_dir["KERNEL"]=kernel_root_dir
140 for module in liste_modules :
142 module=module.upper()
143 module_root_dir=os.environ[module +"_ROOT_DIR"]
144 modules_root_dir[module]=module_root_dir
149 # il faut KERNEL en premier dans la liste des modules
150 # - l'ordre des modules dans le catalogue sera identique
151 # - la liste des modules presents dans le catalogue est exploitée pour charger les modules CORBA python,
152 # il faut charger les modules python du KERNEL en premier
154 if "KERNEL" in liste_modules:liste_modules.remove("KERNEL")
155 liste_modules[:0]=["KERNEL"]
157 #print modules_root_dir
159 os.environ["SALOMEPATH"]=":".join(modules_root_dir.values())
160 if "SUPERV" in liste_modules:with_container_superv=1
163 # -----------------------------------------------------------------------------
165 # Définition des classes d'objets pour le lancement des Server CORBA
171 ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-e']
176 args = self.ARGS+self.CMD
177 #print "args = ", args
178 pid = os.spawnvp(os.P_NOWAIT, args[0], args)
179 process_id[pid]=self.CMD
181 class CatalogServer(Server):
182 SCMD1=['SALOME_ModuleCatalog_Server','-common']
183 SCMD2=['-personal','${HOME}/Salome/resources/CatalogModulePersonnel.xml']
185 def setpath(self,liste_modules):
187 for module in liste_modules:
188 module_root_dir=modules_root_dir[module]
189 module_cata=module+"Catalog.xml"
190 print " ", module_cata
191 cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata)))
192 self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
194 class SalomeDSServer(Server):
195 CMD=['SALOMEDS_Server']
197 class RegistryServer(Server):
198 CMD=['SALOME_Registry_Server', '--salome_session','theSession']
200 class ContainerCPPServer(Server):
201 CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost']
203 class ContainerPYServer(Server):
204 CMD=['SALOME_ContainerPy.py','FactoryServerPy','-ORBInitRef','NameService=corbaname::localhost']
206 class ContainerSUPERVServer(Server):
207 CMD=['SALOME_Container','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost']
209 class LoggerServer(Server):
210 CMD=['SALOME_Logger_Server', 'logger.log']
212 class SessionLoader(Server):
213 CMD=['SALOME_Session_Loader']
214 if with_container_cpp:
216 if with_container_python:
218 if with_container_superv:
223 class SessionServer(Server):
224 CMD=['SALOME_Session_Server']
226 class NotifyServer(Server):
227 CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior']
229 # -----------------------------------------------------------------------------
236 Test function that creates an instance of PYHELLO component
237 usage : pyhello=test(clt)
239 # create an LifeCycleCORBA instance
240 import LifeCycleCORBA
241 lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb)
243 pyhello = lcc.FindOrLoadComponent("FactoryServerPy", "PYHELLO")
246 # -----------------------------------------------------------------------------
248 # Fonctions helper pour ajouter des variables d'environnement
251 def add_path(directory):
252 os.environ["PATH"]=directory + ":" + os.environ["PATH"]
254 def add_ld_library_path(directory):
255 os.environ["LD_LIBRARY_PATH"]=directory + ":" + os.environ["LD_LIBRARY_PATH"]
257 def add_python_path(directory):
258 os.environ["PYTHONPATH"]=directory + ":" + os.environ["PYTHONPATH"]
259 sys.path[:0]=[directory]
261 # -----------------------------------------------------------------------------
263 # initialisation des variables d'environnement
266 python_version="python%d.%d" % sys.version_info[0:2]
269 # Ajout du chemin d'acces aux executables de KERNEL dans le PATH
272 add_path(os.path.join(kernel_root_dir,"bin","salome"))
273 #print "PATH=",os.environ["PATH"]
276 # Ajout des modules dans le LD_LIBRARY_PATH
278 for module in liste_modules:
279 module_root_dir=modules_root_dir[module]
280 add_ld_library_path(os.path.join(module_root_dir,"lib","salome"))
281 #print "LD_LIBRARY_PATH=",os.environ["LD_LIBRARY_PATH"]
284 # Ajout des modules dans le PYTHONPATH (KERNEL prioritaire, donc en dernier)
287 liste_modules_reverse=liste_modules[:]
288 liste_modules_reverse.reverse()
290 #print liste_modules_reverse
291 for module in liste_modules_reverse:
292 module_root_dir=modules_root_dir[module]
293 add_python_path(os.path.join(module_root_dir,"bin","salome"))
294 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome"))
295 add_python_path(os.path.join(module_root_dir,"lib","salome"))
296 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome","shared_modules"))
298 #print "PYTHONPATH=",sys.path
303 # -----------------------------------------------------------------------------
308 session=clt.waitNS("/Kernel/Session",SALOME.Session)
311 # Activation du GUI de Session Server
314 session.GetInterface()
317 # -----------------------------------------------------------------------------
323 # Lancement Session Loader
325 SessionLoader().run()
328 # Initialisation ORB et Naming Service
330 clt=orbmodule.client()
332 # (non obligatoire) Lancement Logger Server et attente de sa
333 # disponibilite dans le naming service
337 clt.waitLogger("Logger")
340 # Lancement Registry Server
342 RegistryServer().run()
345 # Attente de la disponibilité du Registry dans le Naming Service
347 clt.waitNS("/Registry")
350 # Lancement Catalog Server
352 cataServer=CatalogServer()
353 cataServer.setpath(liste_modules)
357 # Attente de la disponibilité du Catalog Server dans le Naming Service
359 import SALOME_ModuleCatalog
360 clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
363 # Lancement SalomeDS Server
365 os.environ["CSF_PluginDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
366 os.environ["CSF_SALOMEDS_ResourcesDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
367 SalomeDSServer().run()
369 if "GEOM" in liste_modules:
370 print "GEOM OCAF Resources"
371 os.environ["CSF_GEOMDS_ResourcesDefaults"]=os.path.join(modules_root_dir["GEOM"],"share","salome","resources")
375 # Attente de la disponibilité du SalomeDS dans le Naming Service
377 clt.waitNS("/myStudyManager")
380 # Lancement Session Server
382 SessionServer().run()
385 # Attente de la disponibilité du Session Server dans le Naming Service
388 session=clt.waitNS("/Kernel/Session",SALOME.Session)
391 # Lancement containers
393 theComputer = os.getenv("HOSTNAME")
394 theComputer = theComputer.split('.')[0]
397 # Lancement Container C++ local
399 if with_container_cpp:
400 ContainerCPPServer().run()
402 # Attente de la disponibilité du Container C++ local
403 # dans le Naming Service
405 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
407 # Lancement Container Python local
409 if with_container_python:
410 ContainerPYServer().run()
412 # Attente de la disponibilité du Container Python local
413 # dans le Naming Service
415 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
417 if with_container_superv:
419 # Lancement Container Supervision local
421 ContainerSUPERVServer().run()
423 # Attente de la disponibilité du Container Supervision local
424 # dans le Naming Service
426 clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
428 # Activation du GUI de Session Server
430 #session.GetInterface()
432 end_time = os.times()
434 print "Start SALOME, elpased time : %5.1f seconds"% (end_time[4] - init_time[4])
439 # -----------------------------------------------------------------------------
442 if __name__ == "__main__":
449 print "--- erreur au lancement Salome ---"
454 filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
455 #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
457 fpid=open(filedict, 'w')
458 pickle.dump(process_id,fpid)
463 Sauvegarde du dictionnaire des process dans , %s
464 Pour tuer les process SALOME, executer : python killSalome.py depuis
465 une console, ou bien killSalome() depuis le present interpreteur,
466 s'il n'est pas fermé.
468 runSalome, avec l'option --killall, commence par tuer les process restants
469 d'une execution précédente.
471 Pour lancer uniquement le GUI, executer startGUI() depuis le present interpreteur,
472 s'il n'est pas fermé.
477 # Impression arborescence Naming Service
482 print " --- registered objects tree in Naming Service ---"
484 session=clt.waitNS("/Kernel/Session")
485 catalog=clt.waitNS("/Kernel/ModulCatalog")
487 container = clt.waitNS("/Containers/" + socket.gethostname().split('.')[0] + "/FactoryServerPy")
489 if os.path.isfile("~/.salome/pystartup"):
490 f=open(os.path.expanduser("~/.salome/pystartup"),'w')
491 PYTHONSTARTUP=f.read()
495 # Add auto-completion and a stored history file of commands to your Python
496 # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
497 # bound to the TAB key by default (you can change it - see readline docs).
499 # Store the history in ~/.salome/pyhistory,
505 readline.parse_and_bind('tab: complete')
507 historyPath = os.path.expanduser("~/.salome/pyhistory")
509 def save_history(historyPath=historyPath):
511 readline.write_history_file(historyPath)
513 if os.path.exists(historyPath):
514 readline.read_history_file(historyPath)
516 atexit.register(save_history)
517 del os, atexit, readline, rlcompleter, save_history, historyPath
519 f=open(os.path.expanduser("~/.salome/pystartup"),'w')
520 f.write(PYTHONSTARTUP)
523 exec PYTHONSTARTUP in {}