connectors/PYRO/__init__.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 22 Apr 2016 17:02:18 +0300
changeset 1501 d917c209529d
parent 1455 4ba27ed51e48
child 1571 486f94a8032c
permissions -rwxr-xr-x
fix Traceback if search icon on library panel is clicked, when no
category/item is selected in the library.

The problem is here, that if nothing is selected method GetSelection()
returns root item, that doesn't have any python data associated with it.
This issue seems to be wx3.0 specified, because it doesn't exist
with wx2.8 on Windows.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     3
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     4
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     5
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     6
# See COPYING file for copyrights details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     7
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     8
# This library is free software; you can redistribute it and/or
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     9
# modify it under the terms of the GNU General Public
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    10
# License as published by the Free Software Foundation; either
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    11
# version 2.1 of the License, or (at your option) any later version.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    12
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    13
# This library is distributed in the hope that it will be useful,
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    16
# General Public License for more details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    17
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    18
# You should have received a copy of the GNU General Public
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    19
# License along with this library; if not, write to the Free Software
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    21
import Pyro
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    22
import Pyro.core
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    23
import Pyro.util
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    24
from Pyro.errors import PyroError
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
import traceback
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    26
from time import sleep
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
    27
import copy
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    28
import socket
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    29
service_type = '_PYRO._tcp.local.'
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    30
import os.path
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    31
# this module attribute contains a list of DNS-SD (Zeroconf) service types
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
    32
# supported by this connector confnode.
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    33
#
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    34
# for connectors that do not support DNS-SD, this attribute can be omitted
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    35
# or set to an empty list.
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    36
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
    37
