Salome HOME
Merge branch 'V9_2_2_BR'
[tools/yacsgen.git] / module_generator / pycompo.py
index d180e502de37e1f04c8b8f5207d06a3a6dfac1a8..12f4fefefcae55b82cdafe1ab54b91e9473cec6a 100644 (file)
@@ -1,4 +1,4 @@
-# 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
   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, cmake_src_compo_py
+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):
   """
@@ -99,8 +98,7 @@ class PYComponent(Component):
       raise Invalid("Invalid kind ()%s for component %s" % (
                                     self.kind, self.name))
     
-    sources = pyfile + "".join(map(lambda x: "\n  " + os.path.basename(x),
-                                   self.sources))
+    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,
@@ -120,7 +118,7 @@ class PYComponent(Component):
         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)
 
@@ -130,7 +128,7 @@ class PYComponent(Component):
         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
@@ -184,7 +182,7 @@ class PYComponent(Component):
         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)
 
@@ -194,7 +192,7 @@ class PYComponent(Component):
         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