connectors/__init__.py
branch#2476
changeset 2007 ef2d479f564f
parent 2006 c4ba142bf3fb
child 2182 eeca1aff0691
equal deleted inserted replaced
2006:c4ba142bf3fb 2007:ef2d479f564f
    34 
    34 
    35 
    35 
    36 def _GetLocalConnectorClassFactory(name):
    36 def _GetLocalConnectorClassFactory(name):
    37     return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
    37     return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
    38 
    38 
       
    39 def _GetLocalConnectorClassDialog(name):
       
    40     return lambda: getattr(__import__(name + '.dialog', globals(), locals(), fromlist=['dialog']), name + "_connector_dialog")
       
    41 
       
    42 def _GetLocalConnectorURITypes(name):
       
    43     return lambda: getattr(__import__(name + '.dialog', globals(), locals(), fromlist=['dialog']), "URITypes", None)
       
    44 
    39 
    45 
    40 connectors = {name:
    46 connectors = {name:
    41               _GetLocalConnectorClassFactory(name)
    47               _GetLocalConnectorClassFactory(name)
    42               for name in listdir(_base_path)
    48               for name in listdir(_base_path)
    43               if (path.isdir(path.join(_base_path, name)) and
    49               if (path.isdir(path.join(_base_path, name)) and
    44                   not name.startswith("__"))}
    50                   not name.startswith("__"))}
       
    51 
       
    52 connectors_dialog = {name:
       
    53                      {"function":_GetLocalConnectorClassDialog(name), "URITypes": _GetLocalConnectorURITypes(name)}
       
    54                      for name in listdir(_base_path)
       
    55                      if (path.isdir(path.join(_base_path, name)) and
       
    56                          not name.startswith("__"))}
    45 
    57 
    46 
    58 
    47 def ConnectorFactory(uri, confnodesroot):
    59 def ConnectorFactory(uri, confnodesroot):
    48     """
    60     """
    49     Return a connector corresponding to the URI
    61     Return a connector corresponding to the URI
    66         return None
    78         return None
    67 
    79 
    68     # import module according to uri type
    80     # import module according to uri type
    69     connectorclass = connectors[servicetype]()
    81     connectorclass = connectors[servicetype]()
    70     return connectorclass(uri, confnodesroot)
    82     return connectorclass(uri, confnodesroot)
       
    83 
       
    84 def ConnectorDialog(conn_type, confnodesroot):
       
    85     if conn_type not in connectors_dialog:
       
    86         return None
       
    87 
       
    88     connectorclass = connectors_dialog[conn_type]["function"]()
       
    89     return connectorclass(confnodesroot)
       
    90 
       
    91 def GetConnectorFromURI(uri):
       
    92     typeOfConnector = None
       
    93     for conn_type in connectors_dialog:
       
    94         connectorTypes = connectors_dialog[conn_type]["URITypes"]()
       
    95         if connectorTypes and uri in connectorTypes:
       
    96             typeOfConnector = conn_type
       
    97             break
       
    98 
       
    99     return typeOfConnector