Another set of meaningless changes to satisfy PEP8 and PyLint.
authorEdouard Tisserant
Thu, 01 Feb 2018 14:51:18 +0100
changeset 1919 ccea0fa6ea91
parent 1918 e7b6478b4ebc
child 1920 584ad449ee58
Another set of meaningless changes to satisfy PEP8 and PyLint.
Beremiz_service.py
canfestival/canfestival.py
canfestival/config_utils.py
connectors/PYRO/__init__.py
controls/DebugVariablePanel/DebugVariableGraphicViewer.py
i18n/mki18n.py
modbus/__init__.py
modbus/mb_utils.py
modbus/modbus.py
runtime/NevowServer.py
runtime/PLCObject.py
svgui/svgui_server.py
util/ProcessLogger.py
--- a/Beremiz_service.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/Beremiz_service.py	Thu Feb 01 14:51:18 2018 +0100
@@ -173,6 +173,8 @@
         # __builtin__.__dict__['_'] = wx.GetTranslation
 
 
+# Life is hard... have a candy.
+# pylint: disable=wrong-import-position,wrong-import-order
 if enablewx:
     try:
         import wx
@@ -549,7 +551,7 @@
 
 
 def LogException(*exp):
-    LogExceptionAndMessage("", exp)
+    LogMessageAndException("", exp)
 
 sys.excepthook = LogException
 
--- a/canfestival/canfestival.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/canfestival/canfestival.py	Thu Feb 01 14:51:18 2018 +0100
@@ -28,8 +28,8 @@
 import sys
 import shutil
 import wx
-from gnosis.xml.pickle import *
-from gnosis.xml.pickle.util import setParanoia
+from gnosis.xml.pickle import *  # pylint: disable=import-error
+from gnosis.xml.pickle.util import setParanoia  # pylint: disable=import-error
 
 import util.paths as paths
 from util.TranslationCatalogs import AddCatalog
@@ -50,7 +50,7 @@
 from nodemanager import NodeManager
 import gen_cfile
 import eds_utils
-import canfestival_config as local_canfestival_config
+import canfestival_config as local_canfestival_config  # pylint: disable=import-error
 
 from commondialogs import CreateNodeDialog
 from subindextable import IECTypeConversion, SizeConversion
@@ -463,7 +463,9 @@
             raise Exception(res)
 
         file = open(os.path.join(buildpath, "MasterGenerated.od"), "w")
-        dump(master, file)
+        # linter disabled here, undefined variable happens
+        # here because gnosis isn't impored while linting
+        dump(master, file)  # pylint: disable=undefined-variable
         file.close()
 
         return [(Gen_OD_path, local_canfestival_config.getCFLAGS(CanFestivalPath))], "", False
--- a/canfestival/config_utils.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/canfestival/config_utils.py	Thu Feb 01 14:51:18 2018 +0100
@@ -697,7 +697,7 @@
     return pointers
 
 
