2 # Copyright (C) 2011-2023 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, or (at your option) any later version.
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: runHOMARD.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 list(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:
97 with_container_cpp = 1
99 with_container_cpp = 0
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 as 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(list(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 home_dir=os.path.expanduser("~")
184 SCMD2=['-personal',os.path.join(home_dir,'Salome', 'resources', 'CatalogModulePersonnel.xml')]
186 def setpath(self,liste_modules):
188 for module in liste_modules:
189 module_root_dir=modules_root_dir[module]
190 module_cata=module+"Catalog.xml"
191 print(" ", module_cata)
192 cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata)))
193 self.CMD = self.SCMD1 + [':'.join(cata_path)] + self.SCMD2
195 class SalomeDSServer(Server):
196 CMD=['SALOMEDS_Server']
198 class RegistryServer(Server):
199 CMD=['SALOME_Registry_Server', '--salome_session','theSession']
201 class ContainerCPPServer(Server):
202 CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost']
204 class ContainerPYServer(Server):
205 CMD=['SALOME_ContainerPy.py','FactoryServerPy','-ORBInitRef','NameService=corbaname::localhost']
207 class ContainerSUPERVServer(Server):
208 CMD=['SALOME_Container','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost']
210 class LoggerServer(Server):
211 CMD=['SALOME_Logger_Server', 'logger.log']
213 class SessionLoader(Server):
214 CMD=['SALOME_Session_Loader']
215 if with_container_cpp:
217 if with_container_python:
219 if with_container_superv:
224 class SessionServer(Server):
225 CMD=['SALOME_Session_Server']
227 class NotifyServer(Server):
228 CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior']
230 # -----------------------------------------------------------------------------
237 Test function that creates an instance of PYHELLO component
238 usage : pyhello=test(clt)
240 # create an LifeCycleCORBA instance
241 import LifeCycleCORBA
242 lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb)
244 pyhello = lcc.FindOrLoadComponent("FactoryServerPy", "PYHELLO")
247 # -----------------------------------------------------------------------------
249 # Fonctions helper pour ajouter des variables d'environnement
252 def add_path(directory):
253 os.environ["PATH"]=directory + ":" + os.environ["PATH"]
255 def add_ld_library_path(directory):
256 os.environ["LD_LIBRARY_PATH"]=directory + ":" + os.environ["LD_LIBRARY_PATH"]
258 def add_python_path(directory):
259 os.environ["PYTHONPATH"]=directory + ":" + os.environ["PYTHONPATH"]
260 sys.path[:0]=[directory]
262 # -----------------------------------------------------------------------------
264 # initialisation des variables d'environnement
267 python_version="python%d.%d" % sys.version_info[0:2]
270 # Ajout du chemin d'acces aux executables de KERNEL dans le PATH
273 add_path(os.path.join(kernel_root_dir,"bin","salome"))
274 #print "PATH=",os.environ["PATH"]
277 # Ajout des modules dans le LD_LIBRARY_PATH
279 for module in liste_modules:
280 module_root_dir=modules_root_dir[module]
281 add_ld_library_path(os.path.join(module_root_dir,"lib","salome"))
282 #print "LD_LIBRARY_PATH=",os.environ["LD_LIBRARY_PATH"]
285 # Ajout des modules dans le PYTHONPATH (KERNEL prioritaire, donc en dernier)
288 liste_modules_reverse=liste_modules[:]
289 liste_modules_reverse.reverse()
291 #print liste_modules_reverse
292 for module in liste_modules_reverse:
293 module_root_dir=modules_root_dir[module]
294 add_python_path(os.path.join(module_root_dir,"bin","salome"))
295 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome"))
296 add_python_path(os.path.join(module_root_dir,"lib","salome"))
297 add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome","shared_modules"))
299 #print "PYTHONPATH=",sys.path
304 # -----------------------------------------------------------------------------
309 session=clt.waitNS("/Kernel/Session",SALOME.Session)
312 # Activation du GUI de Session Server
315 session.GetInterface()
318 # -----------------------------------------------------------------------------
324 # Lancement Session Loader
326 SessionLoader().run()
329 # Initialisation ORB et Naming Service
331 clt=orbmodule.client()
333 # (non obligatoire) Lancement Logger Server et attente de sa
334 # disponibilite dans le naming service
338 clt.waitLogger("Logger")
341 # Lancement Registry Server
343 RegistryServer().run()
346 # Attente de la disponibilit?? du Registry dans le Naming Service
348 clt.waitNS("/Registry")
351 # Lancement Catalog Server
353 cataServer=CatalogServer()
354 cataServer.setpath(liste_modules)
358 # 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
366 os.environ["CSF_PluginDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
367 os.environ["CSF_SALOMEDS_ResourcesDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
368 SalomeDSServer().run()
370 if "GEOM" in liste_modules:
371 print("GEOM OCAF Resources")
372 os.environ["CSF_GEOMDS_ResourcesDefaults"] = os.path.join(modules_root_dir["GEOM"], "share", "salome", "resources")
376 # Attente de la disponibilit?? du SalomeDS dans le Naming Service
381 # Lancement Session Server
383 SessionServer().run()
386 # Attente de la disponibilit?? du Session Server dans le Naming Service
389 session=clt.waitNS("/Kernel/Session",SALOME.Session)
392 # Lancement containers
394 theComputer = os.getenv("HOSTNAME")
395 theComputer = theComputer.split('.')[0]
398 # Lancement Container C++ local
400 if with_container_cpp:
401 ContainerCPPServer().run()
403 # Attente de la disponibilit?? du Container C++ local
404 # dans le Naming Service
406 clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
408 # Lancement Container Python local
410 if with_container_python:
411 ContainerPYServer().run()
413 # Attente de la disponibilit?? du Container Python local
414 # dans le Naming Service
416 clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
418 if with_container_superv:
420 # Lancement Container Supervision local
422 ContainerSUPERVServer().run()
424 # Attente de la disponibilit?? du Container Supervision local
425 # dans le Naming Service
427 clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
429 # Activation du GUI de Session Server
431 #session.GetInterface()
433 end_time = os.times()
435 print("Start SALOME, elpased time : %5.1f seconds"% (end_time[4] - init_time[4]))
440 # -----------------------------------------------------------------------------
443 if __name__ == "__main__":
451 print("--- erreur au lancement Salome ---")
456 filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict'
457 #filedict='/tmp/'+os.getlogin()+'_SALOME_pidict'
459 with codecs.open(filedict, 'w') as fpid:
460 pickle.dump(process_id, fpid)
464 Sauvegarde du dictionnaire des process dans , %s
465 Pour tuer les process SALOME, executer : python killSalome.py depuis
466 une console, ou bien killSalome() depuis le present interpreteur,
467 s'il n'est pas ferm??.
469 runHOMARD, avec l'option --killall, commence par tuer les process restants
470 d'une execution pr??c??dente.
472 Pour lancer uniquement le GUI, executer startGUI() depuis le present interpreteur,
473 s'il n'est pas ferm??.
478 # Impression arborescence Naming Service
483 print(" --- registered objects tree in Naming Service ---")
485 session=clt.waitNS("/Kernel/Session")
486 catalog=clt.waitNS("/Kernel/ModulCatalog")
488 container = clt.waitNS("/Containers/" + socket.gethostname().split('.')[0] + "/FactoryServerPy")
490 if os.path.isfile("~/.salome/pystartup"):
491 with codecs.open(os.path.expanduser("~/.salome/pystartup")) as f:
492 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 with codecs.open(os.path.expanduser("~/.salome/pystartup"), 'w') as f:
520 f.write(PYTHONSTARTUP)
522 exec(PYTHONSTARTUP, {})