Salome HOME
Merge branch 'V9_2_2_BR'
[tools/yacsgen.git] / module_generator / gener.py
index ce80d856f650b7467dca1a8e566801f824619a7d..6b6dc1c47217c4aac4fe5bb5e664a4dabdbb927a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2009-2016  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
@@ -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)")
 
 
   """
@@ -812,9 +812,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 +919,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 +942,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')