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__
/**
* Win32 specific code
**/
#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
#include <windows.h>
#include <locale.h>
long AtomicCompareExchange(long* atomicvar, long compared, long exchange)
{
return InterlockedCompareExchange(atomicvar, exchange, compared);
}
CRITICAL_SECTION Atomic64CS;
long long AtomicCompareExchange64(long long* atomicvar, long long compared, long long exchange)
{
long long res;
EnterCriticalSection(&Atomic64CS);
res=*atomicvar;
if(*atomicvar == compared){
*atomicvar = exchange;
}
LeaveCriticalSection(&Atomic64CS);
return res;
}
struct _timeb timetmp;
void PLC_GetTime(IEC_TIME *CURRENT_TIME)
{
_ftime(&timetmp);
(*CURRENT_TIME).tv_sec = timetmp.time;
(*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000;
}
void PLC_timer_notify()
{
PLC_GetTime(&__CURRENT_TIME);
__run();
}
HANDLE PLC_timer = NULL;
void PLC_SetTimer(unsigned long long next, unsigned long long period)
{
LARGE_INTEGER liDueTime;
/* arg 2 of SetWaitableTimer take 100 ns interval*/
liDueTime.QuadPart = next / (-100);
if (!SetWaitableTimer(PLC_timer, &liDueTime, period<1000000?1:period/1000000, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
}
}
int PLC_shutdown;
int ForceSaveRetainReq(void) {
return PLC_shutdown;
}
/* Variable used to stop plcloop thread */
void PlcLoop()
{
PLC_shutdown = 0;
while(!PLC_shutdown) {
if (WaitForSingleObject(PLC_timer, INFINITE) != WAIT_OBJECT_0)
PLC_shutdown = 1;
PLC_timer_notify();
}
}
HANDLE PLC_thread;
HANDLE debug_sem;
HANDLE debug_wait_sem;
HANDLE python_sem;
HANDLE python_wait_sem;
#define maxval(a,b) ((a>b)?a:b)
int startPLC(int argc,char **argv)
{
unsigned long thread_id = 0;
BOOL tmp;
setlocale(LC_NUMERIC, "C");
debug_sem = CreateSemaphore(
NULL, // default security attributes
1, // initial count
1, // maximum count
NULL); // unnamed semaphore
if (debug_sem == NULL)
{
printf("startPLC CreateSemaphore debug_sem error: %d\n", GetLastError());
return 1;
}
debug_wait_sem = CreateSemaphore(
NULL, // default security attributes
0, // initial count
1, // maximum count
NULL); // unnamed semaphore
if (debug_wait_sem == NULL)
{
printf("startPLC CreateSemaphore debug_wait_sem error: %d\n", GetLastError());
return 1;
}
python_sem = CreateSemaphore(
NULL, // default security attributes
1, // initial count
1, // maximum count
NULL); // unnamed semaphore
if (python_sem == NULL)
{
printf("startPLC CreateSemaphore python_sem error: %d\n", GetLastError());
return 1;
}
python_wait_sem = CreateSemaphore(
NULL, // default security attributes
0, // initial count
1, // maximum count
NULL); // unnamed semaphore
if (python_wait_sem == NULL)
{
printf("startPLC CreateSemaphore python_wait_sem error: %d\n", GetLastError());
return 1;
}
/* Create a waitable timer */
timeBeginPeriod(1);
PLC_timer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
if(NULL == PLC_timer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}
if( __init(argc,argv) == 0 )
{
PLC_SetTimer(common_ticktime__,common_ticktime__);
PLC_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PlcLoop, NULL, 0, &thread_id);
}
else{
return 1;
}
return 0;
}
static unsigned long __debug_tick;
int TryEnterDebugSection(void)
{
//printf("TryEnterDebugSection\n");
if(WaitForSingleObject(debug_sem, 0) == WAIT_OBJECT_0){
/* Only enter if debug active */
if(__DEBUG){
return 1;
}
ReleaseSemaphore(debug_sem, 1, NULL);
}
return 0;
}
void LeaveDebugSection(void)
{
ReleaseSemaphore(debug_sem, 1, NULL);
//printf("LeaveDebugSection\n");
}
int stopPLC()
{
CloseHandle(PLC_timer);
WaitForSingleObject(PLC_thread, INFINITE);
__cleanup();
CloseHandle(debug_wait_sem);
CloseHandle(debug_sem);
CloseHandle(python_wait_sem);
CloseHandle(python_sem);
CloseHandle(PLC_thread);
}
/* from plc_debugger.c */
int WaitDebugData(unsigned long *tick)
{
DWORD res;
res = WaitForSingleObject(debug_wait_sem, INFINITE);
*tick = __debug_tick;
/* Wait signal from PLC thread */
return res != WAIT_OBJECT_0;
}
/* Called by PLC thread when debug_publish finished
* This is supposed to unlock debugger thread in WaitDebugData*/
void InitiateDebugTransfer()
{
/* remember tick */
__debug_tick = __tick;
/* signal debugger thread it can read data */
ReleaseSemaphore(debug_wait_sem, 1, NULL);
}
int suspendDebug(int disable)
{
/* Prevent PLC to enter debug code */
WaitForSingleObject(debug_sem, INFINITE);
__DEBUG = !disable;
if(disable)
ReleaseSemaphore(debug_sem, 1, NULL);
return 0;
}
void resumeDebug()
{
__DEBUG = 1;
/* Let PLC enter debug code */
ReleaseSemaphore(debug_sem, 1, NULL);
}
/* from plc_python.c */
int WaitPythonCommands(void)
{
/* Wait signal from PLC thread */
return WaitForSingleObject(python_wait_sem, INFINITE);
}
/* Called by PLC thread on each new python command*/
void UnBlockPythonCommands(void)
{
/* signal debugger thread it can read data */
ReleaseSemaphore(python_wait_sem, 1, NULL);
}
int TryLockPython(void)
{
return WaitForSingleObject(python_sem, 0) == WAIT_OBJECT_0;
}
void UnLockPython(void)
{
ReleaseSemaphore(python_sem, 1, NULL);
}
void LockPython(void)
{
WaitForSingleObject(python_sem, INFINITE);
}
static void __attribute__((constructor))
beremiz_dll_init(void)
{
InitializeCriticalSection(&Atomic64CS);
}
static void __attribute__((destructor))
beremiz_dll_destroy(void)
{
DeleteCriticalSection(&Atomic64CS);
}