connectors/__init__.py
author Edouard Tisserant
Wed, 25 Feb 2015 13:59:01 +0100
changeset 1451 94e620cbd9de
parent 1440 e8daabf2c438
child 1455 4ba27ed51e48
permissions -rwxr-xr-x
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
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
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     4
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     5
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#See COPYING file for copyrights details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     7
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     8
#This library is free software; you can redistribute it and/or
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     9
#modify it under the terms of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    10
#License as published by the Free Software Foundation; either
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    11
#version 2.1 of the License, or (at your option) any later version.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    12
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    13
#This library is distributed in the hope that it will be useful,
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    14
#but WITHOUT ANY WARRANTY; without even the implied warranty of
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    15
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    16
#General Public License for more details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    17
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    18
#You should have received a copy of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    19
#License along with this library; if not, write to the Free Software
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    20
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    21
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    22
# Package initialisation
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    23
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    24
from os import listdir, path
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    26
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
_base_path = path.split(__file__)[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    29
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    30
def _GetLocalConnectorClassFactory(name):
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    31
    return lambda:getattr(__import__(name,globals(),locals()), name + "_connector_factory")
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    32
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    33
connectors = {name:_GetLocalConnectorClassFactory(name)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    34
                  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
    35
                      if path.isdir(path.join(_base_path, name))
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    36
                          and not name.startswith("__")}
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    37
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 591
diff changeset
    38
def ConnectorFactory(uri, confnodesroot):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    39
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    40
    Return a connector corresponding to the URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    41
    or None if cannot connect to URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    42
    """
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    43
    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
    44
    if servicetype == "LOCAL":
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    45
        # Local is special case
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    46
        # 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
    47
        # 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
    48
        servicetype = "PYRO"
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    49
        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
    50
            taskbaricon=True)
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    51
        uri="PYRO://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
    52
    elif servicetype in connectors:
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    53
        pass
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    54
    elif servicetype[-1]=='S' and servicetype[:-1] in connectors:
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    55
        servicetype = servicetype[:-1]
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    56
    else :
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    57
        return None
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    58
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 763
diff changeset
    59
    # 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
    60
    connectorclass = connectors[servicetype]()
733
915be999f3f0 targets and connectors are nor extensible
Edouard Tisserant
parents: 717
diff changeset
    61
    return connectorclass(uri, confnodesroot)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    62