connectors/__init__.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 09 Jun 2017 18:12:12 +0300
changeset 1695 a63bb4025852
parent 1680 6db967480b7d
child 1731 6ebd9c40b2be
permissions -rwxr-xr-x
avoid infinite loop in search

for example following regexp '()' creates infinite list of result
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     3
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     9
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    10
# See COPYING file for copyrights details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    15
# of the License, or (at your option) any later version.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    17
# This program is distributed in the hope that it will be useful,
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    20
# GNU General Public License for more details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    26
# Package initialisation
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
from os import listdir, path
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    29
import util.paths as paths
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    31
_base_path = paths.AbsDir(__file__)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    33
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    34
def _GetLocalConnectorClassFactory(name):
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    35
    return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    36
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    37
connectors = {name:_GetLocalConnectorClassFactory(name)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    38
                  for name in listdir(_base_path)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    39
                      if path.isdir(path.join(_base_path, name))
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    40
                          and not name.startswith("__")}
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    41
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    42
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 591
diff changeset
    43
def ConnectorFactory(uri, confnodesroot):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    44
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    45
    Return a connector corresponding to the URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    46
    or None if cannot connect to URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    47
    """
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    48
    servicetype = uri.split("://")[0].upper()
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    49
    if servicetype == "LOCAL":
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    50
        # Local is special case
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    51
        # pyro connection to local runtime
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    52
        # started on demand, listening on random port
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    53
        servicetype = "PYRO"
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    54
        runtime_port = confnodesroot.AppFrame.StartLocalRuntime(
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    55
            taskbaricon=True)
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    56
        uri = "PYROLOC://127.0.0.1:" + str(runtime_port)
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    57
    elif servicetype in connectors:
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    58
        pass
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    59
    elif servicetype[-1] == 'S' and servicetype[:-1] in connectors:
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    60
        servicetype = servicetype[:-1]
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1440
diff changeset
    61
    else:
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    62
        return None
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    63
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    64
    # import module according to uri type
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    65
    connectorclass = connectors[servicetype]()
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    66
    return connectorclass(uri, confnodesroot)