connectors/PYRO/__init__.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 11 Mar 2019 09:18:58 +0100
changeset 2493 0ad5e616d37f
parent 2492 7dd551ac2fa0
child 2536 2747d6e72eb8
permissions -rw-r--r--
better pylint complain workaround
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     1
#!/usr/bin/env python
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     2
# -*- coding: utf-8 -*-
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     3
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     6
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     8
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
     9
# See COPYING file for copyrights details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    10
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    11
# This program is free software; you can redistribute it and/or
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    12
# modify it under the terms of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    13
# as published by the Free Software Foundation; either version 2
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    14
# of the License, or (at your option) any later version.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    15
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    16
# This program is distributed in the hope that it will be useful,
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    19
# GNU General Public License for more details.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    20
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    21
# You should have received a copy of the GNU General Public License
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    22
# along with this program; if not, write to the Free Software
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    24
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1783
diff changeset
    25
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1847
diff changeset
    26
from __future__ import absolute_import
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1783
diff changeset
    27
from __future__ import print_function
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    28
import traceback
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    29
from time import sleep
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    30
import copy
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    31
import socket
1783
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1750
diff changeset
    32
import os.path
3311eea28d56 clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1750
diff changeset
    33
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    34
import Pyro
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    35
import Pyro.core
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    36
import Pyro.util
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    37
from Pyro.errors import PyroError
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    38
2339
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2338
diff changeset
    39
import PSKManagement as PSK
2416
1ca207782dde Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2010
diff changeset
    40
from runtime import PlcStatus
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    41
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    42
# this module attribute contains a list of DNS-SD (Zeroconf) service types
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    43
# supported by this connector confnode.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    44
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    45
# for connectors that do not support DNS-SD, this attribute can be omitted
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    46
# or set to an empty list.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    47
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
    48
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    49
def PYRO_connector_factory(uri, confnodesroot):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    50
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    51
    This returns the connector to Pyro style PLCobject
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    52
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    53
    confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    54
2338
2c3222433244 Renaming servicetype into scheme.
Edouard Tisserant
parents: 2334
diff changeset
    55
    scheme, location = uri.split("://")
2c3222433244 Renaming servicetype into scheme.
Edouard Tisserant
parents: 2334
diff changeset
    56
    if scheme == "PYROS":
2493
0ad5e616d37f better pylint complain workaround
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2492
diff changeset
    57
        import connectors.PYRO.PSK_Adapter # pylint: disable=wrong-import-order,unused-import,wrong-import-position
2314
e927c101ce6d PYRO/TLSPSK : must use PYROLOC* protocol scheme in pyro URI, otherwise object ID is missing. Had to use more persuasive pyro3 monkey patching to have PYROLOCPSK resolved properly
Edouard Tisserant
parents: 2313
diff changeset
    58
        schemename = "PYROLOCPSK"
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
    59
        url, ID = location.split('#')  # TODO fix exception when # not found
2312
84b3cc18893b Replaced PYROSSL with PYROPSK.
Edouard Tisserant
parents: 2010
diff changeset
    60
        # load PSK from project
84b3cc18893b Replaced PYROSSL with PYROPSK.
Edouard Tisserant
parents: 2010
diff changeset
    61
        secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret')
