clean-up: fix PEP8 E402 module level import not at top of file
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 21 Aug 2017 22:41:37 +0300
changeset 1783 3311eea28d56
parent 1782 5b6ad7a7fd9d
child 1784 64beb9e9c749
clean-up: fix PEP8 E402 module level import not at top of file
BeremizIDE.py
Beremiz_service.py
IDEFrame.py
PLCOpenEditor.py
canfestival/canfestival.py
connectors/PYRO/__init__.py
controls/DebugVariablePanel/DebugVariablePanel.py
controls/PouInstanceVariablesPanel.py
runtime/PLCObject.py
svgui/pyjs/build.py
svgui/pyjs/jsonrpc/django/jsonrpc.py
svgui/pyjs/lib/pyjslib.py
svgui/pyjs/pyjs.py
targets/typemapping.py
util/Zeroconf.py
--- a/BeremizIDE.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/BeremizIDE.py	Mon Aug 21 22:41:37 2017 +0300
@@ -32,16 +32,8 @@
 import time
 import version
 
-import util.paths as paths
 from types import ListType
 
-beremiz_dir = paths.AbsDir(__file__)
-
-
-def Bpath(*args):
-    return os.path.join(beremiz_dir, *args)
-
-
 import wx.lib.buttons
 import wx.lib.statbmp
 import wx.stc
@@ -53,7 +45,11 @@
 import time
 import traceback
 import commands
-
+import threading
+from threading import Lock, Timer, currentThread
+from time import time as gettime
+
+import util.paths as paths
 from docutil import OpenHtmlFrame
 from editors.EditorPanel import EditorPanel
 from editors.Viewer import Viewer
@@ -67,12 +63,47 @@
 from controls import EnhancedStatusBar as esb
 from dialogs.AboutDialog import ShowAboutDialog
 
-from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
+from PLCControler import \
+    LOCATION_CONFNODE, \
+    LOCATION_MODULE, \
+    LOCATION_GROUP, \
+    LOCATION_VAR_INPUT, \
+    LOCATION_VAR_OUTPUT, \
+    LOCATION_VAR_MEMORY, \
+    ITEM_PROJECT, \
+    ITEM_RESOURCE
+
 from ProjectController import ProjectController, GetAddMenuItems, MATIEC_ERROR_MODEL, ITEM_CONFNODE
 
+from IDEFrame import \
+    TITLE,\
+    EDITORTOOLBAR,\
+    FILEMENU,\
+    EDITMENU,\
+    DISPLAYMENU,\
+    PROJECTTREE,\
+    POUINSTANCEVARIABLESPANEL,\
+    LIBRARYTREE,\
+    SCALING,\
+    PAGETITLES,\
+    IDEFrame, \
+    AppendMenu,\
+    EncodeFileSystemPath, \
+    DecodeFileSystemPath
+
+from util.BitmapLibrary import GetBitmap
+
+
+beremiz_dir = paths.AbsDir(__file__)
+
+
+def Bpath(*args):
+    return os.path.join(beremiz_dir, *args)
+
 
 MAX_RECENT_PROJECTS = 9
 
+
 if wx.Platform == '__WXMSW__':
     faces = {
         'mono': 'Courier New',
@@ -84,10 +115,9 @@
         'size': 10,
     }
 
-from threading import Lock, Timer, currentThread
+
 MainThread = currentThread().ident
 REFRESH_PERIOD = 0.1
-from time import time as gettime
 
 
 class LogPseudoFile:
@@ -203,20 +233,6 @@
 
 ID_FILEMENURECENTPROJECTS = wx.NewId()
 
-from IDEFrame import TITLE,\
-                     EDITORTOOLBAR,\
-                     FILEMENU,\
-                     EDITMENU,\
-                     DISPLAYMENU,\
-                     PROJECTTREE,\
-                     POUINSTANCEVARIABLESPANEL,\
-                     LIBRARYTREE,\
-                     SCALING,\
-                     PAGETITLES,\
-                     IDEFrame, AppendMenu,\
-                     EncodeFileSystemPath, DecodeFileSystemPath
-from util.BitmapLibrary import GetBitmap
-
 
 class Beremiz(IDEFrame):
 
@@ -1095,8 +1111,6 @@
 # -------------------------------------------------------------------------------
 #                               Exception Handler
 # -------------------------------------------------------------------------------
