1 # Copyright (C) 2009-2021 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, or (at your option) any later version.
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 module_generator.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
92 import ${module}_ORB__POA
108 class ExecutionError(Exception):
109 '''General exception during execution'''
111 class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV):
113 To be identified as a SALOME component this Python class
114 must have the same name as the component, inherit omniorb
115 class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent
116 that implements DSC API.
118 def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
120 if os.path.isfile('fort.99'):
121 prefixFile = file("fort.99","r")
122 self.prefixJdc = prefixFile.read()
126 dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
128 def init_service(self,service):
132 def insertPrefix(self,jdc):
134 jdc = self.prefixJdc + jdc
137 def insertPrePost(self,jdc,prepost):
141 jdc = os.linesep + pre + os.linesep + jdc + os.linesep + post + os.linesep
146 def interpstring(self,text,args):
148 self.jdc.g_context.update(args)
149 CONTEXT.set_current_step(self.jdc)
150 linecache.cache['<string>']=0,None,string.split(text,'\\n'),'<string>'
151 exec(text in self.jdc.const_context,self.jdc.g_context)
152 CONTEXT.unset_current_step()
154 CONTEXT.unset_current_step()
156 CONTEXT.unset_current_step()
162 asterEXECompo=asterCEXECompo+"""
164 self._orb.shutdown(0)
167 asterCEXECompo=Template(asterCEXECompo)
168 asterEXECompo=Template(asterEXECompo)
171 def ${service}(self,${inparams}):
172 self.beginService("${component}.${service}")
173 self.jdc=Cata.cata.JdC(procedure=jdc,cata=Cata.cata,nom="Salome",context_ini=${dvars})
175 #modif pour aster 9.0
176 if hasattr(self,"init_timer"):
178 #fin modif pour aster 9.0
180 # On compile le texte Python
183 #modif pour aster 9.0
184 # On initialise les tops de mesure globale de temps d'execution du jdc
185 if hasattr(self,"init_timer"):
186 j.cpu_user=os.times()[0]
187 j.cpu_syst=os.times()[1]
188 #fin modif pour aster 9.0
190 if not j.cr.estvide():
191 msg="ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION"
193 print (">> JDC.py : DEBUT RAPPORT")
195 print (">> JDC.py : FIN RAPPORT")
198 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
200 #surcharge des arguments de la ligne de commande (defaut stocke dans le composant) par un eventuel port de nom argv
202 self.argv=self.argv+argv.split()
206 #initialisation des arguments de la ligne de commande (remplace la methode initexec de B_JDC.py)
207 aster.argv(self.argv)
208 aster.init(CONTEXT.debug)
216 exc_typ,exc_val,exc_fr=sys.exc_info()
217 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
218 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
221 if not j.cr.estvide():
222 msg="ERREUR A L'INTERPRETATION DANS ACCAS - INTERRUPTION"
225 print (">> JDC.py : DEBUT RAPPORT")
227 print (">> JDC.py : FIN RAPPORT")
229 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr), "${component}.py",0))
231 if j.par_lot == 'NON':
232 print ("FIN EXECUTION")
233 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
234 #retour sans erreur (il faut pousser les variables de sortie)
236 self.endService("${component}.${service}")
239 # Verification de la validite du jeu de commande
242 msg="ERREUR A LA VERIFICATION SYNTAXIQUE - INTERRUPTION"
244 print( ">> JDC.py : DEBUT RAPPORT")
246 print( ">> JDC.py : FIN RAPPORT")
248 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(cr),"${component}.py",0))
254 if not j.cr.estvide():
255 msg="ERREUR A L'EXECUTION - INTERRUPTION"
258 print( ">> JDC.py : DEBUT RAPPORT")
260 print( ">> JDC.py : FIN RAPPORT")
262 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
264 #retour sans erreur (il faut pousser les variables de sortie)
265 #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
267 self.endService("${component}.${service}")
270 self.MESSAGE("ERREUR INOPINEE - INTERRUPTION")
272 exc_typ,exc_val,exc_fr=sys.exc_info()
273 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
274 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
276 asterService=Template(asterService)
279 def ${service}(self,${inparams}):
280 self.beginService("${component}.${service}")
283 if "jdc" not in args:
284 fcomm=open("jdc",'r')
288 prepost = '''${body}'''
289 jdc = self.insertPrePost(jdc,prepost)
290 jdc = self.insertPrefix(jdc)
293 fcomm=open("fort.1",'w')
298 raise ExecutionError("Error in initial execution")
300 self.interpstring(jdc,args)
302 self.endService("${component}.${service}")
306 exc_typ,exc_val,exc_fr=sys.exc_info()
307 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
308 self.endService("${component}.${service}")
311 raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"${component}.py",0))
313 asterCEXEService=Template(asterCEXEService)
314 asterEXEService=asterCEXEService
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)
440 # CMakeLists.txt in src/<component> for an aster component
441 # template parameters:
442 # sources: source files, separated by spaces
443 # module: module name
444 # resources: files to be installed in resources directory
445 # scripts: scripts to be installed
446 cmake_src_compo_aster="""
461 INSTALL(FILES $${_res_files} DESTINATION $${SALOME_${module}_INSTALL_RES_DATA})
462 SALOME_INSTALL_SCRIPTS("$${_bin_scripts}" $${SALOME_INSTALL_SCRIPT_SCRIPTS})
463 SALOME_INSTALL_SCRIPTS("$${_bin_py}" $${SALOME_INSTALL_PYTHON})
465 cmake_src_compo_aster=Template(cmake_src_compo_aster)
467 # CMakeLists.txt in src/<component> for an aster lib component
468 # template parameters:
469 # sources: source files, separated by spaces
470 cmake_src_compo_aster_lib="""
477 SALOME_INSTALL_SCRIPTS("$${_bin_SCRIPTS}" $${SALOME_INSTALL_PYTHON})
479 cmake_src_compo_aster_lib=Template(cmake_src_compo_aster_lib)