plcopen/POUVariablesCollector.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 13 Mar 2019 11:47:03 +0300
changeset 2537 eb4a4cc41914
parent 1973 cc7a46953471
child 3750 f62625418bff
permissions -rw-r--r--
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__
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
1943
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
     3
# This file is part of Beremiz.
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     4
# See COPYING file for copyrights details.
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
     5
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1879
diff changeset
     6
from __future__ import absolute_import
1944
6162e34fb246 Moved some code from PLCController.py to other modules. Added necessary imports.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1943
diff changeset
     7
from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args
6162e34fb246 Moved some code from PLCController.py to other modules. Added necessary imports.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1943
diff changeset
     8
from plcopen.types_enums import CLASS_TYPES, POU_TYPES, VAR_CLASS_INFOS
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
     9
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    10
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    11
def class_extraction(value):
1944
6162e34fb246 Moved some code from PLCController.py to other modules. Added necessary imports.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1943
diff changeset
    12
    class_type = CLASS_TYPES.get(value)
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    13
    if class_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    14
        return class_type
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    15
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    16
    pou_type = POU_TYPES.get(value)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    17
    if pou_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    18
        return pou_type
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    19
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    20
    var_type = VAR_CLASS_INFOS.get(value)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    21
    if var_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    22
        return var_type[1]
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    23
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    24
    return None
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    25
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    26
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    27
class _VariablesTreeItemInfos(object):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    28
    __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"]
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
    29
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    30
    def __init__(self, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    31
        for attr, value in zip(self.__slots__, args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    32
            setattr(self, attr, value if value is not None else "")
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
    33
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    34
    def copy(self):
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1852
diff changeset
    35
        return _VariablesTreeItemInfos(*[getattr(self, attr) for attr in self.__slots__])
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    36
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    37
1831
56b48961cc68 fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1785
diff changeset
    38
class VariablesTreeInfosFactory(object):
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    39
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    40
    def __init__(self):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    41
        self.Root = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    42
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    43
    def GetRoot(self):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    44
        return self.Root
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    45
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    46
    def SetRoot(self, context, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    47
        self.Root = _VariablesTreeItemInfos(
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    48
            *([''] + _translate_args(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    49
                [class_extraction, _StringValue] + [_BoolValue] * 2,
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    50
                args) + [[]]))
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    51
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    52
    def AddVariable(self, context, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    53
        if self.Root is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    54
            self.Root.variables.append(_VariablesTreeItemInfos(
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
    55
                *(_translate_args(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    56
                    [_StringValue, class_extraction, _StringValue] +
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
    57
                    [_BoolValue] * 2, args) + [[]])))
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
    58
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
    59
1943
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    60
class POUVariablesCollector(XSLTModelQuery):
1321
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
    61
    def __init__(self, controller):
1943
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    62
        XSLTModelQuery.__init__(self,
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    63
                                controller,
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    64
                                "pou_variables.xslt",
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    65
                                [(name, self.FactoryCaller(name))
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    66
                                 for name in ["SetRoot", "AddVariable"]])
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
    67
1945
90bf6bd94b94 Fixed earlier XSLT optimizations. Some/most results were missing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1944
diff changeset
    68
    def FactoryCaller(self, funcname):
90bf6bd94b94 Fixed earlier XSLT optimizations. Some/most results were missing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1944
diff changeset
    69
        def CallFactory(*args):
90bf6bd94b94 Fixed earlier XSLT optimizations. Some/most results were missing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1944
diff changeset
    70
            return getattr(self.factory, funcname)(*args)
90bf6bd94b94 Fixed earlier XSLT optimizations. Some/most results were missing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1944
diff changeset
    71
        return CallFactory
90bf6bd94b94 Fixed earlier XSLT optimizations. Some/most results were missing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1944
diff changeset
    72
1943
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    73
    def Collect(self, root, debug):
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    74
        self.factory = VariablesTreeInfosFactory()
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    75
        self._process_xslt(root, debug)
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    76
        res = self.factory.GetRoot()
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    77
        self.factory = None
9dc0e38552b2 GetPouVariables optimized with XSLTModelQuery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 1942
diff changeset
    78
        return res