Salome HOME
[EDF29576] : WIP
[modules/yacs.git] / src / yacsloader / driver
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2024  CEA, EDF
4 #
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, or (at your option) any later version.
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 # driver -v -kt micro_schema.xml
23 # driver -d 3 -g 2 --stop-on-error --dump-on-error="popo.xml" -v -kt -i "PyScript0.p1=7" --dump-final="tutu.xml" micro_schema2.xml
24 # driver -g 2 --stop-on-error --dump-on-error="popo.xml" -v -kt -i "PyScript0.p1=7" --dump-final="tutu.xml" micro_schema2.xml
25 # driver -x -g 2 --stop-on-error --dump-on-error="popo.xml" -v -kt -i "PyScript0.p1=7" --dump-final="tutu.xml" micro_schema2.xml
26 # driver -x -g 2 -s -e "popo.xml" -v -kt -i "PyScript0.p1=7" -f "tutu.xml" micro_schema2.xml
27 # driver micro_schema3.xml
28
29 import driver_internal
30 import subprocess as sp
31 import salome
32 import SALOME_Embedded_NamingService_ClientPy
33
34 import signal
35 import SALOMERuntime
36 import os
37
38 proc = None
39 ior_file = None
40
41 def handler(signum, frame):
42   global proc
43   print('Signal handler called with signal', signum, proc.pid)
44   ns = SALOME_Embedded_NamingService_ClientPy.SALOME_Embedded_NamingService_ClientPy( salome.naming_service.LoadIORInFile( ior_file ) )
45   print( ns.repr() )
46   cm = ns.Resolve(salome.CM_NAME_IN_NS)
47   cm.ShutdownContainers()
48   os.kill( proc.pid, signal.SIGKILL )
49
50 if __name__ == "__main__":
51   salome.salome_init()
52   import sys
53   signal.signal(signal.SIGINT, handler)
54   signal.signal(signal.SIGTERM, handler)
55   ior_file = "toto.ior"
56   iorStuff = "{}={}".format( driver_internal.IOREntryInCMD, ior_file)
57   argv = [elt for elt in sys.argv[1:] if elt != ""]
58   proc = sp.Popen( ["python3",driver_internal.__file__] + [ iorStuff ] + argv  )
59   proc.communicate()