connectors/__init__.py
changeset 1455 4ba27ed51e48
parent 1440 e8daabf2c438
child 1571 486f94a8032c
equal deleted inserted replaced
1454:29b02164e65d 1455:4ba27ed51e48
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 #
     3 #
     4 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     4 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     5 #
     5 #
     6 #See COPYING file for copyrights details.
     6 # See COPYING file for copyrights details.
     7 #
     7 #
     8 #This library is free software; you can redistribute it and/or
     8 # This library is free software; you can redistribute it and/or
     9 #modify it under the terms of the GNU General Public
     9 # modify it under the terms of the GNU General Public
    10 #License as published by the Free Software Foundation; either
    10 # License as published by the Free Software Foundation; either
    11 #version 2.1 of the License, or (at your option) any later version.
    11 # version 2.1 of the License, or (at your option) any later version.
    12 #
    12 #
    13 #This library is distributed in the hope that it will be useful,
    13 # This library is distributed in the hope that it will be useful,
    14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16 #General Public License for more details.
    16 # General Public License for more details.
    17 #
    17 #
    18 #You should have received a copy of the GNU General Public
    18 # You should have received a copy of the GNU General Public
    19 #License along with this library; if not, write to the Free Software
    19 # License along with this library; if not, write to the Free Software
    20 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    21 
    21 
    22 # Package initialisation
    22 # Package initialisation
    23 
    23 
    24 from os import listdir, path
    24 from os import listdir, path
    25 
    25 
    26 
    26 
    27 _base_path = path.split(__file__)[0]
    27 _base_path = path.split(__file__)[0]
    28 
    28 
    29 
    29 
    30 def _GetLocalConnectorClassFactory(name):
    30 def _GetLocalConnectorClassFactory(name):
    31     return lambda:getattr(__import__(name,globals(),locals()), name + "_connector_factory")
    31     return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
    32 
    32 
    33 connectors = {name:_GetLocalConnectorClassFactory(name)
    33 connectors = {name:_GetLocalConnectorClassFactory(name)
    34                   for name in listdir(_base_path)
    34                   for name in listdir(_base_path)
    35                       if path.isdir(path.join(_base_path, name))
    35                       if path.isdir(path.join(_base_path, name))
    36                           and not name.startswith("__")}
    36                           and not name.startswith("__")}
       
    37 
    37 
    38 
    38 def ConnectorFactory(uri, confnodesroot):
    39 def ConnectorFactory(uri, confnodesroot):
    39     """
    40     """
    40     Return a connector corresponding to the URI
    41     Return a connector corresponding to the URI
    41     or None if cannot connect to URI
    42     or None if cannot connect to URI
    46         # pyro connection to local runtime
    47         # pyro connection to local runtime
    47         # started on demand, listening on random port
    48         # started on demand, listening on random port
    48         servicetype = "PYRO"
    49         servicetype = "PYRO"
    49         runtime_port = confnodesroot.AppFrame.StartLocalRuntime(
    50         runtime_port = confnodesroot.AppFrame.StartLocalRuntime(
    50             taskbaricon=True)
    51             taskbaricon=True)
    51         uri="PYRO://127.0.0.1:"+str(runtime_port)
    52         uri = "PYROLOC://127.0.0.1:" + str(runtime_port)
    52     elif servicetype in connectors:
    53     elif servicetype in connectors:
    53         pass
    54         pass
    54     elif servicetype[-1]=='S' and servicetype[:-1] in connectors:
    55     elif servicetype[-1] == 'S' and servicetype[:-1] in connectors:
    55         servicetype = servicetype[:-1]
    56         servicetype = servicetype[:-1]
    56     else :
    57     else:
    57         return None
    58         return None
    58 
    59 
    59     # import module according to uri type
    60     # import module according to uri type
    60     connectorclass = connectors[servicetype]()
    61     connectorclass = connectors[servicetype]()
    61     return connectorclass(uri, confnodesroot)
    62     return connectorclass(uri, confnodesroot)
    62