Salome HOME
Increment version: 9.7.0
[tools/yacsgen.git] / module_generator / gener.py
index ce80d856f650b7467dca1a8e566801f824619a7d..69afe86801936f64a13733901a0bd0247935ae2b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2009-2016  EDF R&D
+# Copyright (C) 2009-2021  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
@@ -294,7 +294,7 @@ class Service(object):
 
       >>> s1 = module_generator.Service('myservice', inport=[("a","double"),],
                                         instream=[("aa","CALCIUM_double","I")],
-                                        body="print a")
+                                        body="print( a)")
 
 
   """
@@ -485,8 +485,8 @@ class Generator(object):
     component_libs = "".join([x.libraryName()+" " for x in module.components])
     add_modules = ""
     for x in self.used_modules:
-      cmake_text = cmake_find_module.substitute(module=x)
       if x == "MED":
+        cmake_text = cmake_find_module.substitute(module="FIELDS")
         cmake_text = cmake_text + """
 #####################################
 # FIND MEDCOUPLING
@@ -503,6 +503,9 @@ ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
 #####################################
 
 """
+      else:
+        cmake_text = cmake_find_module.substitute(module=x)
+
       add_modules = add_modules + cmake_text
       pass
     
@@ -538,9 +541,18 @@ ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
 #            other_sks=other_sks+os.path.splitext(os.path.basename(fidl))[0]+"SK.cc "
 
     include_template=Template("$${${module}_ROOT_DIR}/idl/salome")
-    opt_inc="".join([include_template.substitute(module=x)+"\n  " for x in self.used_modules])
     link_template=Template("$${${module}_SalomeIDL${module}}")
-    opt_link="".join([link_template.substitute(module=x)+"\n  " for x in self.used_modules])
+    opt_inc=""
+    opt_link=""
+    for x in self.used_modules:
+      if x=="MED":
+        # here template cannot be used as we mix FIELDS and MED
+        opt_inc+="${FIELDS_ROOT_DIR}/idl/salome\n  "
+        opt_link+="${FIELDS_SalomeIDLMED}\n  "
+      else:
+        opt_inc+=include_template.substitute(module=x)+"\n  "
+        opt_link+=link_template.substitute(module=x)+"\n  "
+
     
     idlfiles={"CMakeLists.txt":cmake_idl.substitute(module=module.name,
                                                     extra_idl=other_idls,
@@ -812,9 +824,9 @@ ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
     for name, content in list(dic.items()):
       filename = os.path.join(basedir, name)
       if isinstance(content, str):
-        fil =  open(filename, 'w')
-        fil.write(content)
-        fil.close()
+        # encodage to utf-8 if unicode string / on python3 str are unicode
+        with open(filename, 'w') as fil:
+          fil.write(content)
       else:
         if not os.path.exists(filename):
           os.makedirs(filename)
@@ -919,15 +931,22 @@ ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
     #add the generated module
     modules.append('  <module name="%s" path="%s"/>' % (self.module.name, os.path.abspath(self.module.prefix)))
 
-
+    ROOT_SALOME=os.getenv("ROOT_SALOME")
     #try to find a prerequisites file
     prerequisites = self.context.get("prerequisites")
     if not prerequisites:
       #try to find one in rootdir
-      prerequisites = os.path.join(rootdir, "profile%s.sh" % suffix)
+      prerequisites = os.path.join(ROOT_SALOME, "salome_prerequisites.sh")
     if not os.path.exists(prerequisites):
       raise Invalid("Can not create an application : prerequisites file not defined or does not exist")
 
+    salome_context = self.context.get("salome_context")
+    if not salome_context:
+      #try to find one in rootdir
+      salome_context = os.path.join(ROOT_SALOME, "salome_context.cfg")
+    if not os.path.exists(salome_context):
+      raise Invalid("Can not create an application : salome_context file not defined or does not exist")
+
     #add resources catalog if it exists
     resources_spec=""
     if os.path.isfile(resources):
@@ -935,6 +954,7 @@ ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
 
     #create config_appli.xml file
     appli = application.substitute(prerequisites=prerequisites,
+                                   context=salome_context,
                                    modules="\n".join(modules),
                                    resources=resources_spec)
     fil = open(os.path.join(appliname, "config_appli.xml"), 'w')