Salome HOME
[EDF28974] : Let s go for python3 porting of driver
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 22 Feb 2024 10:40:12 +0000 (11:40 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 22 Feb 2024 10:40:12 +0000 (11:40 +0100)
src/runtime/RuntimeSALOME.cxx
src/runtime/RuntimeSALOME.hxx
src/yacsloader/driver.py [new file with mode: 0644]

index 20d20215073b790f601a4fcf2978bbbe86cec03a..c8ea03c2877a216b2e182dd17b8ef58a16a240a9 100644 (file)
@@ -420,7 +420,7 @@ void RuntimeSALOME::init(long flags, int argc, char* argv[])
     }
 }
 
-void RuntimeSALOME::fini()
+void RuntimeSALOME::fini(bool isFinalizingPython)
 {
   if (_usePython)
     {
@@ -449,8 +449,9 @@ void RuntimeSALOME::fini()
       nodeMap.erase("PyFunction");
       nodeMap.erase("PyScript");
       nodeMap.erase("SalomePythonNode");
-
-      Py_Finalize();
+      
+      if( isFinalizingPython )
+        Py_Finalize();
 #ifdef REFCNT
       DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
 #endif
index 4cbbc12c315cf74213717183184d4be213fe8851..a9c32672358d462dba309556af6b9abbe2a56cb8 100644 (file)
@@ -83,7 +83,7 @@ namespace YACS
       virtual std::string getVersion() const;
 
       virtual void init(long flags, int argc, char* argv[]);
-      virtual void fini();
+      virtual void fini(bool isFinalizingPython = true);
       PyObject *launchSubProcess(const std::vector<std::string>& cmds);
       virtual std::vector< std::pair<std::string,int> > getCatalogOfComputeNodes() const;
       virtual InputPort* createInputPort(const std::string& name,
diff --git a/src/yacsloader/driver.py b/src/yacsloader/driver.py
new file mode 100644 (file)
index 0000000..e41f961
--- /dev/null
@@ -0,0 +1,87 @@
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# python3 /home/H87074/salome/990_CEA/SALOME-master-native-DB11-SRC/SOURCES/yacs/src/yacsloader/driver.py micro_schema.xml
+
+import loader
+import SALOMERuntime
+import salome
+
+my_runtime_yacs = None
+
+def initializeSALOME():
+    import SALOMERuntime
+    global my_runtime_yacs
+    if my_runtime_yacs:
+        return
+    salome.salome_init()
+    SALOMERuntime.RuntimeSALOME.setRuntime()
+    my_runtime_yacs = SALOMERuntime.getSALOMERuntime()
+
+def SALOMEInitializationNeeded(func):
+    def decaratedFunc(*args,**kwargs):
+        initializeSALOME()
+        return func(*args,**kwargs)
+    return decaratedFunc
+
+@SALOMEInitializationNeeded
+def loadGraph( xmlFileName ):
+    """
+    Args:
+    -----
+    xmlFileName : XML file containing YACS schema
+
+    Returns
+    -------
+
+    SALOMERuntime.SalomeProc : YACS graph instance
+    """
+    l=loader.YACSLoader()
+    p=l.load( xmlFileName )
+    print(type(p))
+    return p
+
+@SALOMEInitializationNeeded
+def executeGraph( proc ):
+    """
+    Args:
+    -----
+
+    proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
+
+    """
+    import pilot
+    ex=pilot.ExecutorSwig()
+    ex.RunW(proc,0)
+    pass
+
+def destroyElementsGeneratedByExecutionOfGraph():
+    salome.cm
+    my_runtime_yacs.fini( False )
+
+if __name__ == "__main__":
+    import argparse
+    parser = argparse.ArgumentParser()
+    parser.add_argument('xmlfilename',help="XML file containing YACS schema to be executed")
+    args = parser.parse_args()
+    proc = loadGraph( args.xmlfilename )
+    executeGraph( proc )
+    destroyElementsGeneratedByExecutionOfGraph()
+