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
66 if os.path.exists(os.path.join(aster_dir,"share", "aster", "elements")):
67 elements_file = os.path.join(aster_dir,"elements")
68 elif os.path.exists(os.path.join(aster_dir,"elements")):
69 elements_file = os.path.join(aster_dir,"elements")
71 elements_file = os.path.join(aster_dir,"catobj","elements")
72 shutil.copyfile(elements_file,"elem.1")
75 def init_service(self,service):
81 asterCompo=Template(asterCompo)
84 # Par rapport a la version precedente
85 # Chaque service est complete par l'appel initial a Complement
86 # Cette methode rajoute a l'appel du premier service de l'instance un prefixe au fichier de commande
87 # Ce prefixe est fourni dans le fichier fort.99 via as_run et exeaster
88 # Le fichier est lu a la creation du module
89 # Interet: introduire DEBUT() dans ce prefixe pour ne plus avoir a s'en preoccuper (ex: boucle for each)
90 import sys,traceback,os
93 import ${module}_ORB__POA
109 class ExecutionError(Exception):
110 '''General exception during execution'''
112 class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV):
114 To be identified as a SALOME component this Python class
115 must have the same name as the component, inherit omniorb
116 class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent
117 that implements DSC API.
119 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
121 if os.path.isfile('fort.99'):
122 prefixFile = file("fort.99","r")
123 self.prefixJdc = prefixFile.read()
127 dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
129 def init_service(self,service):
133 def insertPrefix(self,jdc):
135 jdc = self.prefixJdc + jdc
138 def insertPrePost(self,jdc,prepost):
142 jdc = os.linesep + pre + os.linesep + jdc + os.linesep + post + os.linesep
147 def interpstring(self,text,args):
149 self.jdc.g_context.update(args)
150 CONTEXT.set_current_step(self.jdc)
151 linecache.cache['<string>']=0,None,string.split(text,'\\n'),'<string>'
152 exec text in self.jdc.const_context,self.jdc.g_context
153 CONTEXT.unset_current_step()
155 CONTEXT.unset_current_step()
157 CONTEXT.unset_current_step()
163 asterEXECompo=asterCEXECompo+"""
165 self._orb.shutdown(0)
168 asterCEXECompo=Template(asterCEXECompo)
169 asterEXECompo=Template(asterEXECompo)
172 def ${service}(self,${inparams}):
173 self.beginService("${component}.${service}")
174 self.jdc=Cata.cata.JdC(procedure=jdc,cata=Cata.cata,nom="Salome",context_ini=${dvars})
176 #modif pour aster 9.0
177 if hasattr(self,"init_timer"):
179 #fin modif pour aster 9.0
181 # On compile le texte Python
184 #modif pour aster 9.0
185 # On initialise les tops de mesure globale de temps d'execution du jdc
186 if hasattr(self,"init_timer"):
187 j.cpu_user=os.times()[0]
188 j.cpu_syst=os.times()[1]
189 #fin modif pour aster 9.0
191 if not j.cr.estvide():
192 msg="ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION"
194 print ">> JDC.py : DEBUT RAPPORT"
196 print ">> JDC.py : FIN RAPPORT"
199 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
201 #surcharge des arguments de la ligne de commande (defaut stocke dans le composant) par un eventuel port de nom argv
203 self.argv=self.argv+argv.split()
207 #initialisation des arguments de la ligne de commande (remplace la methode initexec de B_JDC.py)
208 aster.argv(self.argv)
209 aster.init(CONTEXT.debug)
217 exc_typ,exc_val,exc_fr=sys.exc_info()
218 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
219 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
222 if not j.cr.estvide():
223 msg="ERREUR A L'INTERPRETATION DANS ACCAS - INTERRUPTION"
226 print ">> JDC.py : DEBUT RAPPORT"
228 print ">> JDC.py : FIN RAPPORT"
230 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr), "${component}.py",0))
232 if j.par_lot == 'NON':
233 print "FIN EXECUTION"
234 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
235 #retour sans erreur (il faut pousser les variables de sortie)
237 self.endService("${component}.${service}")
240 # Verification de la validite du jeu de commande
243 msg="ERREUR A LA VERIFICATION SYNTAXIQUE - INTERRUPTION"
245 print ">> JDC.py : DEBUT RAPPORT"
247 print ">> JDC.py : FIN RAPPORT"
249 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(cr),"${component}.py",0))
255 if not j.cr.estvide():
256 msg="ERREUR A L'EXECUTION - INTERRUPTION"
259 print ">> JDC.py : DEBUT RAPPORT"
261 print ">> JDC.py : FIN RAPPORT"
263 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
265 #retour sans erreur (il faut pousser les variables de sortie)
266 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
268 self.endService("${component}.${service}")
271 self.MESSAGE("ERREUR INOPINEE - INTERRUPTION")
273 exc_typ,exc_val,exc_fr=sys.exc_info()
274 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
275 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
277 asterService=Template(asterService)
280 def ${service}(self,${inparams}):
281 self.beginService("${component}.${service}")
284 if not args.has_key("jdc"):
285 fcomm=open("jdc",'r')
289 prepost = '''${body}'''
290 jdc = self.insertPrePost(jdc,prepost)
291 jdc = self.insertPrefix(jdc)
294 fcomm=open("fort.1",'w')
299 raise ExecutionError("Error in initial execution")
301 self.interpstring(jdc,args)
303 self.endService("${component}.${service}")
307 exc_typ,exc_val,exc_fr=sys.exc_info()
308 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
309 self.endService("${component}.${service}")
312 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
314 asterCEXEService=Template(asterCEXEService)
315 asterEXEService=asterCEXEService
320 # Check availability of Aster binary distribution
323 AC_DEFUN([AC_CHECK_ASTER],[
325 AC_CHECKING(for Aster)
330 [AC_HELP_STRING([--with-aster=DIR],[root directory path of Aster installation])],
331 [ASTER_DIR="$withval"],[ASTER_DIR=""])
333 if test -f ${ASTER_DIR}/bin/aster ; then
335 AC_MSG_RESULT(Using Aster distribution in ${ASTER_DIR})
337 ASTER_INCLUDES=-I$ASTER_DIR/include/aster
340 AC_SUBST(ASTER_INCLUDES)
343 AC_MSG_WARN("Cannot find Aster distribution")
346 AC_MSG_RESULT(for Aster: $Aster_ok)
355 make_etude="""P actions make_etude
373 make_etude=Template(make_etude)
375 make_etude_exe="""P actions make_etude
391 make_etude_exe=Template(make_etude_exe)
395 export SALOME_CONTAINERNAME=$$1
401 exeaster="""#!/bin/sh
403 export SALOME_CONTAINER=$$1
404 export SALOME_CONTAINERNAME=$$2
405 export SALOME_INSTANCE=$$3
409 exeaster=Template(exeaster)
411 container="""import sys,os
412 from omniORB import CORBA
413 from SALOME_ContainerPy import SALOME_ContainerPy_i
415 if __name__ == '__main__':
418 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
419 poa = orb.resolve_initial_references("RootPOA")
420 print "ORB and POA initialized"
421 containerName=os.getenv("SALOME_CONTAINERNAME")
422 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
423 print "SALOME_ContainerPy_i instance created ",cpy_i
424 cpy_o = cpy_i._this()
425 print "SALOME_ContainerPy_i instance activated ",cpy_o
430 poaManager = poa._get_the_POAManager()
431 poaManager.activate()
435 print "fin container aster"
440 component="""import sys,os
441 from omniORB import CORBA
442 from ${component}_module import ${component}
444 if __name__ == '__main__':
447 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
448 poa = orb.resolve_initial_references("RootPOA")
449 print "ORB and POA initialized",orb,poa
453 container=orb.string_to_object(os.getenv("SALOME_CONTAINER"))
454 containerName=os.getenv("SALOME_CONTAINERNAME")
455 instanceName=os.getenv("SALOME_INSTANCE")
457 compo=${component}(orb,poa,container,containerName, instanceName, "${component}")
458 comp_o = compo._this()
459 comp_iors = orb.object_to_string(comp_o)
460 print "ior aster",comp_iors
466 poaManager = poa._get_the_POAManager()
467 poaManager.activate()
470 print "fin du composant aster standalone"
473 component=Template(component)