-import threading
-import traceback
 
 Max_Traceback_List_Size = 20
 
--- a/Beremiz_service.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/Beremiz_service.py	Mon Aug 21 22:41:37 2017 +0300
@@ -26,7 +26,14 @@
 import os
 import sys
 import getopt
+import threading
 from threading import Thread
+import traceback
+import __builtin__
+import Pyro.core as pyro
+
+from runtime import PLCObject, PLCprint, ServicePublisher
+import util.paths as paths
 
 
 def usage():
@@ -101,7 +108,7 @@
         usage()
         sys.exit()
 
-import util.paths as paths
+
 beremiz_dir = paths.AbsDir(__file__)
 
 if len(argv) > 1:
@@ -114,7 +121,6 @@
     WorkingDir = os.getcwd()
     argv = [WorkingDir]
 
-import __builtin__
 if __name__ == '__main__':
     __builtin__.__dict__['_'] = lambda x: x
 
@@ -375,8 +381,6 @@
                     currenticon = self.MakeIcon(defaulticon)
                 self.SetIcon(currenticon, "Beremiz Service")
 
-from runtime import PLCObject, PLCprint, ServicePublisher
-import Pyro.core as pyro
 
 if not os.path.isdir(WorkingDir):
     os.mkdir(WorkingDir)
@@ -531,8 +535,6 @@
 
 
 # Exception hooks s
-import threading
-import traceback
 
 
 def LogException(*exp):
--- a/IDEFrame.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/IDEFrame.py	Mon Aug 21 22:41:37 2017 +0300
@@ -26,6 +26,7 @@
 import sys
 import cPickle
 from types import TupleType
+import base64
 
 import wx
 import wx.grid
@@ -194,8 +195,6 @@
 #                               Helper Functions
 # -------------------------------------------------------------------------------
 
-import base64
-
 
 def EncodeFileSystemPath(path, use_base64=True):
     path = path.encode(sys.getfilesystemencoding())
--- a/PLCOpenEditor.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/PLCOpenEditor.py	Mon Aug 21 22:41:37 2017 +0300
@@ -33,6 +33,26 @@
 import version
 import util.paths as paths
 
+from docutil import *
+from IDEFrame import IDEFrame, AppendMenu
+from IDEFrame import \
+    TITLE, \
+    EDITORTOOLBAR, \
+    FILEMENU, \
+    EDITMENU, \
+    DISPLAYMENU, \
+    PROJECTTREE, \
+    POUINSTANCEVARIABLESPANEL, \
+    LIBRARYTREE, \
+    PAGETITLES
+
+from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
+from editors.Viewer import Viewer
+from PLCControler import PLCControler
+from dialogs import ProjectDialog
+from dialogs.AboutDialog import ShowAboutDialog
+
+
 beremiz_dir = paths.AbsDir(__file__)
 
 __version__ = "$Revision: 1.130 $"
@@ -76,14 +96,6 @@
     from util.misc import InstallLocalRessources
     InstallLocalRessources(beremiz_dir)
 
-from docutil import *
-from IDEFrame import IDEFrame, AppendMenu
-from IDEFrame import TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, PAGETITLES
-from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath
-from editors.Viewer import Viewer
-from PLCControler import PLCControler
-from dialogs import ProjectDialog
-from dialogs.AboutDialog import ShowAboutDialog
 
 # -------------------------------------------------------------------------------
 #                            PLCOpenEditor Main Class
--- a/canfestival/canfestival.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/canfestival/canfestival.py	Mon Aug 21 22:41:37 2017 +0300
@@ -26,35 +26,46 @@
 import os
 import sys
 import shutil
+import wx
+from gnosis.xml.pickle import *
+from gnosis.xml.pickle.util import setParanoia
 
 import util.paths as paths
-
-base_folder = paths.AbsParentDir(__file__, 2)
-CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
-sys.path.append(os.path.join(CanFestivalPath, "objdictgen"))
-
-import wx
-
-from nodelist import NodeList
+from util.TranslationCatalogs import AddCatalog
+from ConfigTreeNode import ConfigTreeNode
+from PLCControler import \
+    LOCATION_CONFNODE, \
+    LOCATION_MODULE, \
+    LOCATION_GROUP, \
+    LOCATION_VAR_INPUT, \
+    LOCATION_VAR_OUTPUT, \
+    LOCATION_VAR_MEMORY
+
+try:
+    from nodelist import NodeList
+except ImportError:
+    base_folder = paths.AbsParentDir(__file__, 2)
+    CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
+    sys.path.append(os.path.join(CanFestivalPath, "objdictgen"))
+
+    from nodelist import NodeList
+
+
 from nodemanager import NodeManager
 import config_utils
 import gen_cfile
 import eds_utils
 import canfestival_config as local_canfestival_config
