1 # Copyright (C) 2009-2013 EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from string import Template
23 from compat import Template,set
26 import sys,traceback,os
27 import ${module}_ORB__POA
34 sys.path=sys.path+[${python_path}]
38 from Execution.E_SUPERV import SUPERV
40 aster_dir="${aster_dir}"
51 class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV):
53 To be identified as a SALOME component this Python class
54 must have the same name as the component, inherit omniorb
55 class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent
56 that implements DSC API.
58 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
59 dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
62 if hasattr(self,"init_timer"):
64 #fin modif pour aster 9.0
65 if os.path.exists(os.path.join(aster_dir,"elements")):
66 shutil.copyfile(os.path.join(aster_dir,"elements"),"elem.1")
68 shutil.copyfile(os.path.join(aster_dir,"catobj","elements"),"elem.1")
70 def init_service(self,service):
76 asterCompo=Template(asterCompo)
79 # Par rapport a la version precedente
80 # Chaque service est complete par l'appel initial a Complement
81 # Cette methode rajoute a l'appel du premier service de l'instance un prefixe au fichier de commande
82 # Ce prefixe est fourni dans le fichier fort.99 via as_run et exeaster
83 # Le fichier est lu a la creation du module
84 # Interet: introduire DEBUT() dans ce prefixe pour ne plus avoir a s'en preoccuper (ex: boucle for each)
85 import sys,traceback,os
88 import ${module}_ORB__POA
104 class ExecutionError(Exception):
105 '''General exception during execution'''
107 class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV):
109 To be identified as a SALOME component this Python class
110 must have the same name as the component, inherit omniorb
111 class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent
112 that implements DSC API.
114 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
116 if os.path.isfile('fort.99'):
117 prefixFile = file("fort.99","r")
118 self.prefixJdc = prefixFile.read()
122 dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
124 def init_service(self,service):
128 def insertPrefix(self,jdc):
130 jdc = self.prefixJdc + jdc
133 def insertPrePost(self,jdc,prepost):
137 jdc = os.linesep + pre + os.linesep + jdc + os.linesep + post + os.linesep
142 def interpstring(self,text,args):
144 self.jdc.g_context.update(args)
145 CONTEXT.set_current_step(self.jdc)
146 linecache.cache['<string>']=0,None,string.split(text,'\\n'),'<string>'
147 exec text in self.jdc.const_context,self.jdc.g_context
148 CONTEXT.unset_current_step()
150 CONTEXT.unset_current_step()
152 CONTEXT.unset_current_step()
158 asterEXECompo=asterCEXECompo+"""
160 self._orb.shutdown(0)
163 asterCEXECompo=Template(asterCEXECompo)
164 asterEXECompo=Template(asterEXECompo)
167 def ${service}(self,${inparams}):
168 self.beginService("${component}.${service}")
169 self.jdc=Cata.cata.JdC(procedure=jdc,cata=Cata.cata,nom="Salome",context_ini=${dvars})
171 #modif pour aster 9.0
172 if hasattr(self,"init_timer"):
174 #fin modif pour aster 9.0
176 # On compile le texte Python
179 #modif pour aster 9.0
180 # On initialise les tops de mesure globale de temps d'execution du jdc
181 if hasattr(self,"init_timer"):
182 j.cpu_user=os.times()[0]
183 j.cpu_syst=os.times()[1]
184 #fin modif pour aster 9.0
186 if not j.cr.estvide():
187 msg="ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION"
189 print ">> JDC.py : DEBUT RAPPORT"
191 print ">> JDC.py : FIN RAPPORT"
194 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
196 #surcharge des arguments de la ligne de commande (defaut stocke dans le composant) par un eventuel port de nom argv
198 self.argv=self.argv+argv.split()
202 #initialisation des arguments de la ligne de commande (remplace la methode initexec de B_JDC.py)
203 aster.argv(self.argv)
204 aster.init(CONTEXT.debug)
212 exc_typ,exc_val,exc_fr=sys.exc_info()
213 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
214 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
217 if not j.cr.estvide():
218 msg="ERREUR A L'INTERPRETATION DANS ACCAS - INTERRUPTION"
221 print ">> JDC.py : DEBUT RAPPORT"
223 print ">> JDC.py : FIN RAPPORT"
225 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr), "${component}.py",0))
227 if j.par_lot == 'NON':
228 print "FIN EXECUTION"
229 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
230 #retour sans erreur (il faut pousser les variables de sortie)
232 self.endService("${component}.${service}")
235 # Verification de la validite du jeu de commande
238 msg="ERREUR A LA VERIFICATION SYNTAXIQUE - INTERRUPTION"
240 print ">> JDC.py : DEBUT RAPPORT"
242 print ">> JDC.py : FIN RAPPORT"
244 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(cr),"${component}.py",0))
250 if not j.cr.estvide():
251 msg="ERREUR A L'EXECUTION - INTERRUPTION"
254 print ">> JDC.py : DEBUT RAPPORT"
256 print ">> JDC.py : FIN RAPPORT"
258 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
260 #retour sans erreur (il faut pousser les variables de sortie)
261 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
263 self.endService("${component}.${service}")
266 self.MESSAGE("ERREUR INOPINEE - INTERRUPTION")
268 exc_typ,exc_val,exc_fr=sys.exc_info()
269 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
270 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
272 asterService=Template(asterService)
275 def ${service}(self,${inparams}):
276 self.beginService("${component}.${service}")
279 if not args.has_key("jdc"):
280 fcomm=open("jdc",'r')
284 prepost = '''${body}'''
285 jdc = self.insertPrePost(jdc,prepost)
286 jdc = self.insertPrefix(jdc)
289 fcomm=open("fort.1",'w')
294 raise ExecutionError("Error in initial execution")
296 self.interpstring(jdc,args)
298 self.endService("${component}.${service}")
302 exc_typ,exc_val,exc_fr=sys.exc_info()
303 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
304 self.endService("${component}.${service}")
307 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
309 asterCEXEService=Template(asterCEXEService)
310 asterEXEService=asterCEXEService
315 # Check availability of Aster binary distribution
318 AC_DEFUN([AC_CHECK_ASTER],[
320 AC_CHECKING(for Aster)
325 [AC_HELP_STRING([--with-aster=DIR],[root directory path of Aster installation])],
326 [ASTER_DIR="$withval"],[ASTER_DIR=""])
328 if test -f ${ASTER_DIR}/asteru ; then
330 AC_MSG_RESULT(Using Aster distribution in ${ASTER_DIR})
332 ASTER_INCLUDES=-I$ASTER_DIR/bibc/include
335 AC_SUBST(ASTER_INCLUDES)
338 AC_MSG_WARN("Cannot find Aster distribution")
341 AC_MSG_RESULT(for Aster: $Aster_ok)
350 make_etude="""P actions make_etude
368 make_etude=Template(make_etude)
370 make_etude_exe="""P actions make_etude
386 make_etude_exe=Template(make_etude_exe)
390 export SALOME_CONTAINERNAME=$$1
396 exeaster="""#!/bin/sh
398 export SALOME_CONTAINER=$$1
399 export SALOME_CONTAINERNAME=$$2
400 export SALOME_INSTANCE=$$3
404 exeaster=Template(exeaster)
406 container="""import sys,os
407 from omniORB import CORBA
408 from SALOME_ContainerPy import SALOME_ContainerPy_i
410 if __name__ == '__main__':
413 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
414 poa = orb.resolve_initial_references("RootPOA")
415 print "ORB and POA initialized"
416 containerName=os.getenv("SALOME_CONTAINERNAME")
417 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
418 print "SALOME_ContainerPy_i instance created ",cpy_i
419 cpy_o = cpy_i._this()
420 print "SALOME_ContainerPy_i instance activated ",cpy_o
425 poaManager = poa._get_the_POAManager()
426 poaManager.activate()
430 print "fin container aster"
435 component="""import sys,os
436 from omniORB import CORBA
437 from ${component}_module import ${component}
439 if __name__ == '__main__':
442 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
443 poa = orb.resolve_initial_references("RootPOA")
444 print "ORB and POA initialized",orb,poa
448 container=orb.string_to_object(os.getenv("SALOME_CONTAINER"))
449 containerName=os.getenv("SALOME_CONTAINERNAME")
450 instanceName=os.getenv("SALOME_INSTANCE")
452 compo=${component}(orb,poa,container,containerName, instanceName, "${component}")
453 comp_o = compo._this()
454 comp_iors = orb.object_to_string(comp_o)
455 print "ior aster",comp_iors
461 poaManager = poa._get_the_POAManager()
462 poaManager.activate()
465 print "fin du composant aster standalone"
468 component=Template(component)