-# 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
Module that defines PYComponent for SALOME components implemented in Python
"""
import os
-from gener import Component, Invalid
-from pyth_tmpl import pyinitService, pyService, pyCompoEXE, pyCompo
+from module_generator.gener import Component, Invalid
+from module_generator.pyth_tmpl import pyinitService, pyService, pyCompoEXE, pyCompo, cmake_src_compo_py
import textwrap
-from string import split,rstrip,join
def indent(text, prefix=' '):
"""Indent text by prepending a given prefix to each line."""
if not text: return ''
- lines = split(text, '\n')
- lines = map(lambda line, prefix=prefix: prefix + line, lines)
- if lines: lines[-1] = rstrip(lines[-1])
- return join(lines, '\n')
+ lines = text.split('\n')
+ lines = list(map(lambda line, prefix=prefix: prefix + line, lines))
+ if lines: lines[-1] = lines[-1].rstrip()
+ return '\n'.join(lines)
class PYComponent(Component):
"""
if self.kind not in kinds:
raise Invalid("kind must be one of %s for component %s" % (kinds,self.name))
+ def libraryName(self):
+ """ Name of the target library
+ No library for a python component
+ """
+ return ""
+
def makeCompo(self, gen):
"""generate component sources as a dictionary containing
file names (key) and file content (values)
"""
- pyfile = "%s.py" % self.name
- sources = " ".join(map(os.path.basename,self.sources))
- if self.kind == "lib":
- return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)),
- pyfile:self.makepy(gen)
- }
- if self.kind == "exe":
- return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)),
- self.name+".exe":self.makepyexe(gen),
- }
-
- def getMakefileItems(self,gen):
- makefileItems={"header":"include $(top_srcdir)/adm_local/make_common_starter.am"}
+ pyfile = ""
+ file_content = ""
if self.kind == "lib":
- makefileItems["salomepython_PYTHON"]=[self.name+".py"]+self.sources
- if self.kind == "exe":
- makefileItems["salomepython_PYTHON"]=self.sources
- makefileItems["dist_salomescript_SCRIPTS"]=[self.name+".exe"]
- return makefileItems
+ pyfile = self.name + ".py"
+ file_content = self.makepy(gen)
+ elif self.kind == "exe":
+ pyfile = self.name + ".exe"
+ file_content = self.makepyexe(gen)
+ else :
+ raise Invalid("Invalid kind ()%s for component %s" % (
+ self.kind, self.name))
+
+ sources = pyfile + "".join(["\n " + os.path.basename(x) for x in self.sources])
+ cmake_content = cmake_src_compo_py.substitute(sources=sources)
+
+ return {"CMakeLists.txt":cmake_content,
+ pyfile:file_content
+ }
def makepy(self, gen):
"""generate standard SALOME component source (python module)"""
if typ=="file":continue #files are not passed through service interface
params.append(name)
if typ == "pyobj":
- pyparams.append(" %s=cPickle.loads(%s)" %(name, name))
+ pyparams.append(" %s=pickle.loads(%s)" %(name, name))
inparams = ",".join(params)
convertinparams = '\n'.join(pyparams)
if typ=="file":continue #files are not passed through service interface
params.append(name)
if typ == "pyobj":
- pyparams.append(" %s=cPickle.dumps(%s,-1)" %(name, name))
+ pyparams.append(" %s=pickle.dumps(%s,-1)" %(name, name))
outparams = ",".join(params)
convertoutparams = '\n'.join(pyparams)
#dedent and indent the body
if typ=="file":continue #files are not passed through service interface
params.append(name)
if typ == "pyobj":
- pyparams.append(" %s=cPickle.loads(%s)" %(name, name))
+ pyparams.append(" %s=pickle.loads(%s)" %(name, name))
inparams = ",".join(params)
convertinparams = '\n'.join(pyparams)
if typ=="file":continue #files are not passed through service interface
params.append(name)
if typ == "pyobj":
- pyparams.append(" %s=cPickle.dumps(%s,-1)" %(name, name))
+ pyparams.append(" %s=pickle.dumps(%s,-1)" %(name, name))
outparams = ",".join(params)
convertoutparams = '\n'.join(pyparams)
#dedent and indent the body