beremiz

Fix various pylint and pep8 errors

2019-03-13, Andrey Skvortsov
eb4a4cc41914
Fix various pylint and pep8 errors

Check basic code-style problems for PEP-8
pep8 version: 2.4.0
./connectors/PYRO/__init__.py:57:43: E261 at least two spaces before inline comment
./connectors/SchemeEditor.py:29:21: E128 continuation line under-indented for visual indent
./controls/IDBrowser.py:101:23: E127 continuation line over-indented for visual indent
./controls/IDBrowser.py:102:23: E127 continuation line over-indented for visual indent

Check for problems using pylint ...
No config file found, using default configuration
pylint 1.9.4,
astroid 1.6.5
Python 2.7.16rc1 (default, Feb 18 2019, 11:05:09)
[GCC 8.2.0]
Use multiple threads for pylint
Using config file /home/developer/WorkData/PLC/beremiz/beremiz/.pylint
************* Module connectors.PYRO_dialog
connectors/PYRO_dialog.py:9: [W0611(unused-import), ] Unused import wx
************* Module connectors
connectors/__init__.py:32: [W1652(deprecated-types-field), ] Accessing a deprecated fields on the types module
connectors/__init__.py:32: [C0411(wrong-import-order), ] standard import "from types import ClassType" should be placed before "from connectors.ConnectorBase import ConnectorBase"
************* Module connectors.PYRO.PSK_Adapter
connectors/PYRO/PSK_Adapter.py:7: [C0411(wrong-import-order), ] standard import "import ssl" should be placed before "import sslpsk"
************* Module connectors.SchemeEditor
connectors/SchemeEditor.py:29: [C0330(bad-continuation), ] Wrong continued indentation (add 1 space).
wx.ALIGN_CENTER_VERTICAL),
^|
connectors/SchemeEditor.py:42: [W0631(undefined-loop-variable), SchemeEditor.__init__] Using possibly undefined loop variable 'tag'
************* Module runtime.WampClient
runtime/WampClient.py:138: [W1612(unicode-builtin), WampSession.onJoin] unicode built-in referenced
runtime/WampClient.py:154: [W1612(unicode-builtin), WampSession.publishWithOwnID] unicode built-in referenced
runtime/WampClient.py:346: [W1612(unicode-builtin), PublishEvent] unicode built-in referenced
runtime/WampClient.py:351: [W1612(unicode-builtin), PublishEventWithOwnID] unicode built-in referenced
runtime/WampClient.py:31: [W0611(unused-import), ] Unused str imported from builtins as text
************* Module runtime.PLCObject
runtime/PLCObject.py:35: [W1648(bad-python3-import), ] Module moved in Python 3
runtime/PLCObject.py:35: [C0411(wrong-import-order), ] standard import "import md5" should be placed before "from six.moves import xrange"
runtime/PLCObject.py:36: [C0411(wrong-import-order), ] standard import "from tempfile import mkstemp" should be placed before "from six.moves import xrange"
runtime/PLCObject.py:37: [C0411(wrong-import-order), ] standard import "import shutil" should be placed before "from six.moves import xrange"
runtime/PLCObject.py:38: [C0411(wrong-import-order), ] standard import "from functools import wraps, partial" should be placed before "from six.moves import xrange"
************* Module runtime.Worker
runtime/Worker.py:12: [W1648(bad-python3-import), ] Module moved in Python 3
************* Module runtime.spawn_subprocess
runtime/spawn_subprocess.py:125: [C0325(superfluous-parens), ] Unnecessary parens after 'print' keyword
runtime/spawn_subprocess.py:130: [C0325(superfluous-parens), ] Unnecessary parens after 'print' keyword
runtime/spawn_subprocess.py:125: [E1601(print-statement), ] print statement used
runtime/spawn_subprocess.py:130: [E1601(print-statement), ] print statement used
************* Module controls.IDBrowser
controls/IDBrowser.py:101: [C0330(bad-continuation), ] Wrong continued indentation (remove 5 spaces).
if self.isManager
| ^
controls/IDBrowser.py:102: [C0330(bad-continuation), ] Wrong continued indentation (remove 5 spaces).
else dv.DATAVIEW_CELL_INERT),
| ^
************* Module Beremiz_service
Beremiz_service.py:34: [W0611(unused-import), ] Unused import __builtin__
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Beremiz, a Integrated Development Environment for
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
#
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
#
# See COPYING file for copyrights details.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from __future__ import absolute_import
import wx
import wx.grid
class CustomGrid(wx.grid.Grid):
def __init__(self, *args, **kwargs):
wx.grid.Grid.__init__(self, *args, **kwargs)
self.Editable = True
self.AddButton = None
self.DeleteButton = None
self.UpButton = None
self.DownButton = None
self.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Sans'))
self.SetLabelFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Sans'))
self.SetSelectionBackground(wx.WHITE)
self.SetSelectionForeground(wx.BLACK)
self.DisableDragRowSize()
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell)
self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def SetFocus(self):
if self:
wx.grid.Grid.SetFocus(self)
def SetDefaultValue(self, default_value):
self.DefaultValue = default_value
def SetEditable(self, editable=True):
self.Editable = editable
self.RefreshButtons()
def SetButtons(self, buttons):
for name in ["Add", "Delete", "Up", "Down"]:
button = buttons.get(name, None)
setattr(self, "%sButton" % name, button)
if button is not None:
button.Bind(wx.EVT_BUTTON, getattr(self, "On%sButton" % name))
def RefreshButtons(self):
if self:
rows = self.Table.GetNumberRows()
row = self.GetGridCursorRow()
if self.AddButton is not None:
self.AddButton.Enable(self.Editable)
if self.DeleteButton is not None:
self.DeleteButton.Enable(self.Editable and rows > 0)
if self.UpButton is not None:
self.UpButton.Enable(self.Editable and row > 0)
if self.DownButton is not None:
self.DownButton.Enable(self.Editable and 0 <= row < rows - 1)
def CloseEditControl(self):
row, col = self.GetGridCursorRow(), self.GetGridCursorCol()
if row != -1 and col != -1:
self.SetGridCursor(row, col)
def AddRow(self):
self.CloseEditControl()
new_row = self.GetGridCursorRow() + 1
col = max(self.GetGridCursorCol(), 0)
if getattr(self, "_AddRow", None) is not None:
new_row = self._AddRow(new_row)
else:
self.Table.InsertRow(new_row, self.DefaultValue.copy())
self.Table.ResetView(self)
if new_row is not None:
self.SetSelectedCell(new_row, col)
def DeleteRow(self):
self.CloseEditControl()
row = self.GetGridCursorRow()
if row >= 0:
col = self.GetGridCursorCol()
if getattr(self, "_DeleteRow", None) is not None:
self._DeleteRow(row)
else:
self.Table.RemoveRow(row)
self.Table.ResetView(self)
if self.Table.GetNumberRows() > 0:
self.SetSelectedCell(min(row, self.Table.GetNumberRows() - 1), col)
def MoveRow(self, row, move):
self.CloseEditControl()
col = self.GetGridCursorCol()
if getattr(self, "_MoveRow", None) is not None:
new_row = self._MoveRow(row, move)
else:
new_row = self.Table.MoveRow(row, move)
if new_row != row:
self.Table.ResetView(self)
if new_row != row:
self.SetSelectedCell(new_row, col)
def SetSelectedCell(self, row, col):
self.SetGridCursor(row, col)
self.MakeCellVisible(row, col)
self.RefreshButtons()
def OnAddButton(self, event):
self.AddRow()
self.SetFocus()
event.Skip()
def OnDeleteButton(self, event):
self.DeleteRow()
self.SetFocus()
event.Skip()
def OnUpButton(self, event):
self.MoveRow(self.GetGridCursorRow(), -1)
self.SetFocus()
event.Skip()
def OnDownButton(self, event):
self.MoveRow(self.GetGridCursorRow(), 1)
self.SetFocus()
event.Skip()
def OnSelectCell(self, event):
wx.CallAfter(self.RefreshButtons)
event.Skip()
def OnEditorHidden(self, event):
wx.CallAfter(self.SetFocus)
event.Skip()
def OnKeyDown(self, event):
key_handled = False
keycode = event.GetKeyCode()
if keycode == wx.WXK_TAB:
row = self.GetGridCursorRow()
col = self.GetGridCursorCol()
if event.ShiftDown():
if row < 0 or col == 0:
self.Navigate(wx.NavigationKeyEvent.IsBackward)
key_handled = True
elif row < 0 or col == self.Table.GetNumberCols() - 1:
self.Navigate(wx.NavigationKeyEvent.IsForward)
key_handled = True
elif keycode in (wx.WXK_ADD, wx.WXK_NUMPAD_ADD) and self.Editable:
self.AddRow()
key_handled = True
elif keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE) and self.Editable:
self.DeleteRow()
key_handled = True
elif keycode == wx.WXK_UP and event.ShiftDown() and self.Editable:
self.MoveRow(self.GetGridCursorRow(), -1)
key_handled = True
elif keycode == wx.WXK_DOWN and event.ShiftDown() and self.Editable:
self.MoveRow(self.GetGridCursorRow(), 1)
key_handled = True
if not key_handled:
event.Skip()