# HG changeset patch # User Edouard Tisserant # Date 1519132611 -3600 # Node ID 5736d25bb393b19c850814c32405a91136592d19 # Parent 0c20fc810d6151de7ef06ed1635c77a744d0abe1 PEP8 and PyLint conformance: whitespaces and stuff diff -r 0c20fc810d61 -r 5736d25bb393 Beremiz.py --- a/Beremiz.py Tue Feb 20 11:24:40 2018 +0100 +++ b/Beremiz.py Tue Feb 20 14:16:51 2018 +0100 @@ -28,13 +28,13 @@ import os import sys import getopt -import time import wx from wx.lib.agw.advancedsplash import AdvancedSplash, AS_NOTIMEOUT, AS_CENTER_ON_SCREEN import util.paths as paths + class BeremizIDELauncher(object): def __init__(self): self.app = None @@ -102,8 +102,9 @@ def CreateApplication(self): BeremizAppType = wx.App if wx.VERSION >= (3, 0, 0) else wx.PySimpleApp + class BeremizApp(BeremizAppType): - def OnInit(_self): + def OnInit(_self): # pylint: disable=no-self-argument self.ShowSplashScreen() return True @@ -114,15 +115,14 @@ def ShowSplashScreen(self): class Splash(AdvancedSplash): - def OnPaint(_self, event): + def OnPaint(_self, event): # pylint: disable=no-self-argument AdvancedSplash.OnPaint(_self, event) wx.CallAfter(self.AppStart) bmp = wx.Image(self.splashPath).ConvertToBitmap() - self.splash = Splash(None, - bitmap=bmp, + self.splash = Splash(None, + bitmap=bmp, agwStyle=AS_NOTIMEOUT | AS_CENTER_ON_SCREEN) - def BackgroundInitialization(self): self.InitI18n() self.CheckUpdates() @@ -191,7 +191,7 @@ def PreStart(self): self.ProcessCommandLineArgs() self.CreateApplication() - + def AppStart(self): try: self.BackgroundInitialization() @@ -201,7 +201,7 @@ # except (KeyboardInterrupt, SystemExit): # raise except Exception: - self.handle_exception(*sys.exc_info(), exit = True) + self.handle_exception(*sys.exc_info(), exit=True) def MainLoop(self): self.app.MainLoop() diff -r 0c20fc810d61 -r 5736d25bb393 Beremiz_service.py --- a/Beremiz_service.py Tue Feb 20 11:24:40 2018 +0100 +++ b/Beremiz_service.py Tue Feb 20 14:16:51 2018 +0100 @@ -425,7 +425,7 @@ # pyro never frees memory after connection close if no timeout set # taking too small timeout value may cause # unwanted diconnection when IDE is kept busy for long periods - self.daemon.setTimeout(60); + self.daemon.setTimeout(60) self.Start() self.daemon.requestLoop() self.daemon.sock.close() @@ -590,7 +590,7 @@ # Find pre-existing project WAMP config file _wampconf = os.path.join(WorkingDir, "wampconf.json") - # If project's WAMP config file exits, override default (-c) + # If project's WAMP config file exits, override default (-c) if os.path.exists(_wampconf): wampconf = _wampconf diff -r 0c20fc810d61 -r 5736d25bb393 PLCControler.py --- a/PLCControler.py Tue Feb 20 11:24:40 2018 +0100 +++ b/PLCControler.py Tue Feb 20 14:16:51 2018 +0100 @@ -36,10 +36,9 @@ from lxml import etree import util.paths as paths -from util.TranslationCatalogs import NoTranslate from plcopen import * from plcopen.types_enums import * -from plcopen.XSLTModelQuery import _StringValue, _BoolValue, _translate_args +from plcopen.XSLTModelQuery import _StringValue, _BoolValue, _translate_args from plcopen.InstancesPathCollector import InstancesPathCollector from plcopen.POUVariablesCollector import POUVariablesCollector from plcopen.InstanceTagnameCollector import InstanceTagnameCollector @@ -51,6 +50,7 @@ ScriptDirectory = paths.AbsDir(__file__) + class LibraryResolver(etree.Resolver): """Helper object for loading library in xslt stylesheets""" @@ -587,7 +587,7 @@ def GetPouInstanceTagName(self, instance_path, debug=False): project = self.GetProject(debug) - if project is not None : + if project is not None: return self.InstanceTagnameCollector.Collect(project, debug, instance_path) @@ -1110,8 +1110,8 @@ def GetVariableDictionary(self, object_with_vars, tree=False, debug=False): variables = [] - factory = self.VariableInfoCollector.Collect(object_with_vars, - debug, variables, tree) + self.VariableInfoCollector.Collect(object_with_vars, + debug, variables, tree) return variables # Add a global var to configuration to configuration @@ -1264,7 +1264,7 @@ # Return the return type if there is one return_type = pou.interface.getreturnType() if return_type is not None: - factory = self.VariableInfoCollector.Collect(return_type, + factory = self.VariableInfoCollector.Collect(return_type, debug, [], tree) if tree: return [factory.GetType(), factory.GetTree()] diff -r 0c20fc810d61 -r 5736d25bb393 ProjectController.py --- a/ProjectController.py Tue Feb 20 11:24:40 2018 +0100 +++ b/ProjectController.py Tue Feb 20 14:16:51 2018 +0100 @@ -68,7 +68,6 @@ MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$") - def ExtractChildrenTypesFromCatalog(catalog): children_types = [] for n, d, _h, c in catalog: @@ -1810,9 +1809,9 @@ def _Transfer(self): if self.IsPLCStarted(): dialog = wx.MessageDialog( - self.AppFrame, - _("Cannot transfer while PLC is running. Stop it now?"), - style=wx.YES_NO|wx.CENTRE) + self.AppFrame, + _("Cannot transfer while PLC is running. Stop it now?"), + style=wx.YES_NO | wx.CENTRE) if dialog.ShowModal() == wx.ID_YES: self._Stop() else: diff -r 0c20fc810d61 -r 5736d25bb393 controls/VariablePanel.py --- a/controls/VariablePanel.py Tue Feb 20 11:24:40 2018 +0100 +++ b/controls/VariablePanel.py Tue Feb 20 14:16:51 2018 +0100 @@ -32,6 +32,7 @@ import wx.lib.buttons from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType +from plcopen.VariableInfoCollector import _VariableInfos from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT from dialogs.ArrayTypeDialog import ArrayTypeDialog from controls.CustomGrid import CustomGrid @@ -39,7 +40,6 @@ from controls.LocationCellEditor import LocationCellEditor from util.BitmapLibrary import GetBitmap from util.TranslationCatalogs import NoTranslate -from plcopen.VariableInfoCollector import _VariableInfos # ------------------------------------------------------------------------------- diff -r 0c20fc810d61 -r 5736d25bb393 editors/ProjectNodeEditor.py --- a/editors/ProjectNodeEditor.py Tue Feb 20 11:24:40 2018 +0100 +++ b/editors/ProjectNodeEditor.py Tue Feb 20 14:16:51 2018 +0100 @@ -51,7 +51,7 @@ return self.ProjectProperties def __init__(self, parent, controler, window): - configuration = GetProjectMainConfigurationName() + configuration = self.Controler.GetProjectMainConfigurationName() if configuration is not None: tagname = ComputeConfigurationName(configuration) else: diff -r 0c20fc810d61 -r 5736d25bb393 editors/Viewer.py --- a/editors/Viewer.py Tue Feb 20 11:24:40 2018 +0100 +++ b/editors/Viewer.py Tue Feb 20 14:16:51 2018 +0100 @@ -34,7 +34,6 @@ from plcopen.structures import * from plcopen.types_enums import ComputePouName from PLCControler import ITEM_VAR_LOCAL, ITEM_POU, ITEM_PROGRAM, ITEM_FUNCTIONBLOCK -from graphics.DebugDataConsumer import DebugDataConsumer from graphics.GraphicCommons import * from graphics.FBD_Objects import * diff -r 0c20fc810d61 -r 5736d25bb393 graphics/__init__.py --- a/graphics/__init__.py Tue Feb 20 11:24:40 2018 +0100 +++ b/graphics/__init__.py Tue Feb 20 14:16:51 2018 +0100 @@ -23,4 +23,3 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Package initialisation - diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/InstanceTagnameCollector.py --- a/plcopen/InstanceTagnameCollector.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/InstanceTagnameCollector.py Tue Feb 20 14:16:51 2018 +0100 @@ -4,9 +4,10 @@ # See COPYING file for copyrights details. from __future__ import absolute_import -from plcopen.XSLTModelQuery import XSLTModelQuery +from plcopen.XSLTModelQuery import XSLTModelQuery from plcopen.types_enums import * + class InstanceTagName(object): """Helpers object for generating instance tagname""" @@ -38,12 +39,12 @@ XSLTModelQuery.__init__(self, controller, "instance_tagname.xslt", - [(name, self.FactoryCaller(name)) - for name in ["ConfigTagName", - "ResourceTagName", - "PouTagName", - "ActionTagName", - "TransitionTagName"]]) + [(name, self.FactoryCaller(name)) + for name in ["ConfigTagName", + "ResourceTagName", + "PouTagName", + "ActionTagName", + "TransitionTagName"]]) def FactoryCaller(self, funcname): def CallFactory(*args): diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/InstancesPathCollector.py --- a/plcopen/InstancesPathCollector.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/InstancesPathCollector.py Tue Feb 20 14:16:51 2018 +0100 @@ -6,6 +6,7 @@ from __future__ import absolute_import from plcopen.XSLTModelQuery import XSLTModelQuery + class InstancesPathCollector(XSLTModelQuery): """ object for collecting instances path list""" def __init__(self, controller): @@ -19,8 +20,7 @@ self.Instances.append(args[0][0]) def Collect(self, root, name, debug): - self._process_xslt(root, debug, instance_type = name) + self._process_xslt(root, debug, instance_type=name) res = self.Instances self.Instances = [] return res - diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/POUVariablesCollector.py --- a/plcopen/POUVariablesCollector.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/POUVariablesCollector.py Tue Feb 20 14:16:51 2018 +0100 @@ -7,6 +7,7 @@ from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args from plcopen.types_enums import CLASS_TYPES, POU_TYPES, VAR_CLASS_INFOS + def class_extraction(value): class_type = CLASS_TYPES.get(value) if class_type is not None: @@ -56,14 +57,13 @@ [_BoolValue] * 2, args) + [[]]))) - class POUVariablesCollector(XSLTModelQuery): def __init__(self, controller): XSLTModelQuery.__init__(self, controller, "pou_variables.xslt", - [(name, self.FactoryCaller(name)) - for name in ["SetRoot", "AddVariable"]]) + [(name, self.FactoryCaller(name)) + for name in ["SetRoot", "AddVariable"]]) def FactoryCaller(self, funcname): def CallFactory(*args): @@ -76,4 +76,3 @@ res = self.factory.GetRoot() self.factory = None return res - diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/VariableInfoCollector.py --- a/plcopen/VariableInfoCollector.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/VariableInfoCollector.py Tue Feb 20 14:16:51 2018 +0100 @@ -10,6 +10,7 @@ # Helpers object for generating pou var list # ------------------------------------------------------------------------------- + class _VariableInfos(object): __slots__ = ["Name", "Class", "Option", "Location", "InitialValue", "Edit", "Documentation", "Type", "Tree", "Number"] @@ -65,13 +66,13 @@ XSLTModelQuery.__init__(self, controller, "variables_infos.xslt", - [(name, self.FactoryCaller(name)) - for name in [ - "SetType", - "AddDimension", - "AddTree", - "AddVarToTree", - "AddVariable"]]) + [(name, self.FactoryCaller(name)) + for name in [ + "SetType", + "AddDimension", + "AddTree", + "AddVarToTree", + "AddVariable"]]) def FactoryCaller(self, funcname): def CallFactory(*args): @@ -84,4 +85,3 @@ res = self.factory self.factory = None return res - diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/XSLTModelQuery.py --- a/plcopen/XSLTModelQuery.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/XSLTModelQuery.py Tue Feb 20 14:16:51 2018 +0100 @@ -14,30 +14,33 @@ class XSLTModelQuery(object): """ a class to handle XSLT queries on project and libs """ - def __init__(self, controller, xsltpath, ext = []): + def __init__(self, controller, xsltpath, ext=None): # arbitrary set debug to false, updated later self.debug = False # merge xslt extensions for library access to query specific ones xsltext = [ - ("GetProject", lambda *_ignored: - [controller.GetProject(self.debug)]), - ("GetStdLibs", lambda *_ignored: - [lib for lib in StdBlckLibs.values()]), - ("GetExtensions", lambda *_ignored: - [ctn["types"] for ctn in controller.ConfNodeTypes]) - ] + ext + ("GetProject", lambda *_ignored: + [controller.GetProject(self.debug)]), + ("GetStdLibs", lambda *_ignored: + [lib for lib in StdBlckLibs.values()]), + ("GetExtensions", lambda *_ignored: + [ctn["types"] for ctn in controller.ConfNodeTypes]) + ] - # parse and compile. "beremiz" arbitrary namespace for extensions + if ext is not None: + xsltext.extend(ext) + + # parse and compile. "beremiz" arbitrary namespace for extensions self.xslt = etree.XSLT( etree.parse( os.path.join(ScriptDirectory, xsltpath), etree.XMLParser()), - extensions={ ("beremiz", name):call for name, call in xsltext}) + extensions={("beremiz", name): call for name, call in xsltext}) def _process_xslt(self, root, debug, **kwargs): self.debug = debug - res = self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()}) + res = self.xslt(root, **{k: etree.XSLT.strparam(v) for k, v in kwargs.iteritems()}) # print(self.xslt.error_log) return res @@ -60,4 +63,3 @@ return [translate(arg[0]) if len(arg) > 0 else None for translate, arg in zip(translations, args)] - diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/types_enums.py --- a/plcopen/types_enums.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/types_enums.py Tue Feb 20 14:16:51 2018 +0100 @@ -73,8 +73,8 @@ LOCATION_VAR_MEMORY] = range(6) UNEDITABLE_NAMES = [_("User-defined POUs"), _("Functions"), _("Function Blocks"), - _("Programs"), _("Data Types"), _("Transitions"), _("Actions"), - _("Configurations"), _("Resources"), _("Properties")] + _("Programs"), _("Data Types"), _("Transitions"), _("Actions"), + _("Configurations"), _("Resources"), _("Properties")] [USER_DEFINED_POUS, FUNCTIONS, FUNCTION_BLOCKS, PROGRAMS, DATA_TYPES, TRANSITIONS, ACTIONS, CONFIGURATIONS, @@ -84,30 +84,37 @@ # Project Element tag name computation functions # ------------------------------------------------------------------------------- + # Compute a data type name def ComputeDataTypeName(datatype): return "D::%s" % datatype + # Compute a pou name def ComputePouName(pou): return "P::%s" % pou + # Compute a pou transition name def ComputePouTransitionName(pou, transition): return "T::%s::%s" % (pou, transition) + # Compute a pou action name def ComputePouActionName(pou, action): return "A::%s::%s" % (pou, action) + # Compute a pou name def ComputeConfigurationName(config): return "C::%s" % config + # Compute a pou name def ComputeConfigurationResourceName(config, resource): return "R::%s::%s" % (config, resource) + def GetElementType(tagname): words = tagname.split("::") return { diff -r 0c20fc810d61 -r 5736d25bb393 util/ExceptionHandler.py --- a/util/ExceptionHandler.py Tue Feb 20 11:24:40 2018 +0100 +++ b/util/ExceptionHandler.py Tue Feb 20 14:16:51 2018 +0100 @@ -74,7 +74,8 @@ finally: dlg.Destroy() - if exit : sys.exit() #wx.Exit() + if exit: + sys.exit() # wx.Exit() return res @@ -127,7 +128,7 @@ output.write(a + ":\n" + str(info[a]) + "\n\n") output.close() - def handle_exception(e_type, e_value, e_traceback, exit = False): + def handle_exception(e_type, e_value, e_traceback, exit=False): traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func last_tb = get_last_traceback(e_traceback) ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) diff -r 0c20fc810d61 -r 5736d25bb393 util/misc.py --- a/util/misc.py Tue Feb 20 11:24:40 2018 +0100 +++ b/util/misc.py Tue Feb 20 14:16:51 2018 +0100 @@ -46,6 +46,7 @@ return False return True + def GetClassImporter(param): """ is used to resolve library class names in features.py @@ -60,7 +61,7 @@ return reduce(getattr, param.split('.')[1:], mod) return factory else: - return lambda : param + return lambda: param def InstallLocalRessources(CWD):