-# Copyright (C) 2009-2014 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
try:
from string import Template
except:
- from compat import Template, set
+ from module_generator.compat import Template, set
class Invalid(Exception):
pass
debug=0
-from mod_tmpl import *
-from cata_tmpl import catalog, interface, idl, parallel_interface
-from cata_tmpl import xml, xml_interface, xml_service
-from cata_tmpl import idlMakefilePaCO_BUILT_SOURCES, idlMakefilePaCO_nodist_salomeinclude_HEADERS
-from cata_tmpl import idlMakefilePACO_salomepython_DATA, idlMakefilePACO_salomeidl_DATA
-from cata_tmpl import idlMakefilePACO_INCLUDES
-from cata_tmpl import cataOutStream, cataInStream, cataOutparam, cataInparam
-from cata_tmpl import cataOutParallelStream, cataInParallelStream
-from cata_tmpl import cataService, cataCompo
+from module_generator.mod_tmpl import *
+from module_generator.cata_tmpl import catalog, interface, idl
+from module_generator.cata_tmpl import xml, xml_interface, xml_service
+from module_generator.cata_tmpl import idlMakefilePaCO_BUILT_SOURCES, idlMakefilePaCO_nodist_salomeinclude_HEADERS
+from module_generator.cata_tmpl import idlMakefilePACO_salomepython_DATA, idlMakefilePACO_salomeidl_DATA
+from module_generator.cata_tmpl import idlMakefilePACO_INCLUDES
+from module_generator.cata_tmpl import cataOutStream, cataInStream, cataOutparam, cataInparam
+from module_generator.cata_tmpl import cataOutParallelStream, cataInParallelStream
+from module_generator.cata_tmpl import cataService, cataCompo
#from aster_tmpl import check_aster
-from salomemodules import salome_modules
-from yacstypes import corbaTypes, corbaOutTypes, moduleTypes, idlTypes, corba_in_type, corba_out_type
-from yacstypes import ValidTypes, PyValidTypes, calciumTypes, DatastreamParallelTypes
-from yacstypes import ValidImpl, ValidImplTypes, ValidStreamTypes, ValidParallelStreamTypes, ValidDependencies
-from gui_tmpl import cmake_py_gui, pysalomeapp, cmake_cpp_gui, cppsalomeapp
-from doc_tmpl import docmakefile, docconf, docsalomeapp
+from module_generator.salomemodules import salome_modules
+from module_generator.yacstypes import corbaTypes, corbaOutTypes, moduleTypes, idlTypes, corba_in_type, corba_out_type
+from module_generator.yacstypes import ValidTypes, PyValidTypes, calciumTypes, DatastreamParallelTypes
+from module_generator.yacstypes import ValidImpl, ValidImplTypes, ValidStreamTypes, ValidParallelStreamTypes, ValidDependencies
+from module_generator.gui_tmpl import cmake_py_gui, pysalomeapp, cmake_cpp_gui, cppsalomeapp
+from module_generator.doc_tmpl import docmakefile, docconf, docsalomeapp
+from module_generator import yacsgen_version
def makedirs(namedir):
"""Create a new directory named namedir. If a directory already exists copy it to namedir.bak"""
self.gui = gui
try:
self.validate()
- except Invalid,e:
+ except Invalid as e:
if debug:
traceback.print_exc()
- print "Error in module %s: %s" % (name,e)
+ print("Error in module %s: %s" % (name,e))
raise SystemExit
def validate(self):
cmake_vars = cmake_vars + "${" + lib.cmakeVarName() + "}\n "
var_template = Template("$${${name}_SalomeIDL${name}}")
- for mod in self.depend_modules:
+ for mod in self.getDependentModules():
if salome_modules[mod]["linklibs"]:
cmake_vars = cmake_vars + salome_modules[mod]["linklibs"]
else:
default_lib = var_template.substitute(name=mod)
- print "Unknown libraries for module " + mod
- print "Using default library name " + default_lib
+ print("Unknown libraries for module " + mod)
+ print("Using default library name " + default_lib)
cmake_vars = cmake_vars + default_lib + "\n "
return cmake_text, cmake_vars
def setPrerequisites(self, prerequisites_file):
self.prerequisites = prerequisites_file
+ def getIdlInterfaces(self):
+ services = self.getIdlServices()
+ inheritedinterface=""
+ if self.inheritedinterface:
+ inheritedinterface=self.inheritedinterface+","
+ return interface.substitute(component=self.name,
+ services="\n".join(services),
+ inheritedinterface=inheritedinterface)
+
+ def getIdlServices(self):
+ services = []
+ for serv in self.services:
+ params = []
+ for name, typ in serv.inport:
+ if typ == "file":continue #files are not passed through IDL interface
+ if self.impl in ("PY", "ASTER") and typ == "pyobj":
+ typ = "Engines::fileBlock"
+ else:
+ typ=idlTypes[typ]
+ params.append("in %s %s" % (typ, name))
+ for name, typ in serv.outport:
+ if typ == "file":continue #files are not passed through IDL interface
+ if self.impl in ("PY", "ASTER") and typ == "pyobj":
+ typ = "Engines::fileBlock"
+ else:
+ typ=idlTypes[typ]
+ params.append("out %s %s" % (typ, name))
+ service = " %s %s(" % (idlTypes[serv.ret],serv.name)
+ service = service+",".join(params)+") raises (SALOME::SALOME_Exception);"
+ services.append(service)
+ return services
+
+ def getIdlDefs(self):
+ idldefs = """
+#include "DSC_Engines.idl"
+#include "SALOME_Parametric.idl"
+"""
+ if self.interfacedefs:
+ idldefs = idldefs + self.interfacedefs
+ return idldefs
+
+ def getDependentModules(self):
+ """get the list of SALOME modules used by the component
+ """
+ def get_dependent_modules(mod,modules):
+ modules.add(mod)
+ if "depends" in salome_modules[mod]:
+ for m in salome_modules[mod]["depends"]:
+ if m not in modules:
+ get_dependent_modules(m,modules)
+
+ depend_modules = set()
+ for serv in self.services:
+ for name, typ in serv.inport + serv.outport + [ ("return",serv.ret) ] :
+ mod = moduleTypes[typ]
+ if mod:
+ get_dependent_modules(mod,depend_modules)
+ return depend_modules
+
class Service(object):
"""
A :class:`Service` instance represents a component service with dataflow and datastream ports.
>>> s1 = module_generator.Service('myservice', inport=[("a","double"),],
instream=[("aa","CALCIUM_double","I")],
- body="print a")
+ body="print( a)")
"""
srcs = {}
#get the list of SALOME modules used and put it in used_modules attribute
- def get_dependent_modules(mod,modules):
- modules[mod]=1
- if not salome_modules[mod].has_key("depends"):return
- for m in salome_modules[mod]["depends"]:
- if modules.has_key(m):continue
- get_dependent_modules(m,modules)
-
- modules = {}
+ modules = set()
for compo in module.components:
- compo.depend_modules = set()
- for serv in compo.services:
- for name, typ in serv.inport + serv.outport + [ ("return",serv.ret) ] :
- mod = moduleTypes[typ]
- if mod:
- get_dependent_modules(mod,modules)
- compo.depend_modules.add(mod)
-
- self.used_modules = modules.keys()
+ modules |= compo.getDependentModules()
+
+ self.used_modules = modules
for compo in module.components:
#for components files
srcs[compo.name] = fdict
cmakecontent = ""
- components_string = "".join(map(lambda x: x.name+" ", module.components))
+ components_string = "".join([x.name+" " for x in module.components])
if self.module.gui:
GUIname=module.name+"GUI"
cmake_gui="OFF"
prefix = os.path.abspath(self.module.prefix)
- component_libs = "".join(map(lambda x: x.libraryName()+" ",
- module.components))
- add_modules = "".join(map(lambda x:cmake_find_module.substitute(module=x),
- self.used_modules))
+ 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_text + """
+#####################################
+# FIND MEDCOUPLING
+#####################################
+SET(MEDCOUPLING_ROOT_DIR $ENV{MEDCOUPLING_ROOT_DIR} CACHE PATH "Path to MEDCOUPLING module")
+IF(EXISTS ${MEDCOUPLING_ROOT_DIR})
+ LIST(APPEND CMAKE_MODULE_PATH "${MEDCOUPLING_ROOT_DIR}/cmake_files")
+ FIND_PACKAGE(SalomeMEDCoupling REQUIRED)
+ ADD_DEFINITIONS(${MEDCOUPLING_DEFINITIONS})
+ INCLUDE_DIRECTORIES(${MEDCOUPLING_INCLUDE_DIRS})
+ELSE(EXISTS ${MEDCOUPLING_ROOT_DIR})
+ MESSAGE(FATAL_ERROR "We absolutely need MEDCOUPLING module, please define MEDCOUPLING_ROOT_DIR")
+ENDIF(EXISTS ${MEDCOUPLING_ROOT_DIR})
+#####################################
+
+"""
+ add_modules = add_modules + cmake_text
+ pass
+
self.makeFiles({"CMakeLists.txt":cmake_root_cpp.substitute(
module=self.module.name,
module_min=self.module.name.lower(),
compolibs=component_libs,
with_doc=cmake_doc,
with_gui=cmake_gui,
- add_modules=add_modules),
+ add_modules=add_modules,
+ major_version=yacsgen_version.major_version,
+ minor_version=yacsgen_version.minor_version,
+ patch_version=yacsgen_version.patch_version),
"README":"", "NEWS":"", "AUTHORS":"", "ChangeLog":"",
"src":srcs,
"resources":{"CMakeLists.txt":cmake_ressources.substitute(
# 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(map(lambda x:include_template.substitute(module=x)+"\n ",
- self.used_modules))
+ opt_inc="".join([include_template.substitute(module=x)+"\n " for x in self.used_modules])
link_template=Template("$${${module}_SalomeIDL${module}}")
- opt_link="".join(map(lambda x:link_template.substitute(module=x)+"\n ",
- self.used_modules))
+ opt_link="".join([link_template.substitute(module=x)+"\n " for x in self.used_modules])
idlfiles={"CMakeLists.txt":cmake_idl.substitute(module=module.name,
extra_idl=other_idls,
#without gui but with doc: create a small SalomeApp.xml in doc directory
if not os.path.exists(os.path.join(namedir, "doc", "SalomeApp.xml")):
#create a minimal SalomeApp.xml
- salomeapp=docsalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+ salomeapp=docsalomeapp.substitute(module=self.module.name,
+ lmodule=self.module.name.lower(),
+ version=yacsgen_version.complete_version)
d["SalomeApp.xml"]=salomeapp
if not os.path.exists(os.path.join(namedir, "doc", "CMakeLists.txt")):
if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "SalomeApp.xml")):
#create a minimal SalomeApp.xml
- salomeapp=pysalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+ salomeapp=pysalomeapp.substitute(module=self.module.name,
+ lmodule=self.module.name.lower(),
+ version=yacsgen_version.complete_version)
d["SalomeApp.xml"]=salomeapp
return d
elif src[-3:]==".ui":
ui_files=ui_files+os.path.basename(src)+"\n "
elif src[-3:]==".ts":
- ts_files=ts_files+os.path.basename(src)+"\n "
+ ts_files = ts_files + os.path.basename(src) + "\n "
else:
other=other+os.path.basename(src)+"\n "
- compo_dirs = "".join(map(lambda x:
- "${PROJECT_SOURCE_DIR}/src/"+x.name+"\n ",
- self.module.components))
+ compo_dirs = "".join(["${PROJECT_SOURCE_DIR}/src/"+x.name+"\n " for x in self.module.components])
compo_dirs = compo_dirs + "${PROJECT_BINARY_DIR}/src/" + self.module.name + "GUI\n"
- component_libs = "".join(map(lambda x:
- x.libraryName()+" ", self.module.components))
+ component_libs = "".join([x.libraryName()+" " for x in self.module.components])
makefile=cmake_cpp_gui.substitute(module=self.module.name,
include_dirs=compo_dirs,
libs=component_libs,
if not os.path.exists(os.path.join(namedir, "src", self.module.name+"GUI", "SalomeApp.xml")):
#create a minimal SalomeApp.xml
- salomeapp=cppsalomeapp.substitute(module=self.module.name,lmodule=self.module.name.lower())
+ salomeapp=cppsalomeapp.substitute(module=self.module.name,
+ lmodule=self.module.name.lower(),
+ version=yacsgen_version.complete_version)
d["SalomeApp.xml"]=salomeapp
return d
def makeMakefile(self,makefileItems):
makefile=""
- if makefileItems.has_key("header"):
+ if "header" in makefileItems:
makefile=makefile + makefileItems["header"]+'\n'
- if makefileItems.has_key("lib_LTLIBRARIES"):
+ if "lib_LTLIBRARIES" in makefileItems:
makefile=makefile+"lib_LTLIBRARIES= "+" ".join(makefileItems["lib_LTLIBRARIES"])+'\n'
- if makefileItems.has_key("salomepython_PYTHON"):
+ if "salomepython_PYTHON" in makefileItems:
makefile=makefile+"salomepython_PYTHON= "+" ".join(makefileItems["salomepython_PYTHON"])+'\n'
- if makefileItems.has_key("dist_salomescript_SCRIPTS"):
+ if "dist_salomescript_SCRIPTS" in makefileItems:
makefile=makefile+"dist_salomescript_SCRIPTS= "+" ".join(makefileItems["dist_salomescript_SCRIPTS"])+'\n'
- if makefileItems.has_key("salomeres_DATA"):
+ if "salomeres_DATA" in makefileItems:
makefile=makefile+"salomeres_DATA= "+" ".join(makefileItems["salomeres_DATA"])+'\n'
- if makefileItems.has_key("salomeinclude_HEADERS"):
+ if "salomeinclude_HEADERS" in makefileItems:
makefile=makefile+"salomeinclude_HEADERS= "+" ".join(makefileItems["salomeinclude_HEADERS"])+'\n'
- if makefileItems.has_key("body"):
+ if "body" in makefileItems:
makefile=makefile+makefileItems["body"]+'\n'
return makefile
def makeidl(self):
"""generate module IDL file source (CORBA interface)"""
- from pacocompo import PACOComponent
interfaces = []
idldefs=""
for compo in self.module.components:
- if isinstance(compo, PACOComponent):
- services = []
- for serv in compo.services:
- params = []
- for name, typ in serv.inport:
- if typ == "file":continue #files are not passed through IDL interface
- params.append("in %s %s" % (idlTypes[typ], name))
- for name, typ in serv.outport:
- if typ == "file":continue #files are not passed through IDL interface
- params.append("out %s %s" % (idlTypes[typ], name))
- service = " void %s(" % serv.name
- service = service+",".join(params)+");"
- services.append(service)
-
- interfaces.append(parallel_interface.substitute(component=compo.name, services="\n".join(services)))
-
- else:
- services = []
- for serv in compo.services:
- params = []
- for name, typ in serv.inport:
- if typ == "file":continue #files are not passed through IDL interface
- if compo.impl in ("PY", "ASTER") and typ == "pyobj":
- typ = "Engines::fileBlock"
- else:
- typ=idlTypes[typ]
- params.append("in %s %s" % (typ, name))
- for name, typ in serv.outport:
- if typ == "file":continue #files are not passed through IDL interface
- if compo.impl in ("PY", "ASTER") and typ == "pyobj":
- typ = "Engines::fileBlock"
- else:
- typ=idlTypes[typ]
- params.append("out %s %s" % (typ, name))
- service = " %s %s(" % (idlTypes[serv.ret],serv.name)
- service = service+",".join(params)+") raises (SALOME::SALOME_Exception);"
- services.append(service)
-
- from hxxcompo import HXX2SALOMEComponent
- from hxxparacompo import HXX2SALOMEParaComponent
- if isinstance(compo,HXX2SALOMEComponent) or isinstance(compo,HXX2SALOMEParaComponent):
- from hxx_tmpl import interfaceidlhxx
- Inherited=""
- if isinstance(compo,HXX2SALOMEParaComponent):
- Inherited="SALOME_MED::ParaMEDMEMComponent"
- idldefs="""#include "ParaMEDMEMComponent.idl"\n"""
- else:
- if compo.use_medmem==True:
- Inherited="Engines::EngineComponent,SALOME::MultiCommClass,SALOME_MED::MED_Gen_Driver"
- else:
- Inherited="Engines::EngineComponent"
- interfaces.append(interfaceidlhxx.substitute(component=compo.name,inherited=Inherited, services="\n".join(services)))
- else:
- inheritedinterface=""
- if compo.inheritedinterface:
- inheritedinterface=compo.inheritedinterface+","
- interfaces.append(interface.substitute(component=compo.name, services="\n".join(services),inheritedinterface=inheritedinterface))
+ interfaces.append(compo.getIdlInterfaces())
#build idl includes for SALOME modules
for mod in self.used_modules:
idldefs = idldefs + salome_modules[mod]["idldefs"]
for compo in self.module.components:
- if compo.interfacedefs:
- idldefs = idldefs + compo.interfacedefs
+ idldefs = idldefs + compo.getIdlDefs()
+
+ filteredDefs = []
+ for defLine in idldefs.split('\n'):
+ if defLine not in filteredDefs:
+ filteredDefs.append(defLine)
- return idl.substitute(module=self.module.name, interfaces='\n'.join(interfaces),idldefs=idldefs)
+ return idl.substitute(module=self.module.name,
+ interfaces='\n'.join(interfaces),
+ idldefs='\n'.join(filteredDefs) )
# For PaCO++
def makexml(self):
- from pacocompo import PACOComponent
+ from .pacocompo import PACOComponent
interfaces = []
for compo in self.module.components:
if isinstance(compo, PACOComponent):
dic key = file name to create
dic value = file content or dictionary defining the content of a sub directory
"""
- for name, content in dic.items():
+ 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)
modules = []
if restrict:
for mod in restrict:
- if modules_dict.has_key(mod):
+ if mod in modules_dict:
modules.append(modules_dict[mod])
else:
- modules = modules_dict.values()
+ modules = list(modules_dict.values())
#add the alternate modules if given
if altmodules:
- for module, path in altmodules.items():
+ for module, path in list(altmodules.items()):
modules.append(' <module name="%s" path="%s"/>' % (module, path))
#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):
#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')
host = socket.gethostname().split('.')[0]
fil.write(command % host)
fil.close()
-