Salome HOME
Merge branch 'V9_2_2_BR'
[tools/yacsgen.git] / module_generator / aster_tmpl.py
index 629c383a905051f0ec7f38cc808c2004f8b236c3..0e603ecb1fab6c54385260dbd9c15d5db36e18e3 100644 (file)
@@ -1,9 +1,9 @@
-# Copyright (C) 2009-2013  EDF R&D
+# Copyright (C) 2009-2019  EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,7 +20,7 @@
 try:
  from string import Template
 except:
- from compat import Template,set
+ from module_generator.compat import Template,set
 
 asterCompo="""
 import sys,traceback,os
@@ -62,10 +62,15 @@ class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUP
     if hasattr(self,"init_timer"):
       self.init_timer()
     #fin modif pour aster 9.0
-    if os.path.exists(os.path.join(aster_dir,"elements")):
-      shutil.copyfile(os.path.join(aster_dir,"elements"),"elem.1")
+    elements_file = ""
+    if os.path.exists(os.path.join(aster_dir,"share", "aster", "elements")):
+      elements_file = os.path.join(aster_dir,"elements")
+    elif os.path.exists(os.path.join(aster_dir,"elements")):
+      elements_file = os.path.join(aster_dir,"elements")
     else:
-      shutil.copyfile(os.path.join(aster_dir,"catobj","elements"),"elem.1")
+      elements_file = os.path.join(aster_dir,"catobj","elements")
+    shutil.copyfile(elements_file,"elem.1")
+    
 
   def init_service(self,service):
 ${initservice}
@@ -76,8 +81,15 @@ ${servicesimpl}
 asterCompo=Template(asterCompo)
 
 asterCEXECompo="""
+# Par rapport a la version precedente
+# Chaque service est complete par l'appel initial a Complement
+# Cette methode rajoute a l'appel du premier service de l'instance un prefixe au fichier de commande
+# Ce prefixe est fourni dans le fichier fort.99 via as_run et exeaster
+# Le fichier est lu a la creation du module
+# Interet: introduire DEBUT() dans ce prefixe pour ne plus avoir a s'en preoccuper (ex: boucle for each)
 import sys,traceback,os
 import string
+import cPickle
 import ${module}_ORB__POA
 import calcium
 import dsccalcium
