From 78072e1b5bc2f2690c99d9a83072b0fecac141b6 Mon Sep 17 00:00:00 2001 From: dutka Date: Thu, 7 Oct 2004 07:40:12 +0000 Subject: [PATCH] =?utf8?q?Biblioth=C3=A8que=20de=20classes=20Batch=20(new)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/Batch_SWIG/Batch_test.py | 53 ++++++ src/Batch_SWIG/Makefile.in | 49 ++++++ src/Batch_SWIG/libBatch_Swig.i | 59 +++++++ src/Batch_SWIG/libBatch_Swig_exception.i | 24 +++ src/Batch_SWIG/libBatch_Swig_typemap.i | 213 +++++++++++++++++++++++ src/Makefile.in | 4 + 6 files changed, 402 insertions(+) create mode 100644 src/Batch_SWIG/Batch_test.py create mode 100644 src/Batch_SWIG/Makefile.in create mode 100644 src/Batch_SWIG/libBatch_Swig.i create mode 100644 src/Batch_SWIG/libBatch_Swig_exception.i create mode 100644 src/Batch_SWIG/libBatch_Swig_typemap.i diff --git a/src/Batch_SWIG/Batch_test.py b/src/Batch_SWIG/Batch_test.py new file mode 100644 index 000000000..b90cbc14d --- /dev/null +++ b/src/Batch_SWIG/Batch_test.py @@ -0,0 +1,53 @@ +#Batch_test.py + +# pratique +import readline +import rlcompleter +readline.parse_and_bind('tab: complete') + +# Importation de la bibliotheque de classes Batch +from libBatch_Swig import * + +def work(): + # Definition d'un job... + job=Job() + # ... de ses parametres ... + p={} + p['EXECUTABLE']='/home/dutka/tmp/job' + p['NAME']='MonJob' + p['OUTFILE']=[('/tmp/stdout', 'stdout'), ('/tmp/stderr', 'stderr')] + job.setParametre(p) + # ... et de son environnement + job.setEnvironnement({}) + print job + + # Appel au catalogue de BatchManager pour accéder au serveur cli70cu + # Instanciation du catalogue (quasi-singleton) + c=BatchManagerCatalog() + # Instanciation d'une Factory de BatchManager de type 'PBS' + # fbm=c('PBS') + + # Creation d'un BatchManager de type PBS sur le serveur cli70cu + bm=c('PBS')('cli70cu') + + # Soumission du job au BatchManager + jobid=bm.submitJob(job) + print jobid + + # Interrogation de l'etat du job + jobid.queryJob() + + # On attend que le job soit termine + try: + while 1: jinfo = jobid.queryJob() + except: + print "Job", jobid, "is done" + + pass + +if __name__ == "__main__": + work() + pass + + + diff --git a/src/Batch_SWIG/Makefile.in b/src/Batch_SWIG/Makefile.in new file mode 100644 index 000000000..89d6c9731 --- /dev/null +++ b/src/Batch_SWIG/Makefile.in @@ -0,0 +1,49 @@ +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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. +# +# 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# Libraries targets + +LIB = libBatch_Swigcmodule.la +LIB_SRC = + +SWIG_DEF = libBatch_Swig.i +EXPORT_PYSCRIPTS = libBatch_Swig.py Batch_test.py + +CPPFLAGS += $(PYTHON_INCLUDES) $(OPENPBS_INCLUDES) + +LDFLAGS += $(OPENPBS_LIBDIR) + +LIBS += $(PYTHON_LIBS) $(OPENPBS_LIBS) -lSalomeBatch + +@CONCLUDE@ diff --git a/src/Batch_SWIG/libBatch_Swig.i b/src/Batch_SWIG/libBatch_Swig.i new file mode 100644 index 000000000..1f82f0dfa --- /dev/null +++ b/src/Batch_SWIG/libBatch_Swig.i @@ -0,0 +1,59 @@ +/* + * libBatch_Swig.i : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +/* ATTENTION: + ========== + Certaines classes ont des methodes surchargees et SWIG ne gere pas bien + ces surcharges, d'ou un probleme d'utilisation en Python de celles-ci. + En bref, ça ne marche pas et il faudra corriger le probleme... + + TODO : corriger le probleme de surcharge des methodes en Python + + IDM. +*/ + + +/* Le nom du module Python tel qu'il est importe */ +%module libBatch_Swig + +/* Inclusion des conversions de type */ +%include libBatch_Swig_typemap.i + +/* Inclusion de la gestion des exceptions */ +%include libBatch_Swig_exception.i + +%{ +#include "Batch_Job.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" + +#include "Batch_BatchManager.hxx" +#include "Batch_BatchManagerCatalog.hxx" +#include "Batch_FactBatchManager.hxx" +using namespace Batch; +%} + +/* Les classes exportees en Python */ +%include Batch_Job.hxx +%include Batch_JobId.hxx +%include Batch_JobInfo.hxx + +%include Batch_BatchManager.hxx +%include Batch_BatchManagerCatalog.hxx +%include Batch_FactBatchManager.hxx + + + +/* Les methodes alterJob (surchargees et mal gerees en Python) sont + remplacees par des methodes setParametre et setEnvironnement. + cf. remarque ci-dessus. +*/ +%ignore JobId::alterJob(const Parametre & param, const Environnement & env) const; +%ignore JobId::alterJob(const Parametre & param) const; +%ignore JobId::alterJob(const Environnement & env) const; diff --git a/src/Batch_SWIG/libBatch_Swig_exception.i b/src/Batch_SWIG/libBatch_Swig_exception.i new file mode 100644 index 000000000..880ae9085 --- /dev/null +++ b/src/Batch_SWIG/libBatch_Swig_exception.i @@ -0,0 +1,24 @@ +/* + * _exception.i : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +%exception { + try { + $action + } + catch (GenericException & ex) { + string msg = ex.type + " : " + ex.message; + PyErr_SetString(PyExc_RuntimeWarning, msg.c_str()); + return NULL; + } + catch (...) { + PyErr_SetString(PyExc_RuntimeWarning, "unknown exception"); + return NULL; + } +} + diff --git a/src/Batch_SWIG/libBatch_Swig_typemap.i b/src/Batch_SWIG/libBatch_Swig_typemap.i new file mode 100644 index 000000000..9116e8798 --- /dev/null +++ b/src/Batch_SWIG/libBatch_Swig_typemap.i @@ -0,0 +1,213 @@ +/* + * _typemap.i : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +%{ +#include +#include +#include +#include "Batch_Parametre.hxx" +#include "Batch_PyVersatile.hxx" +#include "Batch_JobId.hxx" +#include "Batch_FactBatchManager.hxx" +%} + +# // supprime toutes les definitions par defaut => sert au debug +# %typemap(in) SWIGTYPE ; + + +# // construction d'un dictionnaire Python a partir d'un objet BatchManagerCatalog C++ +%typemap(out) map * +{ + $result = PyDict_New(); + + // on itere sur toutes les clefs de la map + for(map::const_iterator it=(* $1).begin(); it!=(* $1).end(); it++) { + string key = (*it).first; + PyObject * obj = SWIG_NewPointerObj((void *) (*it).second, SWIGTYPE_p_Batch__FactBatchManager, 0); + PyDict_SetItem($result, PyString_FromString(key.c_str()), obj); + } +} + + +# // construction d'un dictionnaire Python a partir d'un objet Parametre C++ +%typemap(out) Parametre +{ + $result = PyDict_New(); + + // on itere sur toutes les clefs de la map, et on passe par la classe PyVersatile + // qui convertit un Versatile en PyObject et vice versa + for(Parametre::const_iterator it=$1.begin(); it!=$1.end(); it++) { + string key = (*it).first; + PyVersatile PyV = (*it).second; + PyDict_SetItem($result, PyString_FromString(key.c_str()), PyV); + } +} + + +# // construction d'un objet Parametre C++ a partir d'un dictionnaire Python +%typemap(in) Parametre & (Parametre PM) +{ + if (!PyDict_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a dictionnary"); + return NULL; + } + + try { + // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile + // qui convertit un Versatile en PyObject et vice versa + PyObject *key, *value; + int pos = 0; + while (PyDict_Next($input, &pos, &key, &value)) { + string mk = PyString_AsString(key); + PyVersatile PyV = value; + PyV.setName(mk); + PM[mk] = PyV; + } + + $1 = ± // $1 est une reference donc on lui passe une adresse + } + catch (GenericException & ex) { + string msg = ex.type + " : " + ex.message; + PyErr_SetString(PyExc_RuntimeWarning, msg.c_str()); + return NULL; + } + catch (...) { + PyErr_SetString(PyExc_RuntimeWarning, "unknown exception"); + return NULL; + } +} + + +# // construction d'un objet Parametre C++ a partir d'un dictionnaire Python +%typemap(in) Parametre (Parametre PM) +{ + if (!PyDict_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a dictionnary"); + return NULL; + } + + try { + // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile + // qui convertit un Versatile en PyObject et vice versa + PyObject *key, *value; + int pos = 0; + while (PyDict_Next($input, &pos, &key, &value)) { + string mk = PyString_AsString(key); + PyVersatile PyV = value; + PyV.setName(mk); + PM[mk] = PyV; + } + + $1 = PM; + } + catch (GenericException & ex) { + string msg = ex.type + " : " + ex.message; + PyErr_SetString(PyExc_RuntimeWarning, msg.c_str()); + return NULL; + } + catch (...) { + PyErr_SetString(PyExc_RuntimeWarning, "unknown exception"); + return NULL; + } +} + + +# // construction d'un dictionnaire Python a partir d'un objet Environnement C++ +%typemap(out) Environnement +{ + $result = PyDict_New(); + + // on itere sur toutes les clefs de la map + for(Environnement::const_iterator it=$1.begin(); it!=$1.end(); it++) { + string key = (*it).first; + string val = (*it).second; + PyDict_SetItem($result, + PyString_FromString(key.c_str()), + PyString_FromString(val.c_str())); + } +} + + +# // construction d'un objet Environnement C++ a partir d'un dictionnaire Python +%typemap(in) Environnement & (Environnement E) +{ + if (!PyDict_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a dictionnary"); + return NULL; + } + + // on itere sur toutes les clefs du dictionnaire + PyObject *key, *value; + int pos = 0; + while (PyDict_Next($input, &pos, &key, &value)) { + string mk = PyString_AsString(key); + string val = PyString_AsString(value); + E[mk] = val; + } + + $1 = &E; // $1 est une reference donc on lui passe une adresse +} + + + +# // construction d'un objet Environnement C++ a partir d'un dictionnaire Python +%typemap(in) Environnement (Environnement E) +{ + if (!PyDict_Check($input)) { + PyErr_SetString(PyExc_ValueError,"Expected a dictionnary"); + return NULL; + } + + // on itere sur toutes les clefs du dictionnaire + PyObject *key, *value; + int pos = 0; + while (PyDict_Next($input, &pos, &key, &value)) { + string mk = PyString_AsString(key); + string val = PyString_AsString(value); + E[mk] = val; + } + + $1 = E; +} + + + +# // construction d'une string Python a partir d'une string STL +%typemap(python,out) string +{ + $result = PyString_FromString($1.c_str()); +} + + + +# // construction d'une string STL a partir d'une string Python +#%typemap(in) string & (string S) +#{ +## if (!PyString_Check($input)) { +# PyErr_SetString(PyExc_ValueError,"Expected a string"); +# return NULL; +# } +# +# S = string(PyString_AsString($input)); +# $1 = &S; // $1 est une reference donc on lui passe une adresse +#} + + + +# // construction d'une string STL a partir d'une string Python +#%typemap(in) string (string S) +#{ +## if (!PyString_Check($input)) { +# PyErr_SetString(PyExc_ValueError,"Expected a string"); +# return NULL; +# } +# +# S = string(PyString_AsString($input)); +# $1 = S; +#} diff --git a/src/Makefile.in b/src/Makefile.in index 5c3530e4b..687bb2365 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -44,6 +44,10 @@ SUBDIRS = MSG2QM SALOMELocalTrace Logger SALOMELogger Utils PatchQt \ Session SALOME_SWIG TOOLSGUI SALOME_PY \ RegistryDisplay ModuleGenerator SALOME_PYQT Loader +ifeq (@WITHOPENPBS@,yes) + SUBDIRS += Batch Batch_SWIG +endif + ifeq (@WITHMPICH@,yes) SUBDIRS+= MPIContainer endif -- 2.39.2