-from ConfigTreeNode import ConfigTreeNode
+
 from commondialogs import CreateNodeDialog
 from subindextable import IECTypeConversion, SizeConversion
-
-from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
 from SlaveEditor import SlaveEditor, MasterViewer
 from NetworkEditor import NetworkEditor
 
-from gnosis.xml.pickle import *
-from gnosis.xml.pickle.util import setParanoia
+
+AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale"))
 setParanoia(0)
 
-from util.TranslationCatalogs import AddCatalog
-AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale"))
 
 # --------------------------------------------------
 #              Location Tree Helper
--- a/connectors/PYRO/__init__.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/connectors/PYRO/__init__.py	Mon Aug 21 22:41:37 2017 +0300
@@ -30,8 +30,9 @@
 from time import sleep
 import copy
 import socket
+import os.path
+
 service_type = '_PYRO._tcp.local.'
-import os.path
 # this module attribute contains a list of DNS-SD (Zeroconf) service types
 # supported by this connector confnode.
 #
--- a/controls/DebugVariablePanel/DebugVariablePanel.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/controls/DebugVariablePanel/DebugVariablePanel.py	Mon Aug 21 22:41:37 2017 +0300
@@ -30,10 +30,11 @@
 import wx.lib.buttons
 
 import matplotlib
-matplotlib.use('WX')
+matplotlib.use('WX')   # noqa
 import matplotlib.pyplot
 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap
 
+
 from editors.DebugViewer import DebugViewer
 from util.BitmapLibrary import GetBitmap
 
@@ -41,6 +42,7 @@
 from DebugVariableTextViewer import DebugVariableTextViewer
 from DebugVariableGraphicViewer import *
 
+
 MILLISECOND = 1000000        # Number of nanosecond in a millisecond
 SECOND = 1000 * MILLISECOND  # Number of nanosecond in a second
 MINUTE = 60 * SECOND         # Number of nanosecond in a minute
--- a/controls/PouInstanceVariablesPanel.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/controls/PouInstanceVariablesPanel.py	Mon Aug 21 22:41:37 2017 +0300
@@ -28,6 +28,17 @@
 import wx.lib.agw.customtreectrl as CT
 import wx.lib.buttons
 
+from PLCControler import \
+    ITEMS_VARIABLE, \
+    ITEM_CONFIGURATION, \
+    ITEM_RESOURCE, \
+    ITEM_POU, \
+    ITEM_TRANSITION, \
+    ITEM_ACTION
+
+from util.BitmapLibrary import GetBitmap
+
+
 # Customize CustomTreeItem for adding icon on item right
 CT.GenericTreeItem._rightimages = []
 
@@ -116,9 +127,6 @@
 
 _ButtonCallbacks = namedtuple("ButtonCallbacks", ["leftdown", "dclick"])
 
-from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU, ITEM_TRANSITION, ITEM_ACTION
-from util.BitmapLibrary import GetBitmap
-
 
 class PouInstanceVariablesPanel(wx.Panel):
 
--- a/runtime/PLCObject.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/runtime/PLCObject.py	Mon Aug 21 22:41:37 2017 +0300
@@ -28,6 +28,7 @@
 import commands
 import types
 import sys
+import traceback
 from targets.typemapping import LogLevelsDefault, LogLevelsCount, TypeTranslator, UnpackDebugBuffer
 from time import time
 
@@ -38,8 +39,6 @@
 elif os.name == "posix":
     from _ctypes import dlopen, dlclose
 
-import traceback
-
 
 def get_last_traceback(tb):
     while tb.tb_next:
--- a/svgui/pyjs/build.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/svgui/pyjs/build.py	Mon Aug 21 22:41:37 2017 +0300
@@ -7,6 +7,7 @@
 from os.path import join, dirname, basename, abspath, split, isfile, isdir
 from optparse import OptionParser
 import pyjs
+import time
 from cStringIO import StringIO
 try:
     # Python 2.5 and above
