1 # Copyright (C) 2009-2012 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 import sys,traceback,os
81 import ${module}_ORB__POA
97 class ExecutionError(Exception):
98 '''General exception during execution'''
100 class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV):
102 To be identified as a SALOME component this Python class
103 must have the same name as the component, inherit omniorb
104 class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent
105 that implements DSC API.
107 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
109 dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
111 def init_service(self,service):
115 def interpstring(self,text,args):
117 self.jdc.g_context.update(args)
118 CONTEXT.set_current_step(self.jdc)
119 linecache.cache['<string>']=0,None,string.split(text,'\\n'),'<string>'
120 exec text in self.jdc.const_context,self.jdc.g_context
121 CONTEXT.unset_current_step()
123 CONTEXT.unset_current_step()
125 CONTEXT.unset_current_step()
131 asterEXECompo=asterCEXECompo+"""
133 self._orb.shutdown(0)
136 asterCEXECompo=Template(asterCEXECompo)
137 asterEXECompo=Template(asterEXECompo)
140 def ${service}(self,${inparams}):
141 self.beginService("${component}.${service}")
142 self.jdc=Cata.cata.JdC(procedure=jdc,cata=Cata.cata,nom="Salome",context_ini=${dvars})
144 #modif pour aster 9.0
145 if hasattr(self,"init_timer"):
147 #fin modif pour aster 9.0
149 # On compile le texte Python
152 #modif pour aster 9.0
153 # On initialise les tops de mesure globale de temps d'execution du jdc
154 if hasattr(self,"init_timer"):
155 j.cpu_user=os.times()[0]
156 j.cpu_syst=os.times()[1]
157 #fin modif pour aster 9.0
159 if not j.cr.estvide():
160 msg="ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION"
162 print ">> JDC.py : DEBUT RAPPORT"
164 print ">> JDC.py : FIN RAPPORT"
167 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
169 #surcharge des arguments de la ligne de commande (defaut stocke dans le composant) par un eventuel port de nom argv
171 self.argv=self.argv+argv.split()
175 #initialisation des arguments de la ligne de commande (remplace la methode initexec de B_JDC.py)
176 aster.argv(self.argv)
177 aster.init(CONTEXT.debug)
185 exc_typ,exc_val,exc_fr=sys.exc_info()
186 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
187 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
190 if not j.cr.estvide():
191 msg="ERREUR A L'INTERPRETATION DANS ACCAS - INTERRUPTION"
194 print ">> JDC.py : DEBUT RAPPORT"
196 print ">> JDC.py : FIN RAPPORT"
198 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr), "${component}.py",0))
200 if j.par_lot == 'NON':
201 print "FIN EXECUTION"
202 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
203 #retour sans erreur (il faut pousser les variables de sortie)
205 self.endService("${component}.${service}")
208 # Verification de la validite du jeu de commande
211 msg="ERREUR A LA VERIFICATION SYNTAXIQUE - INTERRUPTION"
213 print ">> JDC.py : DEBUT RAPPORT"
215 print ">> JDC.py : FIN RAPPORT"
217 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(cr),"${component}.py",0))
223 if not j.cr.estvide():
224 msg="ERREUR A L'EXECUTION - INTERRUPTION"
227 print ">> JDC.py : DEBUT RAPPORT"
229 print ">> JDC.py : FIN RAPPORT"
231 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
233 #retour sans erreur (il faut pousser les variables de sortie)
234 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
236 self.endService("${component}.${service}")
239 self.MESSAGE("ERREUR INOPINEE - INTERRUPTION")
241 exc_typ,exc_val,exc_fr=sys.exc_info()
242 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
243 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
245 asterService=Template(asterService)
248 def ${service}(self,${inparams}):
249 self.beginService("${component}.${service}")
252 if not args.has_key("jdc"):
253 fcomm=open("jdc",'r')
259 fcomm=open("fort.1",'w')
264 raise ExecutionError("Error in initial execution")
266 self.interpstring(jdc,args)
268 self.endService("${component}.${service}")
272 exc_typ,exc_val,exc_fr=sys.exc_info()
273 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
274 self.endService("${component}.${service}")
277 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
279 asterCEXEService=Template(asterCEXEService)
280 asterEXEService=asterCEXEService
285 # Check availability of Aster binary distribution
288 AC_DEFUN([AC_CHECK_ASTER],[
290 AC_CHECKING(for Aster)
295 [AC_HELP_STRING([--with-aster=DIR],[root directory path of Aster installation])],
296 [ASTER_DIR="$withval"],[ASTER_DIR=""])
298 if test -f ${ASTER_DIR}/asteru ; then
300 AC_MSG_RESULT(Using Aster distribution in ${ASTER_DIR})
302 ASTER_INCLUDES=-I$ASTER_DIR/bibc/include
305 AC_SUBST(ASTER_INCLUDES)
308 AC_MSG_WARN("Cannot find Aster distribution")
311 AC_MSG_RESULT(for Aster: $Aster_ok)
320 make_etude="""P actions make_etude
338 make_etude=Template(make_etude)
340 make_etude_exe="""P actions make_etude
356 make_etude_exe=Template(make_etude_exe)
360 export SALOME_CONTAINERNAME=$$1
366 exeaster="""#!/bin/sh
368 export SALOME_CONTAINER=$$1
369 export SALOME_CONTAINERNAME=$$2
370 export SALOME_INSTANCE=$$3
374 exeaster=Template(exeaster)
376 container="""import sys,os
377 from omniORB import CORBA
378 from SALOME_ContainerPy import SALOME_ContainerPy_i
380 if __name__ == '__main__':
383 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
384 poa = orb.resolve_initial_references("RootPOA")
385 print "ORB and POA initialized"
386 containerName=os.getenv("SALOME_CONTAINERNAME")
387 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
388 print "SALOME_ContainerPy_i instance created ",cpy_i
389 cpy_o = cpy_i._this()
390 print "SALOME_ContainerPy_i instance activated ",cpy_o
395 poaManager = poa._get_the_POAManager()
396 poaManager.activate()
400 print "fin container aster"
405 component="""import sys,os
406 from omniORB import CORBA
407 from ${component}_module import ${component}
409 if __name__ == '__main__':
412 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
413 poa = orb.resolve_initial_references("RootPOA")
414 print "ORB and POA initialized",orb,poa
418 container=orb.string_to_object(os.getenv("SALOME_CONTAINER"))
419 containerName=os.getenv("SALOME_CONTAINERNAME")
420 instanceName=os.getenv("SALOME_INSTANCE")
422 compo=${component}(orb,poa,container,containerName, instanceName, "${component}")
423 comp_o = compo._this()
424 comp_iors = orb.object_to_string(comp_o)
425 print "ior aster",comp_iors
431 poaManager = poa._get_the_POAManager()
432 poaManager.activate()
435 print "fin du composant aster standalone"
438 component=Template(component)