1 # Copyright (C) 2009-2015 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 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
321 make_etude="""P actions make_etude
339 make_etude=Template(make_etude)
341 make_etude_exe="""P actions make_etude
357 make_etude_exe=Template(make_etude_exe)
361 export SALOME_CONTAINERNAME=$$1
367 exeaster="""#!/bin/sh
369 export SALOME_CONTAINER=$$1
370 export SALOME_CONTAINERNAME=$$2
371 export SALOME_INSTANCE=$$3
375 exeaster=Template(exeaster)
377 container="""import sys,os
378 from omniORB import CORBA
379 from SALOME_ContainerPy import SALOME_ContainerPy_i
381 if __name__ == '__main__':
384 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
385 poa = orb.resolve_initial_references("RootPOA")
386 print "ORB and POA initialized"
387 containerName=os.getenv("SALOME_CONTAINERNAME")
388 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
389 print "SALOME_ContainerPy_i instance created ",cpy_i
390 cpy_o = cpy_i._this()
391 print "SALOME_ContainerPy_i instance activated ",cpy_o
396 poaManager = poa._get_the_POAManager()
397 poaManager.activate()
401 print "fin container aster"
406 component="""import sys,os
407 from omniORB import CORBA
408 from ${component}_module import ${component}
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",orb,poa
419 container=orb.string_to_object(os.getenv("SALOME_CONTAINER"))
420 containerName=os.getenv("SALOME_CONTAINERNAME")
421 instanceName=os.getenv("SALOME_INSTANCE")
423 compo=${component}(orb,poa,container,containerName, instanceName, "${component}")
424 comp_o = compo._this()
425 comp_iors = orb.object_to_string(comp_o)
426 print "ior aster",comp_iors
432 poaManager = poa._get_the_POAManager()
433 poaManager.activate()
436 print "fin du composant aster standalone"
439 component=Template(component)
441 # CMakeLists.txt in src/<component> for an aster component
442 # template parameters:
443 # sources: source files, separated by spaces
444 # module: module name
445 # resources: files to be installed in resources directory
446 # scripts: scripts to be installed
447 cmake_src_compo_aster="""
462 INSTALL(FILES $${_res_files} DESTINATION $${SALOME_${module}_INSTALL_RES_DATA})
463 SALOME_INSTALL_SCRIPTS("$${_bin_scripts}" $${SALOME_INSTALL_SCRIPT_SCRIPTS})
464 SALOME_INSTALL_SCRIPTS("$${_bin_py}" $${SALOME_INSTALL_PYTHON})
466 cmake_src_compo_aster=Template(cmake_src_compo_aster)
468 # CMakeLists.txt in src/<component> for an aster lib component
469 # template parameters:
470 # sources: source files, separated by spaces
471 cmake_src_compo_aster_lib="""
478 SALOME_INSTALL_SCRIPTS("$${_bin_SCRIPTS}" $${SALOME_INSTALL_PYTHON})
480 cmake_src_compo_aster_lib=Template(cmake_src_compo_aster_lib)