@@ -542,9 +543,6 @@
     return d
 
 
-import time
-
-
 def add_subdeps(deps, mod_name):
     sd = subdeps(mod_name)
     if len(sd) == 1:
--- a/svgui/pyjs/jsonrpc/django/jsonrpc.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/svgui/pyjs/jsonrpc/django/jsonrpc.py	Mon Aug 21 22:41:37 2017 +0300
@@ -1,9 +1,15 @@
 # jsonrpc.py
 #   original code: http://trac.pyworks.org/pyjamas/wiki/DjangoWithPyJamas
 #   also from: http://www.pimentech.fr/technologies/outils
+from datetime import date
+import datetime
+import sys
+
 from django.utils import simplejson
 from django.http import HttpResponse
-import sys
+from django import forms
+from django.core.serializers import serialize
+
 
 from pyjs.jsonrpc import JSONRPCServiceBase
 # JSONRPCService and jsonremote are used in combination to drastically
@@ -64,8 +70,6 @@
 # part of the app:
 #  (r'^formsservice/$', 'djangoapp.views.processor'),
 
-from django import forms
-
 
 def builderrors(form):
     d = {}
@@ -208,11 +212,6 @@
 #  (r'^service1/$', 'djangoapp.views.jsonservice'),
 
 
-from django.core.serializers import serialize
-import datetime
-from datetime import date
-
-
 def dict_datetimeflatten(item):
     d = {}
     for k, v in item.items():
--- a/svgui/pyjs/lib/pyjslib.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/svgui/pyjs/lib/pyjslib.py	Mon Aug 21 22:41:37 2017 +0300
@@ -231,7 +231,9 @@
     loader.next()
 
 
-import sys
+# as comment on line 20 says
+# import sys should be below
+import sys  # noqa
 
 
 class BaseException:
--- a/svgui/pyjs/pyjs.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/svgui/pyjs/pyjs.py	Mon Aug 21 22:41:37 2017 +0300
@@ -20,6 +20,7 @@
 from compiler import ast
 import os
 import copy
+import cStringIO
 
 # the standard location for builtins (e.g. pyjslib) can be
 # over-ridden by changing this.  it defaults to sys.prefix
@@ -1520,9 +1521,6 @@
             raise TranslationError("unsupported type (in expr)", node)
 
 
-import cStringIO
-
-
 def translate(file_name, module_name, debug=False):
     f = file(file_name, "r")
     src = f.read()
--- a/targets/typemapping.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/targets/typemapping.py	Mon Aug 21 22:41:37 2017 +0300
@@ -23,14 +23,13 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 import ctypes
+from ctypes import *
+from datetime import timedelta as td
+
 ctypes.pythonapi.PyString_AsString.argtypes = (ctypes.c_void_p,)
 ctypes.pythonapi.PyString_AsString.restype = ctypes.POINTER(ctypes.c_char)
 
 