-if __name__ == "__main__":
+if __name__ == "__main__":  # pylint: disable=all
     def usage():
         print("""
 Usage of config_utils.py test :
--- a/connectors/PYRO/__init__.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/connectors/PYRO/__init__.py	Thu Feb 01 14:51:18 2018 +0100
@@ -76,7 +76,7 @@
 
         def _settimeout(self, timeout):
             self.timeout = timeout
-        from M2Crypto.SSL import Connection
+        from M2Crypto.SSL import Connection  # pylint: disable=import-error
         Connection.timeout = None
         Connection.gettimeout = _gettimeout
         Connection.settimeout = _settimeout
--- a/controls/DebugVariablePanel/DebugVariableGraphicViewer.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/controls/DebugVariablePanel/DebugVariableGraphicViewer.py	Thu Feb 01 14:51:18 2018 +0100
@@ -26,7 +26,7 @@
 from __future__ import absolute_import
 from types import TupleType
 from time import time as gettime
-from distutils.version import LooseVersion
+from cycler import cycler
 
 import numpy
 import wx
@@ -42,10 +42,6 @@
 from controls.DebugVariablePanel.GraphButton import GraphButton
 
 
-if LooseVersion(matplotlib.__version__) >= LooseVersion("1.5.0"):
-    from cycler import cycler
-
-
 # Graph variable display type
 GRAPH_PARALLEL, GRAPH_ORTHOGONAL = range(2)
 
@@ -983,10 +979,7 @@
         return AddText
 
     def SetAxesColor(self, color):
-        if LooseVersion(matplotlib.__version__) >= LooseVersion("1.5.0"):
-            self.Axes.set_prop_cycle(cycler('color', color))
-        else:
-            self.Axes.set_color_cycle(color)
+        self.Axes.set_prop_cycle(cycler('color', color))
 
     def ResetGraphics(self):
         """
--- a/i18n/mki18n.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/i18n/mki18n.py	Thu Feb 01 14:51:18 2018 +0100
@@ -439,7 +439,8 @@
 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 #
 if __name__ == "__main__":
-    import getopt     # command line parsing
+    # command line parsing
+    import getopt    # pylint: disable=wrong-import-order,wrong-import-position
     argc = len(sys.argv)
     if argc == 1:
         printUsage('Missing argument: specify at least one of -m or -p (or both).')
--- a/modbus/__init__.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/modbus/__init__.py	Thu Feb 01 14:51:18 2018 +0100
@@ -21,6 +21,3 @@
 #
 # This code is made available on the understanding that it will not be
 # used in safety-critical situations without a full and competent review.
-
-
-from modbus import *
--- a/modbus/mb_utils.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/modbus/mb_utils.py	Thu Feb 01 14:51:18 2018 +0100
@@ -70,8 +70,7 @@
     node_dict = {"locnodestr": location,
                  "host": host,
                  "port": port,
-                 "slaveid": slaveid,
-                 }
+                 "slaveid": slaveid}
     return node_init_template % node_dict
 
 
@@ -128,8 +127,7 @@
                  "baud": baud,
                  "parity": modbus_serial_parity_dict[parity],
                  "stopbits": stopbits,
-                 "slaveid": slaveid
-                 }
+                 "slaveid": slaveid}
     return node_init_template % node_dict
 
 
@@ -149,8 +147,7 @@
                  "baud": baud,
                  "parity": modbus_serial_parity_dict[parity],
                  "stopbits": stopbits,
-                 "coms_period": coms_period
-                 }
+                 "coms_period": coms_period}
     return node_init_template % node_dict
 
 
@@ -168,8 +165,7 @@
     node_dict = {"locnodestr": location,
                  "host": host,
                  "port": port,
-                 "coms_period": coms_period
-                 }
+                 "coms_period": coms_period}
     return node_init_template % node_dict
 
 
--- a/modbus/modbus.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/modbus/modbus.py	Thu Feb 01 14:51:18 2018 +0100
@@ -23,13 +23,12 @@
 # used in safety-critical situations without a full and competent review.
 
 
+from __future__ import absolute_import
 import os
-import sys
-from mb_utils import *
-
-import wx
+from modbus.mb_utils import *
+
 from ConfigTreeNode import ConfigTreeNode
-from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
+from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_MEMORY
 
 base_folder = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
 base_folder = os.path.join(base_folder, "..")
@@ -45,7 +44,7 @@
 #
 
 
-class _RequestPlug:
+class _RequestPlug(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="ModbusRequest">
@@ -110,7 +109,7 @@
         # 1 or 16
         datasize = modbus_function_dict[function][4]
         # 'Q' for coils and holding registers, 'I' for input discretes and input registers
-        datazone = modbus_function_dict[function][5]
+        # datazone = modbus_function_dict[function][5]
         # 'X' for bits, 'W' for words
         datatacc = modbus_function_dict[function][6]
         # 'Coil', 'Holding Register', 'Input Discrete' or 'Input Register'
@@ -166,7 +165,7 @@
 }
 
 
