--- a/ProjectController.py Tue Aug 07 13:35:28 2018 +0200
+++ b/ProjectController.py Wed Aug 08 10:15:51 2018 +0200
@@ -65,7 +65,8 @@
base_folder = paths.AbsParentDir(__file__)
-MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$")
+MATIEC_ERROR_MODEL = re.compile( + ".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$") def ExtractChildrenTypesFromCatalog(catalog):
@@ -94,6 +95,7 @@
class Iec2CSettings(object):
self.iec2c_buildopts = None
@@ -109,11 +111,12 @@
- cmd = "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else "")
+ cmd = "iec2c" + (".exe" if wx.Platform == '__WXMSW__' else "") os.path.join(base_folder, "matiec")
- path = self.findObject(paths, lambda p: os.path.isfile(os.path.join(p, cmd)))
+ path = self.findObject( + paths, lambda p: os.path.isfile(os.path.join(p, cmd))) # otherwise use iec2c from PATH
@@ -126,7 +129,8 @@
os.path.join(base_folder, "matiec", "lib"),
- path = self.findObject(paths, lambda p: os.path.isfile(os.path.join(p, "ieclib.txt")))
+ path = self.findObject( + paths, lambda p: os.path.isfile(os.path.join(p, "ieclib.txt"))) @@ -146,7 +150,8 @@
- # Invoke compiler. Output files are listed to stdout, errors to stderr
+ # Output files are listed to stdout, errors to stderr _status, result, _err_result = ProcessLogger(None, buildcmd,
@@ -186,17 +191,17 @@
<xsd:element name="TargetType">
<xsd:choice minOccurs="0">
- """+targets.GetTargetChoices()+"""
+ """ + targets.GetTargetChoices() + """ - </xsd:element>"""+(("""
+ </xsd:element>""" + ((""" <xsd:element name="Libraries" minOccurs="0">
- """+"\n".join(['<xsd:attribute name=' +
- '"Enable_' + libname + '_Library" ' +
- 'type="xsd:boolean" use="optional" default="' +
- ('true' if default else 'false') + '"/>'
- for libname, _lib, default in features.libraries])+"""
+ """ + "\n".join(['<xsd:attribute name=' + + '"Enable_' + libname + '_Library" ' + + 'type="xsd:boolean" use="optional" default="' + + ('true' if default else 'false') + '"/>' + for libname, _lib, default in features.libraries]) + """ </xsd:element>""") if len(features.libraries) > 0 else '') + """
@@ -206,11 +211,11 @@
class ProjectController(ConfigTreeNode, PLCControler):
This class define Root object of the confnode tree.
@@ -221,7 +226,8 @@
- # For root object, available Children Types are modules of the confnode packages.
+ # For root object, available Children Types are modules of the confnode CTNChildrenTypes = ExtractChildrenTypesFromCatalog(features.catalog)
XSD = GetProjectControllerXSD()
EditorType = ProjectNodeEditor
@@ -272,8 +278,10 @@
- for libname, clsname, default in features.libraries:
- if self.BeremizRoot.Libraries is not None and getattr(self.BeremizRoot.Libraries, "Enable_"+libname+"_Library"):
+ for libname, clsname, _default in features.libraries: + if self.BeremizRoot.Libraries is not None and \ + getattr(self.BeremizRoot.Libraries, + "Enable_" + libname + "_Library"): Lib = GetClassImporter(clsname)()(self, libname, TypeStack)
TypeStack.append(Lib.GetTypes())
self.Libraries.append(Lib)
@@ -363,7 +371,8 @@
target = self.Parser.CreateElement("TargetType", "BeremizRoot")
temp_root.setTargetType(target)
target_name = self.GetDefaultTargetName()
- target.setcontent(self.Parser.CreateElement(target_name, "TargetType"))
+ self.Parser.CreateElement(target_name, "TargetType")) def GetParamsAttributes(self, path=None):
@@ -371,7 +380,8 @@
if params[0]["name"] == "BeremizRoot":
for child in params[0]["children"]:
if child["name"] == "TargetType" and child["value"] == '':
- child.update(self.GetTarget().getElementInfos("TargetType"))
+ self.GetTarget().getElementInfos("TargetType")) def SetParamsAttribute(self, path, value):
@@ -405,7 +415,8 @@
def _getProjectFilesPath(self, project_path=None):
if project_path is not None:
return os.path.join(project_path, "project_files")
- projectfiles_path = os.path.join(self.GetProjectPath(), "project_files")
+ projectfiles_path = os.path.join( + self.GetProjectPath(), "project_files") if not os.path.exists(projectfiles_path):
os.mkdir(projectfiles_path)
@@ -416,7 +427,8 @@
def SetProjectDefaultConfiguration(self):
# Sets default task and instance for new project
- config = self.Project.getconfiguration(self.GetProjectMainConfigurationName())
+ config = self.Project.getconfiguration( + self.GetProjectMainConfigurationName()) resource = config.getresource()[0].getname()
config = config.getname()
resource_tagname = ComputeConfigurationResourceName(config, resource)
@@ -473,7 +485,8 @@
if self.Project is not None:
(fname_err, lnum, src) = (("PLC",) + error)
- self.logger.write_warning(XSDSchemaErrorMessage.format(a1=fname_err, a2=lnum, a3=src))
+ self.logger.write_warning( + XSDSchemaErrorMessage.format(a1=fname_err, a2=lnum, a3=src)) if len(self.GetProjectConfigNames()) == 0:
@@ -530,14 +543,17 @@
def CheckNewProjectPath(self, old_project_path, new_project_path):
if old_project_path == new_project_path:
message = (_("Save path is the same as path of a project! \n"))
- dialog = wx.MessageDialog(self.AppFrame, message, _("Error"), wx.OK | wx.ICON_ERROR)
+ dialog = wx.MessageDialog( + self.AppFrame, message, _("Error"), wx.OK | wx.ICON_ERROR) plc_file = os.path.join(new_project_path, "plc.xml")
if os.path.isfile(plc_file):
- message = (_("Selected directory already contains another project. Overwrite? \n"))
- dialog = wx.MessageDialog(self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
+ _("Selected directory already contains another project. Overwrite? \n")) + dialog = wx.MessageDialog( + self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR) answer = dialog.ShowModal()
return answer == wx.ID_YES
@@ -545,7 +561,8 @@
def SaveProject(self, from_project_path=None):
if self.CheckProjectPathPerm(False):
if from_project_path is not None:
- old_projectfiles_path = self._getProjectFilesPath(from_project_path)
+ old_projectfiles_path = self._getProjectFilesPath( if os.path.isdir(old_projectfiles_path):
shutil.copytree(old_projectfiles_path,
self._getProjectFilesPath(self.ProjectPath))
@@ -560,7 +577,8 @@
path = os.getenv("USERPROFILE")
- dirdialog = wx.DirDialog(self.AppFrame, _("Choose a directory to save project"), path, wx.DD_NEW_DIR_BUTTON)
+ dirdialog = wx.DirDialog( + self.AppFrame, _("Choose a directory to save project"), path, wx.DD_NEW_DIR_BUTTON) answer = dirdialog.ShowModal()
@@ -584,7 +602,8 @@
if len(self.Libraries) == 0:
self.GetIECProgramsAndVariables()
- LibIECCflags = '"-I%s" -Wno-unused-function' % os.path.abspath(self.GetIECLibPath())
+ LibIECCflags = '"-I%s" -Wno-unused-function' % os.path.abspath( LocatedCCodeAndFlags = []
for lib in self.Libraries:
@@ -592,7 +611,7 @@
LocatedCCodeAndFlags.append(res[:2])
- return map(list, zip(*LocatedCCodeAndFlags))+[tuple(Extras)]
+ return map(list, zip(*LocatedCCodeAndFlags)) + [tuple(Extras)] # Update PLCOpenEditor ConfNode Block types from loaded confnodes
def RefreshConfNodesBlockLists(self):
@@ -658,7 +677,8 @@
self.DefaultBuildPath = os.path.join(self.ProjectPath, "build")
# Create a build path in temp folder
- self.DefaultBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build")
+ self.DefaultBuildPath = os.path.join( + tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build") if not os.path.exists(self.DefaultBuildPath):
os.makedirs(self.DefaultBuildPath)
@@ -683,19 +703,23 @@
filepath = os.path.join(self._getBuildPath(), "LOCATED_VARIABLES.h")
if os.path.isfile(filepath):
- # IEC2C compiler generate a list of located variables : LOCATED_VARIABLES.h
- location_file = open(os.path.join(self._getBuildPath(), "LOCATED_VARIABLES.h"))
+ # IEC2C compiler generate a list of located variables : + os.path.join(self._getBuildPath(), "LOCATED_VARIABLES.h")) # each line of LOCATED_VARIABLES.h declares a located variable
lines = [line.strip() for line in location_file.readlines()]
# This regular expression parses the lines genereated by IEC2C
- LOCATED_MODEL = re.compile("__LOCATED_VAR\((?P<IEC_TYPE>[A-Z]*),(?P<NAME>[_A-Za-z0-9]*),(?P<DIR>[QMI])(?:,(?P<SIZE>[XBWDL]))?,(?P<LOC>[,0-9]*)\)")
+ LOCATED_MODEL = re.compile( + "__LOCATED_VAR\((?P<IEC_TYPE>[A-Z]*),(?P<NAME>[_A-Za-z0-9]*),(?P<DIR>[QMI])(?:,(?P<SIZE>[XBWDL]))?,(?P<LOC>[,0-9]*)\)") result = LOCATED_MODEL.match(line)
resdict = result.groupdict()
- # rewrite string for variadic location as a tuple of integers
+ # rewrite string for variadic location as a tuple of resdict['LOC'] = tuple(map(int, resdict['LOC'].split(',')))
# set located size to 'X' if not given
@@ -721,16 +745,20 @@
# Update PLCOpenEditor ConfNode Block types before generate ST code
self.RefreshConfNodesBlockLists()
- self.logger.write(_("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n"))
+ _("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n")) # ask PLCOpenEditor controller to write ST/IL/SFC code file
- _program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath())
+ _program, errors, warnings = self.GenerateProgram( + self._getIECgeneratedcodepath()) - self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n"))
+ self.logger.write_warning( + _("Warnings in ST/IL/SFC code generator :\n")) self.logger.write_warning("%s\n" % warning)
- self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n") % errors[0])
+ self.logger.write_error( + _("Error in ST/IL/SFC code generator :\n%s\n") % errors[0]) plc_file = open(self._getIECcodepath(), "w")
# Add ST Library from confnodes
@@ -765,9 +793,11 @@
- # Invoke compiler. Output files are listed to stdout, errors to stderr
+ # Output files are listed to stdout, errors to stderr status, result, err_result = ProcessLogger(self.logger, buildcmd,
- no_stdout=True, no_stderr=True).spin()
self.logger.write_error(buildcmd + "\n")
self.logger.write_error(repr(e) + "\n")
@@ -796,29 +826,36 @@
if first_line <= i <= last_line:
if last_section is not None:
- self.logger.write_warning("In section: " + last_section)
+ self.logger.write_warning( + "In section: " + last_section) last_section = None # only write section once
self.logger.write_warning("%04d: %s" % (i, line))
- self.logger.write_error(_("Error : IEC to C compiler returned %d\n") % status)
+ self.logger.write_error( + _("Error : IEC to C compiler returned %d\n") % status) # Now extract C files of stdout
- C_files = [fname for fname in result.splitlines() if fname[-2:] == ".c" or fname[-2:] == ".C"]
+ C_files = [fname for fname in result.splitlines() if fname[ + -2:] == ".c" or fname[-2:] == ".C"] # remove those that are not to be compiled because included by others
- self.logger.write_error(_("Error : At least one configuration and one resource must be declared in PLC !\n"))
+ self.logger.write_error( + _("Error : At least one configuration and one resource must be declared in PLC !\n")) # transform those base names to full names with path
- C_files = map(lambda filename: os.path.join(buildpath, filename), C_files)
+ lambda filename: os.path.join(buildpath, filename), C_files) # prepend beremiz include to configuration header
- H_files = [fname for fname in result.splitlines() if fname[-2:] == ".h" or fname[-2:] == ".H"]
+ H_files = [fname for fname in result.splitlines() if fname[ + -2:] == ".h" or fname[-2:] == ".H"] H_files.remove("LOCATED_VARIABLES.h")
- H_files = map(lambda filename: os.path.join(buildpath, filename), H_files)
+ lambda filename: os.path.join(buildpath, filename), H_files) with file(H_file, 'r') as original:
@@ -826,7 +863,8 @@
modified.write('#include "beremiz.h"\n' + data)
self.logger.write(_("Extracting Located Variables...\n"))
- # Keep track of generated located variables for later use by self._Generate_C
+ # Keep track of generated located variables for later use by self.PLCGeneratedLocatedVars = self.GetLocations()
# Keep track of generated C files for later use by self.CTNGenerate_C
self.PLCGeneratedCFiles = C_files
@@ -861,11 +899,11 @@
- #######################################################################
# C CODE GENERATION METHODS
- #######################################################################
def CTNGenerate_C(self, buildpath, locations):
@@ -904,7 +942,8 @@
csvfile = os.path.join(self._getBuildPath(), "VARIABLES.csv")
ProgramsListAttributeName = ["num", "C_path", "type"]
- VariablesListAttributeName = ["num", "vartype", "IEC_path", "C_path", "type"]
+ VariablesListAttributeName = [ + "num", "vartype", "IEC_path", "C_path", "type"] self._DbgVariablesList = []
@@ -924,9 +963,11 @@
# first section contains programs
for line in ListGroup[0]:
# Split and Maps each field to dictionnary entries
- attrs = dict(zip(ProgramsListAttributeName, line.strip().split(';')))
+ zip(ProgramsListAttributeName, line.strip().split(';'))) # Truncate "C_path" to remove conf an resources names
- attrs["C_path"] = '__'.join(attrs["C_path"].split(".", 2)[1:])
+ attrs["C_path"] = '__'.join( + attrs["C_path"].split(".", 2)[1:]) # Push this dictionnary into result.
self._ProgramList.append(attrs)
@@ -935,7 +976,8 @@
for line in ListGroup[1]:
# Split and Maps each field to dictionnary entries
- attrs = dict(zip(VariablesListAttributeName, line.strip().split(';')))
+ zip(VariablesListAttributeName, line.strip().split(';'))) # Truncate "C_path" to remove conf an resources names
parts = attrs["C_path"].split(".", 2)
@@ -966,7 +1008,8 @@
self._Ticktime = int(ListGroup[2][0])
- self.logger.write_error(_("Cannot open/parse VARIABLES.csv!\n"))
+ self.logger.write_error( + _("Cannot open/parse VARIABLES.csv!\n")) self.logger.write_error(traceback.format_exc())
self.ResetIECProgramsAndVariables()
@@ -1036,16 +1079,16 @@
"retrieve_calls": "\n ".join([
"__retrieve_%s();" % locstr for locstr in locstrs]),
"publish_calls": "\n ".join([ # Call publish in reverse order
- "__publish_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]),
+ "__publish_%s();" % locstrs[i - 1] for i in xrange(len(locstrs), 0, -1)]), "init_calls": "\n ".join([
- "init_level=%d; " % (i+1) +
+ "init_level=%d; " % (i + 1) + "if((res = __init_%s(argc,argv))){" % locstr +
# "printf(\"%s\"); "%locstr + #for debug
"return res;}" for i, locstr in enumerate(locstrs)]),
"cleanup_calls": "\n ".join([
"if(init_level >= %d) " % i +
- "__cleanup_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)])
+ "__cleanup_%s();" % locstrs[i - 1] for i in xrange(len(locstrs), 0, -1)]) plc_main_code = targets.GetCode("plc_main_head.c") % {
"calls_prototypes": "\n",
@@ -1054,7 +1097,8 @@
- plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent().getLocalTag())
+ plc_main_code += targets.GetTargetCode( + self.GetTarget().getcontent().getLocalTag()) plc_main_code += targets.GetCode("plc_main_tail.c")
@@ -1126,21 +1170,25 @@
self.PLCGeneratedLocatedVars)
- self.logger.write_error(_("Runtime IO extensions C code generation failed !\n"))
+ self.logger.write_error( + _("Runtime IO extensions C code generation failed !\n")) self.logger.write_error(traceback.format_exc())
# Generate C code and compilation params from liraries
- LibCFilesAndCFLAGS, LibLDFLAGS, LibExtraFiles = self.GetLibrariesCCode(buildpath)
+ LibCFilesAndCFLAGS, LibLDFLAGS, LibExtraFiles = self.GetLibrariesCCode( - self.logger.write_error(_("Runtime library extensions C code generation failed !\n"))
+ self.logger.write_error( + _("Runtime library extensions C code generation failed !\n")) self.logger.write_error(traceback.format_exc())
- self.LocationCFilesAndCFLAGS = LibCFilesAndCFLAGS + CTNLocationCFilesAndCFLAGS
+ self.LocationCFilesAndCFLAGS = LibCFilesAndCFLAGS + \ + CTNLocationCFilesAndCFLAGS self.LDFLAGS = CTNLDFLAGS + LibLDFLAGS
ExtraFiles = CTNExtraFiles + LibExtraFiles
@@ -1159,7 +1207,8 @@
# Header file for extensions
- open(os.path.join(buildpath, "beremiz.h"), "w").write(targets.GetHeader())
+ open(os.path.join(buildpath, "beremiz.h"), "w").write( # Template based part of C code generation
# files are stacked at the beginning, as files of confnode tree root
@@ -1178,10 +1227,12 @@
code_path = os.path.join(buildpath, filename)
open(code_path, "w").write(code)
- # Insert this file as first file to be compiled at root confnode
- self.LocationCFilesAndCFLAGS[0][1].insert(0, (code_path, self.plcCFLAGS))
+ # Insert this file as first file to be compiled at root + self.LocationCFilesAndCFLAGS[0][1].insert( + 0, (code_path, self.plcCFLAGS)) - self.logger.write_error(name+_(" generation failed !\n"))
+ self.logger.write_error(name + _(" generation failed !\n")) self.logger.write_error(traceback.format_exc())
@@ -1191,12 +1242,16 @@
def ShowError(self, logger, from_location, to_location):
chunk_infos = self.GetChunkInfos(from_location, to_location)
for infos, (start_row, start_col) in chunk_infos:
- row = 1 if from_location[0] < start_row else (from_location[0] - start_row)
- col = 1 if (start_row != from_location[0]) else (from_location[1] - start_col)
+ row = 1 if from_location[0] < start_row else ( + from_location[0] - start_row) + col = 1 if (start_row != from_location[0]) else ( + from_location[1] - start_col) - row = 1 if to_location[0] < start_row else (to_location[0] - start_row)
- col = 1 if (start_row != to_location[0]) else (to_location[1] - start_col)
+ row = 1 if to_location[0] < start_row else ( + to_location[0] - start_row) + col = 1 if (start_row != to_location[0]) else ( + to_location[1] - start_col) if self.AppFrame is not None:
@@ -1227,7 +1282,8 @@
if self._IECCodeView is None:
plc_file = self._getIECcodepath()
- self._IECCodeView = IECCodeViewer(self.AppFrame.TabsOpened, "", self.AppFrame, None, instancepath=name)
+ self._IECCodeView = IECCodeViewer( + self.AppFrame.TabsOpened, "", self.AppFrame, None, instancepath=name) self._IECCodeView.SetTextSyntax("ALL")
self._IECCodeView.SetKeywords(IEC_KEYWORDS)
@@ -1248,7 +1304,8 @@
if self._IECRawCodeView is None:
controler = MiniTextControler(self._getIECrawcodepath(), self)
- self._IECRawCodeView = IECCodeViewer(self.AppFrame.TabsOpened, "", self.AppFrame, controler, instancepath=name)
+ self._IECRawCodeView = IECCodeViewer( + self.AppFrame.TabsOpened, "", self.AppFrame, controler, instancepath=name) self._IECRawCodeView.SetTextSyntax("ALL")
self._IECRawCodeView.SetKeywords(IEC_KEYWORDS)
self._IECRawCodeView.RefreshView()
@@ -1262,7 +1319,8 @@
elif name == "Project Files":
if self._ProjectFilesView is None:
- self._ProjectFilesView = FileManagementPanel(self.AppFrame.TabsOpened, self, name, self._getProjectFilesPath(), True)
+ self._ProjectFilesView = FileManagementPanel( + self.AppFrame.TabsOpened, self, name, self._getProjectFilesPath(), True) for extension, name, editor in features.file_editors:
@@ -1304,7 +1362,8 @@
name = "::".join([filepath, editor_name])
editor = editors[editor_name]()
- self._FileEditors[filepath] = editor(self.AppFrame.TabsOpened, self, name, self.AppFrame)
+ self._FileEditors[filepath] = editor( + self.AppFrame.TabsOpened, self, name, self.AppFrame) self._FileEditors[filepath].SetIcon(GetBitmap("FILE"))
if isinstance(self._FileEditors[filepath], DebugViewer):
self._FileEditors[filepath].SetDataProducer(self)
@@ -1395,18 +1454,20 @@
self.MethodsFromStatus.get(status, {}))
for method, active in allmethods.items():
- self.ShowMethod(method,active)
+ self.ShowMethod(method, active) self.previous_plcstate = status
if self.AppFrame is not None:
self.AppFrame.RefreshStatusToolBar()
if status == "Disconnected":
- self.AppFrame.ConnectionStatusBar.SetStatusText(self.GetTextStatus(status), 1)
+ self.AppFrame.ConnectionStatusBar.SetStatusText( + self.GetTextStatus(status), 1) self.AppFrame.ConnectionStatusBar.SetStatusText('', 2)
self.AppFrame.ConnectionStatusBar.SetStatusText(
_("Connected to URI: %s") % self.BeremizRoot.getURI_location().strip(), 1)
- self.AppFrame.ConnectionStatusBar.SetStatusText(self.GetTextStatus(status), 2)
+ self.AppFrame.ConnectionStatusBar.SetStatusText( + self.GetTextStatus(status), 2) def GetTextStatus(self, status):
@@ -1416,12 +1477,13 @@
"Disconnected": _("Disconnected")
return msgs.get(status, status)
def ShowPLCProgress(self, status="", progress=0):
self.AppFrame.ProgressStatusBar.Show()
- self.AppFrame.ConnectionStatusBar.SetStatusText(self.GetTextStatus(status), 1)
+ self.AppFrame.ConnectionStatusBar.SetStatusText( + self.GetTextStatus(status), 1) self.AppFrame.ProgressStatusBar.SetValue(progress)
def HidePLCProgress(self):
@@ -1437,19 +1499,23 @@
def SnapshotAndResetDebugValuesBuffers(self):
if self._connector is not None:
plc_status, Traces = self._connector.GetTraceVariables()
- # print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()]
+ # print [dict.keys() for IECPath, (dict, log, status, fvalue) in + # self.IECdebug_datas.items()] if plc_status == "Started":
for debug_tick, debug_buff in Traces:
- debug_vars = UnpackDebugBuffer(debug_buff, self.TracedIECTypes)
+ debug_vars = UnpackDebugBuffer( + debug_buff, self.TracedIECTypes) if debug_vars is not None and len(debug_vars) == len(self.TracedIECPath):
for IECPath, values_buffer, value in izip(
- IECdebug_data = self.IECdebug_datas.get(IECPath, None)
+ IECdebug_data = self.IECdebug_datas.get( if IECdebug_data is not None and value is not None:
- forced = IECdebug_data[2:4] == ["Forced", value]
+ forced = IECdebug_data[2:4] == [ if not IECdebug_data[4] and len(values_buffer) > 0:
values_buffer[-1] = (value, forced)
@@ -1478,14 +1544,17 @@
IECPathsToPop.append(IECPath)
elif IECPath != "__tick__":
- Idx, IEC_Type = self._IECPathToIdx.get(IECPath, (None, None))
+ Idx, IEC_Type = self._IECPathToIdx.get( if IEC_Type in DebugTypesSize:
Idxs.append((Idx, IEC_Type, fvalue, IECPath))
- self.logger.write_warning(_("Debug: Unsupported type to debug '%s'\n") % IEC_Type)
+ self.logger.write_warning( + _("Debug: Unsupported type to debug '%s'\n") % IEC_Type) - self.logger.write_warning(_("Debug: Unknown variable '%s'\n") % IECPath)
+ self.logger.write_warning( + _("Debug: Unknown variable '%s'\n") % IECPath) for IECPathToPop in IECPathsToPop:
self.IECdebug_datas.pop(IECPathToPop)
@@ -1512,8 +1581,10 @@
# Links between PLC located variables and real variables are not ready
# Timer to prevent rapid-fire when registering many variables
- # use wx.CallAfter use keep using same thread. TODO : use wx.Timer instead
- self.DebugTimer = Timer(0.5, wx.CallAfter, args=[self.RegisterDebugVarToConnector])
+ # use wx.CallAfter use keep using same thread. TODO : use wx.Timer + self.DebugTimer = Timer( + 0.5, wx.CallAfter, args=[self.RegisterDebugVarToConnector]) # Rearm anti-rapid-fire timer
@@ -1617,9 +1688,11 @@
if len(self.TracedIECPath) == len(buffers):
for IECPath, values in izip(self.TracedIECPath, buffers):
- self.CallWeakcallables(IECPath, "NewValues", debug_ticks, values)
+ self.CallWeakcallables( + IECPath, "NewValues", debug_ticks, values) - self.CallWeakcallables("__tick__", "NewDataAvailable", debug_ticks)
+ self.CallWeakcallables( + "__tick__", "NewDataAvailable", debug_ticks) delay = time.time() - start_time
next_refresh = max(REFRESH_PERIOD - delay, 0.2 * delay)
@@ -1684,7 +1757,8 @@
# don't accept re-connetion if already connected
if self._connector is not None:
- self.logger.write_error(_("Already connected. Please disconnect\n"))
+ self.logger.write_error( + _("Already connected. Please disconnect\n")) @@ -1722,7 +1796,8 @@
self._SetConnector(connectors.ConnectorFactory(uri, self))
- self.logger.write_error(_("Exception while connecting %s!\n") % uri)
+ self.logger.write_error( + _("Exception while connecting %s!\n") % uri) self.logger.write_error(traceback.format_exc())
# Did connection success ?
@@ -1739,7 +1814,8 @@
self.logger.write(_("Debugger ready\n"))
- self.logger.write_warning(_("Debug does not match PLC - stop/transfert/start to re-enable\n"))
+ self.logger.write_warning( + _("Debug does not match PLC - stop/transfert/start to re-enable\n")) def CompareLocalAndRemotePLC(self):
if self._connector is None:
@@ -1750,7 +1826,8 @@
if not self._connector.MatchMD5(MD5):
# self.logger.write_warning(
- # _("Latest build does not match with target, please transfer.\n"))
+ # _("Latest build does not match with target, please self.EnableMethod("_Transfer", True)
@@ -1783,7 +1860,8 @@
# Check if md5 file is empty : ask user to build PLC
- self.logger.write_error(_("Failed : Must build before transfer.\n"))
+ self.logger.write_error( + _("Failed : Must build before transfer.\n")) # Compare PLC project with PLC on target
@@ -1818,7 +1896,8 @@
self.logger.write_error(_("Transfer failed\n"))
- self.logger.write_error(_("No PLC to transfer (did build succeed ?)\n"))
+ self.logger.write_error( + _("No PLC to transfer (did build succeed ?)\n")) wx.CallAfter(self.UpdateMethodsFromPLCStatus)
--- a/runtime/WampClient.py Tue Aug 07 13:35:28 2018 +0200
+++ b/runtime/WampClient.py Wed Aug 08 10:15:51 2018 +0200
@@ -67,9 +67,9 @@
# de-activated dumb wamp config
"url": "ws://127.0.0.1:8888"
@@ -84,6 +84,7 @@
""" Get Callee or Subscriber corresponding to '.' spearated object path """
@@ -94,6 +95,7 @@
class WampSession(wamp.ApplicationSession):
if "secret" in self.config.extra:
user = self.config.extra["ID"]
@@ -105,12 +107,14 @@
if challenge.method == u"wampcra":
if "secret" in self.config.extra:
secret = self.config.extra["secret"].encode('utf8')
- signature = auth.compute_wcs(secret, challenge.extra['challenge'].encode('utf8'))
+ signature = auth.compute_wcs( + secret, challenge.extra['challenge'].encode('utf8')) return signature.decode("ascii")
raise Exception("no secret given for authentication")
- raise Exception("don't know how to handle authmethod {}".format(challenge.method))
+ "don't know how to handle authmethod {}".format(challenge.method)) def onJoin(self, details):
@@ -144,6 +148,7 @@
class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
def __init__(self, config, *args, **kwargs):
WampWebSocketClientFactory.__init__(self, *args, **kwargs)
@@ -163,15 +168,19 @@
def clientConnectionFailed(self, connector, reason):
- print(_("WAMP Client connection failed (%s) .. retrying ..") % time.ctime())
- super(ReconnectingWampWebSocketClientFactory, self).clientConnectionFailed(connector, reason)
+ print(_("WAMP Client connection failed (%s) .. retrying ..") % + super(ReconnectingWampWebSocketClientFactory, + self).clientConnectionFailed(connector, reason) def clientConnectionLost(self, connector, reason):
- print(_("WAMP Client connection lost (%s) .. retrying ..") % time.ctime())
- super(ReconnectingWampWebSocketClientFactory, self).clientConnectionFailed(connector, reason)
+ print(_("WAMP Client connection lost (%s) .. retrying ..") % + super(ReconnectingWampWebSocketClientFactory, + self).clientConnectionFailed(connector, reason) @@ -180,20 +189,22 @@
url = WampClientConf["url"]
if not IsCorrectUri(url):
raise annotate.ValidateError(
- {"url":"Invalid URL: {}".format(url)},
+ {"url": "Invalid URL: {}".format(url)}, _("WAMP configuration error:"))
if os.path.exists(_WampConf):
WampClientConf = json.load(open(_WampConf))
WampClientConf = defaultWampConfig.copy()
for itemName in mandatoryConfigItems:
- if WampClientConf.get(itemName, None) is None :
- raise Exception(_("WAMP configuration error : missing '{}' parameter.").format(itemName))
+ if WampClientConf.get(itemName, None) is None: + _("WAMP configuration error : missing '{}' parameter.").format(itemName)) CheckConfiguration(WampClientConf)
@@ -205,13 +216,14 @@
with open(os.path.realpath(_WampSecret), 'w') as f:
def SetConfiguration(WampClientConf):
CheckConfiguration(WampClientConf)
lastKnownConfig = WampClientConf.copy()
with open(os.path.realpath(_WampConf), 'w') as f:
json.dump(WampClientConf, f, sort_keys=True, indent=4)
if 'active' in WampClientConf and WampClientConf['active']:
@@ -226,7 +238,7 @@
def LoadWampSecret(secretfname):
WSClientWampSecret = open(secretfname, 'rb').read()
- if len(WSClientWampSecret) == 0 :
+ if len(WSClientWampSecret) == 0: raise Exception(_("WAMP secret empty"))
return WSClientWampSecret
@@ -252,7 +264,8 @@
# set secret file path only if not already set
- # default project's wamp secret also has precedance over commandline given
+ # default project's wamp secret also + # has precedance over commandline given if os.path.exists(_WampSecretDefault):
_WampSecret = _WampSecretDefault
@@ -260,7 +273,7 @@
if _WampSecret is not None:
WampClientConf["secret"] = LoadWampSecret(_WampSecret)
print(_("WAMP authentication has no secret configured"))
_WampSecret = _WampSecretDefault
@@ -285,7 +298,7 @@
# start the client from a Twisted endpoint
- conn = connectWS(_transportFactory)
+ connectWS(_transportFactory) print(_("WAMP client connecting to :"), WampClientConf["url"])
@@ -294,9 +307,9 @@
def StopReconnectWampClient():
- if _transportFactory is not None :
+ if _transportFactory is not None: _transportFactory.stopTrying()
- if _WampSession is not None :
+ if _WampSession is not None: @@ -314,10 +327,11 @@
- if _transportFactory is not None :
- if _WampSession is not None :
- if _WampSession.is_attached() :
+ if _transportFactory is not None: + if _WampSession is not None: + if _WampSession.is_attached(): @@ -328,14 +342,16 @@
-#### WEB CONFIGURATION INTERFACE ####
+# WEB CONFIGURATION INTERFACE WAMP_SECRET_URL = "secret"
webExposedConfigItems = ['active', 'url', 'ID']
-def wampConfigDefault(ctx,argument):
- if lastKnownConfig is not None :
+def wampConfigDefault(ctx, argument): + if lastKnownConfig is not None: return lastKnownConfig.get(argument.name, None)
def wampConfig(**kwargs):
secretfile_field = kwargs["secretfile"]
if secretfile_field is not None:
@@ -347,69 +363,73 @@
newConfig = lastKnownConfig.copy()
for argname in webExposedConfigItems:
arg = kwargs.get(argname, None)
SetConfiguration(newConfig)
class FileUploadDownload(annotate.FileUpload):
class FileUploadDownloadRenderer(webform.FileUploadRenderer):
def input(self, context, slot, data, name, value):
+ # pylint: disable=expression-not-assigned - slot = webform.FileUploadRenderer.input(self, context, slot, data, name, value)
+ slot = webform.FileUploadRenderer.input( + self, context, slot, data, name, value) download_url = data.typedValue.getAttribute('download_url')
return slot[tags.a(href=download_url)[_("Download")]]
-registerAdapter(FileUploadDownloadRenderer, FileUploadDownload, formless.iformless.ITypedRenderer)
+registerAdapter(FileUploadDownloadRenderer, FileUploadDownload, + formless.iformless.ITypedRenderer) def getDownloadUrl(ctx, argument):
- if lastKnownConfig is not None :
+ if lastKnownConfig is not None: return url.URL.fromContext(ctx).\
- child(lastKnownConfig["ID"]+".secret")
+ child(lastKnownConfig["ID"] + ".secret") - annotate.String(label=_("Current status"),
- default = lambda *k:getWampStatus())),
+ annotate.String(label=_("Current status"), + default=lambda *k:getWampStatus())), - annotate.String(label=_("ID"),
- default = wampConfigDefault)),
+ annotate.String(label=_("ID"), + default=wampConfigDefault)),
- label = _("File containing secret for that ID"),
- download_url = getDownloadUrl,
+ FileUploadDownload(label=_("File containing secret for that ID"), + download_url=getDownloadUrl)), - annotate.Boolean(label=_("Enable WAMP connection"),
- default=wampConfigDefault)),
+ annotate.Boolean(label=_("Enable WAMP connection"), + default=wampConfigDefault)), - annotate.String(label=_("WAMP Server URL"),
- default=wampConfigDefault))]
+ annotate.String(label=_("WAMP Server URL"), + default=wampConfigDefault))] def deliverWampSecret(ctx, segments):
- filename = segments[1].decode('utf-8')
+ # filename = segments[1].decode('utf-8') # FIXME: compare filename to ID+".secret"
# for now all url under /secret returns the secret
- # TODO: make beutifull message in case of exception
+ # TODO: make beautifull message in case of exception # while loading secret (if empty or dont exist)
secret = LoadWampSecret(_WampSecret)
- return static.Data(secret, 'application/octet-stream'),()
+ return static.Data(secret, 'application/octet-stream'), () def RegisterWebSettings(NS):
NS.ConfigurableSettings.addExtension(
NS.customSettingsURLs[WAMP_SECRET_URL] = deliverWampSecret