84b3cc18893b Replaced PYROSSL with PYROPSK.
Edouard Tisserant
parents: 2010
diff changeset
    62
        if not os.path.exists(secpath):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    63
            confnodesroot.logger.write_error(
2312
84b3cc18893b Replaced PYROSSL with PYROPSK.
Edouard Tisserant
parents: 2010
diff changeset
    64
                'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    65
            return None
2324
1cf3768ebf85 Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents: 2314
diff changeset
    66
        secret = open(secpath).read().partition(':')[2].rstrip('\n\r')
1cf3768ebf85 Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents: 2314
diff changeset
    67
        Pyro.config.PYROPSK = (secret, ID)
2313
2eaf235270f8 PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents: 2312
diff changeset
    68
        # strip ID from URL, so that pyro can understand it.
2eaf235270f8 PYRO/TLSPSK : fixed typos, used appropriate ciphers (https://github.com/drbild/sslpsk/issues/3), use PYROPSK instead of unresolvable PYROLOCPSK.
Edouard Tisserant
parents: 2312
diff changeset
    69
        location = url
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    70
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    71
        schemename = "PYROLOC"
2312
84b3cc18893b Replaced PYROSSL with PYROPSK.
Edouard Tisserant
parents: 2010
diff changeset
    72
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    73
    # Try to get the proxy object
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    74
    try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    75
        RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
    76
    except Exception, e:
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
    77
        confnodesroot.logger.write_error(
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
    78
            _("Connection to {loc} failed with exception {ex}\n").format(
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
    79
                loc=location, exo=str(e)))
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    80
        return None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    81
2468
046303391dea PYRO(S): Added timeout on client side to allow unfreezing IDE after some time when communication with target dropped
Edouard Tisserant
parents: 2463
diff changeset
    82
    RemotePLCObjectProxy.adapter.setTimeout(60)
046303391dea PYRO(S): Added timeout on client side to allow unfreezing IDE after some time when communication with target dropped
Edouard Tisserant
parents: 2463
diff changeset
    83
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    84
    def PyroCatcher(func, default=None):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    85
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    86
        A function that catch a Pyro exceptions, write error to logger
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    87
        and return default value when it happen
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    88
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    89
        def catcher_func(*args, **kwargs):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    90
            try:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    91
                return func(*args, **kwargs)
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2416
diff changeset
    92
            except Pyro.errors.ConnectionClosedError as e:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    93
                confnodesroot.logger.write_error(_("Connection lost!\n"))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    94
                confnodesroot._SetConnector(None)
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2416
diff changeset
    95
            except Pyro.errors.ProtocolError as e:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    96
                confnodesroot.logger.write_error(_("Pyro exception: %s\n") % e)
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2416
diff changeset
    97
            except Exception as e:
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    98
                # confnodesroot.logger.write_error(traceback.format_exc())
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    99
                errmess = ''.join(Pyro.util.getPyroTraceback(e))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   100
                confnodesroot.logger.write_error(errmess + "\n")
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1783
diff changeset
   101
                print(errmess)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   102
                confnodesroot._SetConnector(None)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   103
            return default
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   104
        return catcher_func
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   105
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   106
    # Check connection is effective.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   107
    # lambda is for getattr of GetPLCstatus to happen inside catcher
2324
1cf3768ebf85 Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents: 2314
diff changeset
   108
    IDPSK = PyroCatcher(RemotePLCObjectProxy.GetPLCID)()
1cf3768ebf85 Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents: 2314
diff changeset
   109
    if IDPSK is None:
2430
65ff9a309ff3 Fixed regression in connecting to LOCAL:// targets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2429
diff changeset
   110
        confnodesroot.logger.write_warning(_("PLC did not provide identity and security infomation.\n"))
65ff9a309ff3 Fixed regression in connecting to LOCAL:// targets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2429
diff changeset
   111
    else:
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2478
diff changeset
   112
        ID, secret = IDPSK
2430
65ff9a309ff3 Fixed regression in connecting to LOCAL:// targets
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2429
diff changeset
   113
        PSK.UpdateID(confnodesroot.ProjectPath, ID, secret, uri)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   114
1995
691d119ba20f Removed DebugThread. Take advantage of the fact that buffering is done in runtime. No need to poll for traces more than ten per second, then use simple wxTimer for that. Also removed Debug Lock since now everything happens in wx' mainloop.
Edouard Tisserant
parents: 1982
diff changeset
   115
    _special_return_funcs = {
691d119ba20f Removed DebugThread. Take advantage of the fact that buffering is done in runtime. No need to poll for traces more than ten per second, then use simple wxTimer for that. Also removed Debug Lock since now everything happens in wx' mainloop.
Edouard Tisserant
parents: 1982
diff changeset
   116
        "StartPLC": False,
2429
15f18dc8b56a Merge, with surprizingly little conflicts
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2339 2418
diff changeset
   117
        "GetTraceVariables": (PlcStatus.Broken, None),
2416
1ca207782dde Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2010
diff changeset
   118
        "GetPLCstatus": (PlcStatus.Broken, None),
1995
691d119ba20f Removed DebugThread. Take advantage of the fact that buffering is done in runtime. No need to poll for traces more than ten per second, then use simple wxTimer for that. Also removed Debug Lock since now everything happens in wx' mainloop.
Edouard Tisserant
parents: 1982
diff changeset
   119
        "RemoteExec": (-1, "RemoteExec script failed!")
691d119ba20f Removed DebugThread. Take advantage of the fact that buffering is done in runtime. No need to poll for traces more than ten per second, then use simple wxTimer for that. Also removed Debug Lock since now everything happens in wx' mainloop.
Edouard Tisserant
parents: 1982
diff changeset
   120
    }
1997
d9e8fb47340f PEP-8 and PyLint
Edouard Tisserant
parents: 1995
diff changeset
   121
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   122
    class PyroProxyProxy(object):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   123
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   124
        A proxy proxy class to handle Beremiz Pyro interface specific behavior.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   125
        And to put Pyro exception catcher in between caller and Pyro proxy
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   126
        """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   127
        def __getattr__(self, attrName):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   128
            member = self.__dict__.get(attrName, None)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   129
            if member is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   130
                def my_local_func(*args, **kwargs):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   131
                    return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs)
1995
691d119ba20f Removed DebugThread. Take advantage of the fact that buffering is done in runtime. No need to poll for traces more than ten per second, then use simple wxTimer for that. Also removed Debug Lock since now everything happens in wx' mainloop.
Edouard Tisserant
parents: 1982
diff changeset
   132
                member = PyroCatcher(my_local_func, _special_return_funcs.get(attrName, None))
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   133
                self.__dict__[attrName] = member
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   134
            return member
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
   135
2463
8742337a9fe3 Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents: 2430
diff changeset
   136
    return PyroProxyProxy