--- a/py_ext/PythonFileCTNMixin.py Mon Aug 21 20:17:19 2017 +0000
+++ b/py_ext/PythonFileCTNMixin.py Mon Aug 21 23:22:58 2017 +0300
@@ -23,7 +23,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-import os, re
+import os
+import re
from lxml import etree
import util.paths as paths
@@ -32,6 +33,7 @@
from CodeFileTreeNode import CodeFile
from PythonEditor import PythonEditor
+
class PythonFileCTNMixin(CodeFile):
CODEFILE_NAME = "PyFile"
@@ -59,8 +61,8 @@
'xmlns="http://www.w3.org/2001/XMLSchema"',
'xmlns:xhtml="http://www.w3.org/1999/xhtml"')
for cre, repl in [
- (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
- (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
+ (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
+ (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
pythonfile_xml = cre.sub(repl, pythonfile_xml)
try:
@@ -85,34 +87,36 @@
PreSectionsTexts = {}
PostSectionsTexts = {}
- def GetSection(self,section):
- return self.PreSectionsTexts.get(section,"") + "\n" + \
+
+ def GetSection(self, section):
+ return self.PreSectionsTexts.get(section, "") + "\n" + \
getattr(self.CodeFile, section).getanyText() + "\n" + \
- self.PostSectionsTexts.get(section,"")
+ self.PostSectionsTexts.get(section, "")
def CTNGenerate_C(self, buildpath, locations):
# location string for that CTN
- location_str = "_".join(map(lambda x:str(x),
+ location_str = "_".join(map(lambda x: str(x),
self.GetCurrentLocation()))
configname = self.GetCTRoot().GetProjectConfigNames()[0]
pyextname = self.CTNName()
- varinfos = map(lambda variable : {
- "name": variable.getname(),
- "desc" : repr(variable.getdesc()),
- "onchangecode" : '"'+variable.getonchange()+\
- "('"+variable.getname()+"')\"" \
- if variable.getonchange() else '""',
- "onchange" : repr(variable.getonchange()) \
- if variable.getonchange() else None,
- "opts" : repr(variable.getopts()),
- "configname" : configname.upper(),
- "uppername" : variable.getname().upper(),
- "IECtype" : variable.gettype(),
- "pyextname" :pyextname},
- self.CodeFile.variables.variable)
+ varinfos = map(lambda variable: {
+ "name": variable.getname(),
+ "desc": repr(variable.getdesc()),
+ "onchangecode": '"' + variable.getonchange() +
+ "('" + variable.getname() + "')\""
+ if variable.getonchange() else '""',
+ "onchange": repr(variable.getonchange())
+ if variable.getonchange() else None,
+ "opts": repr(variable.getopts()),
+ "configname": configname.upper(),
+ "uppername": variable.getname().upper(),
+ "IECtype": variable.gettype(),
+ "pyextname": pyextname},
+ self.CodeFile.variables.variable)
# python side PLC global variables access stub
- globalstubs = "\n".join(["""\
+ globalstubs = "\n".join([
+ """\
_%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
TypeTranslator["%(IECtype)s"]
_PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s
@@ -127,8 +131,7 @@
%(desc)s,
%(onchange)s,
%(opts)s))
-""" % varinfo
- for varinfo in varinfos])
+""" % varinfo for varinfo in varinfos])
# Runtime calls (start, stop, init, and cleanup)
rtcalls = ""
@@ -170,7 +173,7 @@
# write generated content to python file
runtimefile_path = os.path.join(buildpath,
- "runtime_%s.py"%location_str)
+ "runtime_%s.py" % location_str)
runtimefile = open(runtimefile_path, 'w')
runtimefile.write(PyFileContent.encode('utf-8'))
runtimefile.close()
@@ -234,14 +237,14 @@
__SET_VAR(__%(name)s_notifier->,CODE,,__STRING_LITERAL(%(onchangelen)d,%(onchangecode)s));
"""
vardec = "\n".join([(vardecfmt + vardeconchangefmt
- if varinfo["onchange"] else vardecfmt)% varinfo
+ if varinfo["onchange"] else vardecfmt) % varinfo
for varinfo in varinfos])
varret = "\n".join([varretfmt % varinfo for varinfo in varinfos])
varpub = "\n".join([(varpubonchangefmt if varinfo["onchange"] else
varpubfmt) % varinfo
for varinfo in varinfos])
varinit = "\n".join([varinitonchangefmt % dict(
- onchangelen = len(varinfo["onchangecode"]),**varinfo)
+ onchangelen=len(varinfo["onchangecode"]), **varinfo)
for varinfo in varinfos if varinfo["onchange"]])
# TODO : use config name obtained from model instead of default
@@ -278,16 +281,15 @@
}
""" % locals()
- Gen_PyCfile_path = os.path.join(buildpath, "PyCFile_%s.c"%location_str)
- pycfile = open(Gen_PyCfile_path,'w')
+ Gen_PyCfile_path = os.path.join(buildpath, "PyCFile_%s.c" % location_str)
+ pycfile = open(Gen_PyCfile_path, 'w')
pycfile.write(PyCFileContent)
pycfile.close()
- matiec_CFLAGS = '"-I%s"'%os.path.abspath(
+ matiec_CFLAGS = '"-I%s"' % os.path.abspath(
self.GetCTRoot().GetIECLibPath())
return ([(Gen_PyCfile_path, matiec_CFLAGS)],
"",
True,
- ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")))
-
+ ("runtime_%s.py" % location_str, file(runtimefile_path, "rb")))