Salome HOME
e41f9619425c2aecee579c67624e898ac5dacbc5
[modules/yacs.git] / src / yacsloader / driver.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2024  CEA, EDF
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # python3 /home/H87074/salome/990_CEA/SALOME-master-native-DB11-SRC/SOURCES/yacs/src/yacsloader/driver.py micro_schema.xml
22
23 import loader
24 import SALOMERuntime
25 import salome
26
27 my_runtime_yacs = None
28
29 def initializeSALOME():
30     import SALOMERuntime
31     global my_runtime_yacs
32     if my_runtime_yacs:
33         return
34     salome.salome_init()
35     SALOMERuntime.RuntimeSALOME.setRuntime()
36     my_runtime_yacs = SALOMERuntime.getSALOMERuntime()
37
38 def SALOMEInitializationNeeded(func):
39     def decaratedFunc(*args,**kwargs):
40         initializeSALOME()
41         return func(*args,**kwargs)
42     return decaratedFunc
43
44 @SALOMEInitializationNeeded
45 def loadGraph( xmlFileName ):
46     """
47     Args:
48     -----
49     xmlFileName : XML file containing YACS schema
50
51     Returns
52     -------
53
54     SALOMERuntime.SalomeProc : YACS graph instance
55     """
56     l=loader.YACSLoader()
57     p=l.load( xmlFileName )
58     print(type(p))
59     return p
60
61 @SALOMEInitializationNeeded
62 def executeGraph( proc ):
63     """
64     Args:
65     -----
66
67     proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
68
69     """
70     import pilot
71     ex=pilot.ExecutorSwig()
72     ex.RunW(proc,0)
73     pass
74
75 def destroyElementsGeneratedByExecutionOfGraph():
76     salome.cm
77     my_runtime_yacs.fini( False )
78
79 if __name__ == "__main__":
80     import argparse
81     parser = argparse.ArgumentParser()
82     parser.add_argument('xmlfilename',help="XML file containing YACS schema to be executed")
83     args = parser.parse_args()
84     proc = loadGraph( args.xmlfilename )
85     executeGraph( proc )
86     destroyElementsGeneratedByExecutionOfGraph()
87