-from ctypes import *
-from datetime import timedelta as td
-
-
 class IEC_STRING(Structure):
     """
     Must be changed according to changes in iec_types.h
--- a/util/Zeroconf.py	Mon Aug 21 21:55:18 2017 +0300
+++ b/util/Zeroconf.py	Mon Aug 21 22:41:37 2017 +0300
@@ -1,82 +1,78 @@
-""" Multicast DNS Service Discovery for Python, v0.12
-    Copyright (C) 2003, Paul Scott-Murphy
-
-    This module provides a framework for the use of DNS Service Discovery
-    using IP multicast.  It has been tested against the JRendezvous
-    implementation from <a href="http://strangeberry.com">StrangeBerry</a>,
-    and against the mDNSResponder from Mac OS X 10.3.8.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-"""
-
-"""0.12 update - allow selection of binding interface
-         typo fix - Thanks A. M. Kuchlingi
-         removed all use of word 'Rendezvous' - this is an API change"""
-
-"""0.11 update - correction to comments for addListener method
-                 support for new record types seen from OS X
-                  - IPv6 address
-                  - hostinfo
-                 ignore unknown DNS record types
-                 fixes to name decoding
-                 works alongside other processes using port 5353 (e.g. on Mac OS X)
-                 tested against Mac OS X 10.3.2's mDNSResponder
-                 corrections to removal of list entries for service browser"""
-
-"""0.10 update - Jonathon Paisley contributed these corrections:
-                 always multicast replies, even when query is unicast
-                 correct a pointer encoding problem
-                 can now write records in any order
-                 traceback shown on failure
-                 better TXT record parsing
-                 server is now separate from name
-                 can cancel a service browser
-
-                 modified some unit tests to accommodate these changes"""
-
-"""0.09 update - remove all records on service unregistration
-                 fix DOS security problem with readName"""
-
-"""0.08 update - changed licensing to LGPL"""
-
-"""0.07 update - faster shutdown on engine
-                 pointer encoding of outgoing names
-                 ServiceBrowser now works
-                 new unit tests"""
-
-"""0.06 update - small improvements with unit tests
-                 added defined exception types
-                 new style objects
-                 fixed hostname/interface problem
-                 fixed socket timeout problem
-                 fixed addServiceListener() typo bug
-                 using select() for socket reads
-                 tested on Debian unstable with Python 2.2.2"""
-
-"""0.05 update - ensure case insensitivty on domain names
-                 support for unicast DNS queries"""
-
-"""0.04 update - added some unit tests
-                 added __ne__ adjuncts where required
-                 ensure names end in '.local.'
-                 timeout on receiving socket for clean shutdown"""
-
-__author__ = "Paul Scott-Murphy"
-__email__ = "paul at scott dash murphy dot com"
-__version__ = "0.12"
+#  Multicast DNS Service Discovery for Python, v0.12
+#     Copyright (C) 2003, Paul Scott-Murphy
+#
+#     This module provides a framework for the use of DNS Service Discovery
+#     using IP multicast.  It has been tested against the JRendezvous
+#     implementation from <a href="http://strangeberry.com">StrangeBerry</a>,
+#     and against the mDNSResponder from Mac OS X 10.3.8.
+
+#     This library is free software; you can redistribute it and/or
+#     modify it under the terms of the GNU Lesser General Public
+#     License as published by the Free Software Foundation; either
+#     version 2.1 of the License, or (at your option) any later version.
+
+#     This library 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
+#     Lesser General Public License for more details.
+
+#     You should have received a copy of the GNU Lesser General Public
+#     License along with this library; if not, write to the Free Software
+#     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#
+#
+# 0.12 update - allow selection of binding interface
+#          typo fix - Thanks A. M. Kuchlingi
+#          removed all use of word 'Rendezvous' - this is an API change
+#
+# 0.11 update - correction to comments for addListener method
+#                  support for new record types seen from OS X
+#                   - IPv6 address
+#                   - hostinfo
+#                  ignore unknown DNS record types
+#                  fixes to name decoding
+#                  works alongside other processes using port 5353 (e.g. on Mac OS X)
+#                  tested against Mac OS X 10.3.2's mDNSResponder
+#                  corrections to removal of list entries for service browser
+#
+# 0.10 update - Jonathon Paisley contributed these corrections:
+#                  always multicast replies, even when query is unicast
+#                  correct a pointer encoding problem
+#                  can now write records in any order
+#                  traceback shown on failure
+#                  better TXT record parsing
+#                  server is now separate from name
+#                  can cancel a service browser
+#
+#                  modified some unit tests to accommodate these changes
+#
+# 0.09 update - remove all records on service unregistration
+#                  fix DOS security problem with readName
+#
+# 0.08 update - changed licensing to LGPL
+#
+# 0.07 update - faster shutdown on engine
+#                  pointer encoding of outgoing names
+#                  ServiceBrowser now works
+#                  new unit tests
+#
+# 0.06 update - small improvements with unit tests
+#                  added defined exception types
+#                  new style objects
+#                  fixed hostname/interface problem
+#                  fixed socket timeout problem
+#                  fixed addServiceListener() typo bug
+#                  using select() for socket reads
+#                  tested on Debian unstable with Python 2.2.2
+#
+# 0.05 update - ensure case insensitivty on domain names
+#                  support for unicast DNS queries
+#
+# 0.04 update - added some unit tests
+#                  added __ne__ adjuncts where required
+#                  ensure names end in '.local.'
+#                  timeout on receiving socket for clean shutdown
 
 import string
 import time
@@ -86,6 +82,12 @@
 import select
 import traceback
 
+
+__author__ = "Paul Scott-Murphy"
+__email__ = "paul at scott dash murphy dot com"
+__version__ = "0.12"
+
+
 __all__ = ["Zeroconf", "ServiceInfo", "ServiceBrowser"]
 
 # hook for threads