def PYRO_connector_factory(uri, confnodesroot):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    38
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    39
    This returns the connector to Pyro style PLCobject
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    40
    """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    41
    confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    42
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    43
    servicetype, location = uri.split("://")
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    44
    if servicetype == "PYROS":
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    45
        schemename = "PYROLOCSSL"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    46
        # Protect against name->IP substitution in Pyro3
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    47
        Pyro.config.PYRO_DNS_URI = True
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    48
        # Beware Pyro lib need str path, not unicode
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    49
        # don't rely on PYRO_STORAGE ! see documentation
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    50
        Pyro.config.PYROSSL_CERTDIR = os.path.abspath(str(confnodesroot.ProjectPath) + '/certs')
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    51
        if not os.path.exists(Pyro.config.PYROSSL_CERTDIR):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    52
            confnodesroot.logger.write_error(
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    53
                'Error : the directory %s is missing for SSL certificates (certs_dir).'
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    54
                'Please fix it in your project.\n' % Pyro.config.PYROSSL_CERTDIR)
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    55
            return None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    56
        else:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    57
            confnodesroot.logger.write(_("PYRO using certificates in '%s' \n")
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    58
                                       % (Pyro.config.PYROSSL_CERTDIR))
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    59
        Pyro.config.PYROSSL_CERT = "client.crt"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    60
        Pyro.config.PYROSSL_KEY = "client.key"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    61
        # Ugly Monkey Patching
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    62
        def _gettimeout(self):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    63
            return self.timeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    64
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    65
        def _settimeout(self, timeout):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    66
            self.timeout = timeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    67
        from M2Crypto.SSL import Connection
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    68
        Connection.timeout = None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    69
        Connection.gettimeout = _gettimeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    70
        Connection.settimeout = _settimeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    71
        # M2Crypto.SSL.Checker.WrongHost: Peer certificate commonName does not
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    72
        # match host, expected 127.0.0.1, got server
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    73
        Connection.clientPostConnectionCheck = None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    74
    else:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    75
        schemename = "PYROLOC"
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    76
    if location.find(service_type) != -1:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    77
        try:
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    78
            from util.Zeroconf import Zeroconf
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    79
            r = Zeroconf()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    80
            i = r.getServiceInfo(service_type, location)
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    81
            if i is None:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    82
                raise Exception("'%s' not found" % location)
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    83
            ip = str(socket.inet_ntoa(i.getAddress()))
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    84
            port = str(i.getPort())
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    85
            newlocation = ip + ':' + port
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    86
            confnodesroot.logger.write(_("'%s' is located at %s\n") % (location, newlocation))
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    87
            location = newlocation
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    88
            r.close()
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    89
        except Exception, msg:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    90
            confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n") % location)
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    91
            confnodesroot.logger.write_error(traceback.format_exc())
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    92
            return None
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
    93
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    94
    # Try to get the proxy object
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    95
    try:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    96
        RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    97
    except Exception, msg:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    98
        confnodesroot.logger.write_error(_("Connection to '%s' failed.\n") % location)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
    99
        confnodesroot.logger.write_error(traceback.format_exc())
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   100
        return None
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   101
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   102
    def PyroCatcher(func, default=None):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   103
        """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   104
        A function that catch a Pyro exceptions, write error to logger
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   105
        and return default value when it happen
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   106
        """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   107
        def catcher_func(*args, **kwargs):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   108
            try:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   109
                return func(*args, **kwargs)
1116
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   110
            except Pyro.errors.ConnectionClosedError, e:
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   111
                confnodesroot.logger.write_error("Connection lost!\n")
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   112
                confnodesroot._SetConnector(None)
493
015a803301b9 Catch ProtocolError exception when connection failed
laurent
parents: 486
diff changeset
   113
            except Pyro.errors.ProtocolError, e:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   114
                confnodesroot.logger.write_error("Pyro exception: " + str(e) + "\n")
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   115
            except Exception, e:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   116
                # confnodesroot.logger.write_error(traceback.format_exc())
477
f66a092b6e74 Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 465
diff changeset
   117
                errmess = ''.join(Pyro.util.getPyroTraceback(e))
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   118
                confnodesroot.logger.write_error(errmess + "\n")
477
f66a092b6e74 Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 465
diff changeset
   119
                print errmess
1116
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   120
                confnodesroot._SetConnector(None)
1070
86ee833e33ef Added exception printing on Pyro connector, tracking random connection failure...
Edouard Tisserant
parents: 1035
diff changeset
   121
            return default
218
71fddab24be9 remove old code and fix typo
greg
parents: 203
diff changeset
   122
        return catcher_func
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   123
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   124
    # Check connection is effective.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   125
    # lambda is for getattr of GetPLCstatus to happen inside catcher
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   126
    if PyroCatcher(lambda: RemotePLCObjectProxy.GetPLCstatus())() is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   127
        confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n"))
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   128
        return None
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   129
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   130
    class PyroProxyProxy(object):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   131
        """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   132
        A proxy proxy class to handle Beremiz Pyro interface specific behavior.
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   133
        And to put Pyro exception catcher in between caller and Pyro proxy
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   134
        """
284
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   135
        def __init__(self):
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   136
            # for safe use in from debug thread, must create a copy
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   137
            self.RemotePLCObjectProxyCopy = None
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   138
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   139
        def GetPyroProxy(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   140
            """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   141
            This func returns the real Pyro Proxy.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   142
            Use this if you musn't keep reference to it.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   143
            """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   144
            return RemotePLCObjectProxy
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   145
235
a66e150f2888 Improved debug data feedback.
etisserant
parents: 231
diff changeset
   146
        def _PyroStartPLC(self, *args, **kwargs):
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   147
            """
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   148
            confnodesroot._connector.GetPyroProxy() is used
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   149
            rather than RemotePLCObjectProxy because
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   150
            object is recreated meanwhile,
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   151
            so we must not keep ref to it here
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   152
            """
969
1950fe687dde Fix warning with LogMessage function
Laurent Bessard
parents: 923
diff changeset
   153
            current_status, log_count = confnodesroot._connector.GetPyroProxy().GetPLCstatus()
465
67d32a91d70b Fixes in debug + reconnect to running PLC
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 446
diff changeset
   154
            if current_status == "Dirty":
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   155
                """
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   156
                Some bad libs with static symbols may polute PLC
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   157
                ask runtime to suicide and come back again
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   158
                """
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   159
                confnodesroot.logger.write(_("Force runtime reload\n"))
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   160
                confnodesroot._connector.GetPyroProxy().ForceReload()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   161
                confnodesroot._Disconnect()
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   162
                # let remote PLC time to resurect.(freeze app)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   163
                sleep(0.5)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   164
                confnodesroot._Connect()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   165
            self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   166
            return confnodesroot._connector.GetPyroProxy().StartPLC(*args, **kwargs)
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   167
        StartPLC = PyroCatcher(_PyroStartPLC, False)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   168
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   169
        def _PyroGetTraceVariables(self):
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   170
            """
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   171
            for safe use in from debug thread, must use the copy
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   172
            """
465
67d32a91d70b Fixes in debug + reconnect to running PLC
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 446
diff changeset
   173
            if self.RemotePLCObjectProxyCopy is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   174
                self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   175
            return self.RemotePLCObjectProxyCopy.GetTraceVariables()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   176
        GetTraceVariables = PyroCatcher(_PyroGetTraceVariables, ("Broken", None))
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   177
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   178
        def _PyroGetPLCstatus(self):
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   179
            return RemotePLCObjectProxy.GetPLCstatus()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   180
        GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, ("Broken", None))
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   181
699
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   182
        def _PyroRemoteExec(self, script, **kwargs):
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   183
            return RemotePLCObjectProxy.RemoteExec(script, **kwargs)
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   184
        RemoteExec = PyroCatcher(_PyroRemoteExec, (-1, "RemoteExec script failed!"))
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   185
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   186
        def __getattr__(self, attrName):
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   187
            member = self.__dict__.get(attrName, None)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   188
            if member is None:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   189
                def my_local_func(*args, **kwargs):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   190
                    return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs)
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   191
                member = PyroCatcher(my_local_func, None)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   192
                self.__dict__[attrName] = member
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   193
            return member
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   194
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   195
    return PyroProxyProxy()