@@ -106,12 +118,32 @@ class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUP
   '''
   def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):
     self.init=0
+    if os.path.isfile('fort.99'):
+      prefixFile = file("fort.99","r")
+      self.prefixJdc = prefixFile.read()
+      prefixFile.close()
+    else:
+      self.prefixJdc = ""
     dsccalcium.PyDSCComponent.__init__(self, orb, poa,contID,containerName,instanceName,interfaceName)
 
   def init_service(self,service):
 ${initservice}
     return False
 
+  def insertPrefix(self,jdc):
+    if not self.init:
+      jdc = self.prefixJdc + jdc
+    return jdc
+
+  def insertPrePost(self,jdc,prepost):
+    if prepost <> "":
+      exec(prepost)
+      try:
+        jdc = os.linesep + pre + os.linesep + jdc + os.linesep + post + os.linesep
+      except NameError:
+        pass
+    return jdc
+    
   def interpstring(self,text,args):
     try:
       self.jdc.g_context.update(args)
@@ -159,9 +191,9 @@ asterService="""
     if not j.cr.estvide():
        msg="ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION"
        self.MESSAGE(msg)
-       print ">> JDC.py : DEBUT RAPPORT"
-       print j.cr
-       print ">> JDC.py : FIN RAPPORT"
+       print (">> JDC.py : DEBUT RAPPORT")
+       print (j.cr)
+       print (">> JDC.py : FIN RAPPORT")
        j.supprime()
        sys.stdout.flush()
        raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
@@ -191,14 +223,14 @@ asterService="""
        msg="ERREUR A L'INTERPRETATION DANS ACCAS - INTERRUPTION"
        self.MESSAGE(msg)
        ier=1
-       print ">> JDC.py : DEBUT RAPPORT"
-       print j.cr
-       print ">> JDC.py : FIN RAPPORT"
+       print (">> JDC.py : DEBUT RAPPORT")
+       print (j.cr)
+       print (">> JDC.py : FIN RAPPORT")
        sys.stdout.flush()
        raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr), "${component}.py",0))
 
     if j.par_lot == 'NON':
-       print "FIN EXECUTION"
+       print ("FIN EXECUTION")
        #err=calcium.cp_fin(self.proxy,calcium.CP_ARRET)
        #retour sans erreur (il faut pousser les variables de sortie)
        sys.stdout.flush()
@@ -210,9 +242,9 @@ asterService="""
     if not cr.estvide():
        msg="ERREUR A LA VERIFICATION SYNTAXIQUE - INTERRUPTION"
        self.MESSAGE(msg)
-       print ">> JDC.py : DEBUT RAPPORT"
-       print cr
-       print ">> JDC.py : FIN RAPPORT"
+       print( ">> JDC.py : DEBUT RAPPORT")
+       print( cr)
+       print( ">> JDC.py : FIN RAPPORT")
        sys.stdout.flush()
        raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(cr),"${component}.py",0))
 
@@ -224,9 +256,9 @@ asterService="""
           msg="ERREUR A L'EXECUTION - INTERRUPTION"
           self.MESSAGE(msg)
           ier=1
-          print ">> JDC.py : DEBUT RAPPORT"
-          print j.cr
-          print ">> JDC.py : FIN RAPPORT"
+          print( ">> JDC.py : DEBUT RAPPORT")
+          print( j.cr)
+          print( ">> JDC.py : FIN RAPPORT")
           sys.stdout.flush()
           raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,msg+'\\n'+str(j.cr),"${component}.py",0))
        else:
@@ -254,6 +286,9 @@ asterCEXEService="""
         jdc=fcomm.read()
         fcomm.close()
         #args["jdc"]=jdc
+      prepost = '''${body}'''
+      jdc = self.insertPrePost(jdc,prepost)
+      jdc = self.insertPrefix(jdc)
       if not self.init:
         self.init=1
         fcomm=open("fort.1",'w')
@@ -279,40 +314,6 @@ asterCEXEService="""
 asterCEXEService=Template(asterCEXEService)
 asterEXEService=asterCEXEService
 
-
-check_aster="""
-#
-# Check availability of Aster binary distribution
-#
-
-AC_DEFUN([AC_CHECK_ASTER],[
-
-AC_CHECKING(for Aster)
-
-Aster_ok=no
-
-AC_ARG_WITH(aster,
-      [AC_HELP_STRING([--with-aster=DIR],[root directory path of Aster installation])],
-      [ASTER_DIR="$withval"],[ASTER_DIR=""])
-
-if test -f ${ASTER_DIR}/asteru ; then
-   Aster_ok=yes
-   AC_MSG_RESULT(Using Aster distribution in ${ASTER_DIR})
-
-   ASTER_INCLUDES=-I$ASTER_DIR/bibc/include
-
-   AC_SUBST(ASTER_DIR)
-   AC_SUBST(ASTER_INCLUDES)
-
-else
-   AC_MSG_WARN("Cannot find Aster distribution")
-fi
-
-AC_MSG_RESULT(for Aster: $Aster_ok)
-
-])dnl
-"""
-
 comm="""
 DEBUT(PAR_LOT='NON')
 """
@@ -379,15 +380,15 @@ from SALOME_ContainerPy import SALOME_ContainerPy_i
 
 if __name__ == '__main__':
 
-  print sys.argv
+  print( sys.argv)
   orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
   poa = orb.resolve_initial_references("RootPOA")
-  print "ORB and POA initialized"
+  print( "ORB and POA initialized")
   containerName=os.getenv("SALOME_CONTAINERNAME")
   cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
-  print "SALOME_ContainerPy_i instance created ",cpy_i
+  print( "SALOME_ContainerPy_i instance created ",cpy_i)
   cpy_o = cpy_i._this()
-  print "SALOME_ContainerPy_i instance activated ",cpy_o
+  print( "SALOME_ContainerPy_i instance activated ",cpy_o)
   sys.stdout.flush()
   sys.stderr.flush()
 
@@ -397,7 +398,7 @@ if __name__ == '__main__':
 
   #Block for ever
   orb.run()
-  print "fin container aster"
+  print( "fin container aster")
   sys.stdout.flush()
   sys.stderr.flush()
 """
@@ -408,10 +409,10 @@ from ${component}_module import ${component}
 
 if __name__ == '__main__':
 
-  print sys.argv
+  print( sys.argv)
   orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
   poa = orb.resolve_initial_references("RootPOA")
-  print "ORB and POA initialized",orb,poa
+  print( "ORB and POA initialized",orb,poa)
   sys.stdout.flush()
   sys.stderr.flush()
 
@@ -422,7 +423,7 @@ if __name__ == '__main__':
   compo=${component}(orb,poa,container,containerName, instanceName, "${component}")
   comp_o = compo._this()
   comp_iors = orb.object_to_string(comp_o)
-  print "ior aster",comp_iors
+  print( "ior aster",comp_iors)
 
   sys.stdout.flush()
   sys.stderr.flush()
@@ -432,8 +433,48 @@ if __name__ == '__main__':
   poaManager.activate()
 
   orb.run()
-  print "fin du composant aster standalone"
+  print( "fin du composant aster standalone")
 
 """
 component=Template(component)
 
+# CMakeLists.txt in src/<component> for an aster component
+# template parameters:
+#   sources: source files, separated by spaces
+#   module: module name
+#   resources: files to be installed in resources directory
+#   scripts: scripts to be installed
+cmake_src_compo_aster="""
+# scripts / static
+SET(_bin_py
+  ${sources}
+)
+
+SET(_res_files
+  ${resources}
+)
+
+SET(_bin_scripts
+  ${scripts}
+)
+
+# --- rules ---
+INSTALL(FILES $${_res_files} DESTINATION $${SALOME_${module}_INSTALL_RES_DATA})
+SALOME_INSTALL_SCRIPTS("$${_bin_scripts}" $${SALOME_INSTALL_SCRIPT_SCRIPTS})
+SALOME_INSTALL_SCRIPTS("$${_bin_py}" $${SALOME_INSTALL_PYTHON})
+"""
+cmake_src_compo_aster=Template(cmake_src_compo_aster)
+
+# CMakeLists.txt in src/<component> for an aster lib component
+# template parameters:
+#   sources: source files, separated by spaces
+cmake_src_compo_aster_lib="""
+# scripts / static
+SET(_bin_SCRIPTS
+  ${sources}
+)
+
+# --- rules ---
+SALOME_INSTALL_SCRIPTS("$${_bin_SCRIPTS}" $${SALOME_INSTALL_PYTHON})
+"""
+cmake_src_compo_aster_lib=Template(cmake_src_compo_aster_lib)