-# 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
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
-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
-import yacsgen_version
+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 + 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 get_dependent_modules(mod,modules):
modules.add(mod)
- if salome_modules[mod].has_key("depends"):
+ if "depends" in salome_modules[mod]:
for m in salome_modules[mod]["depends"]:
if m not in modules:
get_dependent_modules(m,modules)
>>> s1 = module_generator.Service('myservice', inport=[("a","double"),],
instream=[("aa","CALCIUM_double","I")],
- body="print a")
+ body="print( a)")
"""
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))
+ 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)
# 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,
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,
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
# 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, basestring):
- if isinstance(content, unicode):
- # encodage to utf-8 if unicode string
- content=content.encode('utf8')
- fil = open(filename, 'w')
- fil.write(content)
- fil.close()
+ if isinstance(content, str):
+ # 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
host = socket.gethostname().split('.')[0]
fil.write(command % host)
fil.close()
-