connectors/__init__.py
author laurent
Thu, 08 Oct 2009 11:26:40 +0200
changeset 411 8261c8f1e365
parent 399 77e23bf04c33
child 591 3ece9ba72aaf
permissions -rwxr-xr-x
Bug on Debug trying to start (and stop) before PLC started fixed.
Adding support for detecting platform default settings for target type and canfestival node.
Clear tests folder, leaving only multi-platform tests.
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
import PYRO
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    27
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
_base_path = path.split(__file__)[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    29
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    30
connector_types = [name for name in listdir(_base_path)
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    31
                        if path.isdir(path.join(_base_path, name))
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    32
                            and name.upper() != "CVS"
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    33
                            and not name.startswith("__")]
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    34
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    35
# a dict from a URI scheme (connector name) to connector module
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    36
connector_modules = {}
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    37
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    38
# a dict from a DNS-SD service type to a connector module that support it
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    39
dnssd_connectors = {}
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    40
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    41
for t in connector_types:
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    42
    new_module = getattr(__import__("connectors." + t), t)
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    43
    connector_modules[t] = new_module
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    44
    
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    45
    if hasattr(new_module, "supported_dnssd_services"):
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    46
        for st in new_module.supported_dnssd_services:
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    47
            dnssd_connectors[st] = new_module
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    48
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    49
def ConnectorFactory(uri, pluginsroot):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    50
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    51
    Return a connector corresponding to the URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    52
    or None if cannot connect to URI
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    53
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    54
    servicetype = uri.split("://")[0]
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    55
    if servicetype in connector_types:
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    56
        # import module according to uri type
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    57
        connectormodule = connector_modules[servicetype]
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    58
        factoryname = servicetype + "_connector_factory"
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    59
        return getattr(connectormodule, factoryname)(uri, pluginsroot)
227
48c13b84505c - Some improovements in debug data feedback data
etisserant
parents: 203
diff changeset
    60
    elif servicetype == "LOCAL":
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 298
diff changeset
    61
        runtime_port = pluginsroot.AppFrame.StartLocalRuntime(taskbaricon=True)
227
48c13b84505c - Some improovements in debug data feedback data
etisserant
parents: 203
diff changeset
    62
        return PYRO.PYRO_connector_factory(
290
3bd617ae7a05 Local Runtime (LOCAL://) now launched "on demand"
etisserant
parents: 227
diff changeset
    63
                       "PYRO://127.0.0.1:"+str(runtime_port), 
227
48c13b84505c - Some improovements in debug data feedback data
etisserant
parents: 203
diff changeset
    64
                       pluginsroot)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    65
    else :
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    66
        return None    
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    67