-class _MemoryAreaPlug:
+class _MemoryAreaPlug(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="MemoryArea">
@@ -215,7 +214,7 @@
         # 1 or 16
         datasize = modbus_memtype_dict[function][4]
         # 'Q' for coils and holding registers, 'I' for input discretes and input registers
-        datazone = modbus_memtype_dict[function][5]
+        # datazone = modbus_memtype_dict[function][5]
         # 'X' for bits, 'W' for words
         datatacc = modbus_memtype_dict[function][6]
         # 'Coil', 'Holding Register', 'Input Discrete' or 'Input Register'
@@ -260,7 +259,7 @@
 #
 #
 
-class _ModbusTCPclientPlug:
+class _ModbusTCPclientPlug(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="ModbusTCPclient">
@@ -314,7 +313,7 @@
 #
 #
 
-class _ModbusTCPserverPlug:
+class _ModbusTCPserverPlug(object):
     # NOTE: the Port number is a 'string' and not an 'integer'!
     # This is because the underlying modbus library accepts strings
     # (e.g.: well known port names!)
@@ -376,7 +375,7 @@
 #
 #
 
-class _ModbusRTUclientPlug:
+class _ModbusRTUclientPlug(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="ModbusRTUclient">
@@ -446,7 +445,7 @@
 #
 
 
-class _ModbusRTUslavePlug:
+class _ModbusRTUslavePlug(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="ModbusRTUslave">
@@ -516,7 +515,7 @@
 #
 #
 #
-class RootClass:
+class RootClass(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:element name="ModbusRoot">
@@ -533,8 +532,10 @@
       </xsd:element>
     </xsd:schema>
     """
-    CTNChildrenTypes = [("ModbusTCPclient", _ModbusTCPclientPlug, "Modbus TCP Client"), ("ModbusTCPserver", _ModbusTCPserverPlug, "Modbus TCP Server"), ("ModbusRTUclient", _ModbusRTUclientPlug, "Modbus RTU Client"), ("ModbusRTUslave", _ModbusRTUslavePlug,  "Modbus RTU Slave")
-                        ]
+    CTNChildrenTypes = [("ModbusTCPclient", _ModbusTCPclientPlug, "Modbus TCP Client"),
+                        ("ModbusTCPserver", _ModbusTCPserverPlug, "Modbus TCP Server"),
+                        ("ModbusRTUclient", _ModbusRTUclientPlug, "Modbus RTU Client"),
+                        ("ModbusRTUslave", _ModbusRTUslavePlug,  "Modbus RTU Slave")]
 
     # Return the number of (modbus library) nodes this specific instance of the modbus plugin will need
     #   return type: (tcp nodes, rtu nodes, ascii nodes)
@@ -567,8 +568,7 @@
         # print type(self.CTNType)
         # print "#############"
 
-        loc_dict = {"locstr": "_".join(map(str, self.GetCurrentLocation())),
-                    }
+        loc_dict = {"locstr": "_".join(map(str, self.GetCurrentLocation()))}
 
         # Determine the number of (modbus library) nodes ALL instances of the modbus plugin will need
         #   total_node_count: (tcp nodes, rtu nodes, ascii nodes)
@@ -663,10 +663,10 @@
                     for iecvar in subchild.GetLocations():
                         # print repr(iecvar)
                         absloute_address = iecvar["LOC"][3]
-                        start_address = int(GetCTVal(child, 2))
+                        start_address = int(GetCTVal(subchild, 2))
                         relative_addr = absloute_address - start_address
                         # test if relative address in request specified range
-                        if relative_addr in xrange(int(GetCTVal(child, 1))):
+                        if relative_addr in xrange(int(GetCTVal(subchild, 1))):
                             if str(iecvar["NAME"]) not in loc_vars_list:
                                 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % (
                                     server_id, memarea, absloute_address))
@@ -693,10 +693,10 @@
                     for iecvar in subchild.GetLocations():
                         # print repr(iecvar)
                         absloute_address = iecvar["LOC"][3]
-                        start_address = int(GetCTVal(child, 2))
+                        start_address = int(GetCTVal(subchild, 2))
                         relative_addr = absloute_address - start_address
                         # test if relative address in request specified range
-                        if relative_addr in xrange(int(GetCTVal(child, 1))):
+                        if relative_addr in xrange(int(GetCTVal(subchild, 1))):
                             if str(iecvar["NAME"]) not in loc_vars_list:
                                 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % (
                                     server_id, memarea, absloute_address))
@@ -717,9 +717,9 @@
                     client_request_list.append(new_req)
                     for iecvar in subchild.GetLocations():
                         # absloute address - start address
-                        relative_addr = iecvar["LOC"][3] - int(GetCTVal(child, 3))
+                        relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3))
                         # test if relative address in request specified range
-                        if relative_addr in xrange(int(GetCTVal(child, 2))):
+                        if relative_addr in xrange(int(GetCTVal(subchild, 2))):
                             if str(iecvar["NAME"]) not in loc_vars_list:
                                 loc_vars.append(
                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
@@ -742,9 +742,9 @@
                     client_request_list.append(new_req)
                     for iecvar in subchild.GetLocations():
                         # absloute address - start address
-                        relative_addr = iecvar["LOC"][3] - int(GetCTVal(child, 3))
+                        relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3))
                         # test if relative address in request specified range
-                        if relative_addr in xrange(int(GetCTVal(child, 2))):
+                        if relative_addr in xrange(int(GetCTVal(subchild, 2))):
                             if str(iecvar["NAME"]) not in loc_vars_list:
                                 loc_vars.append(
                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
--- a/runtime/NevowServer.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/runtime/NevowServer.py	Thu Feb 01 14:51:18 2018 +0100
@@ -26,10 +26,10 @@
 from __future__ import absolute_import
 from __future__ import print_function
 import os
-import util.paths as paths
 from nevow import appserver, inevow, tags, loaders, athena
 from nevow.page import renderer
 from twisted.internet import reactor
+import util.paths as paths
 
 xhtml_header = '''<?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
--- a/runtime/PLCObject.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/runtime/PLCObject.py	Thu Feb 01 14:51:18 2018 +0100
@@ -25,22 +25,22 @@
 from __future__ import absolute_import
 from threading import Timer, Thread, Lock, Semaphore, Event
 import ctypes
+import _ctypes
 import os
 import sys
 import traceback
 from time import time
-
 import Pyro.core as pyro
 
 from runtime.typemapping import TypeTranslator
 from runtime.loglevels import LogLevelsDefault, LogLevelsCount
 
-
 if os.name in ("nt", "ce"):
-    from _ctypes import LoadLibrary as dlopen
-    from _ctypes import FreeLibrary as dlclose
+    dlopen = _ctypes.LoadLibrary
+    dlclose = _ctypes.FreeLibrary
 elif os.name == "posix":
-    from _ctypes import dlopen, dlclose
+    dlopen = _ctypes.dlopen
+    dlclose = _ctypes.dlclose
 
 
 def get_last_traceback(tb):
--- a/svgui/svgui_server.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/svgui/svgui_server.py	Thu Feb 01 14:51:18 2018 +0100
@@ -27,7 +27,7 @@
 import os
 
 from nevow import tags, loaders
-import simplejson as json
+import simplejson as json  # pylint: disable=import-error
 import runtime.NevowServer as NS
 
 svgfile = '%(svgfile)s'
--- a/util/ProcessLogger.py	Wed Jan 31 15:25:30 2018 +0100
+++ b/util/ProcessLogger.py	Thu Feb 01 14:51:18 2018 +0100
@@ -29,9 +29,7 @@
 import subprocess
 import ctypes
 from threading import Timer, Lock, Thread, Semaphore
-import wx
-if os.name == 'posix':
-    from signal import SIGTERM, SIGKILL
+import signal
 
 
 class outputThread(Thread):
@@ -126,11 +124,11 @@
             "stderr": subprocess.PIPE
         }
 
-        if no_gui and wx.Platform == '__WXMSW__':
+        if no_gui and os.name in ("nt", "ce"):
             self.startupinfo = subprocess.STARTUPINFO()
             self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
             popenargs["startupinfo"] = self.startupinfo
-        elif wx.Platform == '__WXGTK__':
+        elif os.name == 'posix':
             popenargs["shell"] = False
 
         if timeout:
@@ -200,16 +198,16 @@
 
         self.outt.killed = True
         self.errt.killed = True
-        if wx.Platform == '__WXMSW__':
+        if os.name in ("nt", "ce"):
             PROCESS_TERMINATE = 1
             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
             ctypes.windll.kernel32.TerminateProcess(handle, -1)
             ctypes.windll.kernel32.CloseHandle(handle)
         else:
             if gently:
-                sig = SIGTERM
+                sig = signal.SIGTERM
             else:
-                sig = SIGKILL
+                sig = signal.SIGKILL
             try:
                 os.kill(self.Proc.pid, sig)
             except Exception: