1 from __future__ import absolute_import |
|
2 from os import listdir, path |
|
3 import util.paths as paths |
|
4 |
|
5 _base_path = paths.AbsDir(__file__) |
|
6 |
|
7 |
|
8 def _GetLocalConnectorClassDialog(name): |
|
9 return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_dialog") |
|
10 |
|
11 def _GetLocalConnectorURITypes(name): |
|
12 return lambda: getattr(__import__(name, globals(), locals()), "URITypes", None) |
|
13 |
|
14 connectors_dialog = {name: |
|
15 {"function":_GetLocalConnectorClassDialog(name), "URITypes": _GetLocalConnectorURITypes(name)} |
|
16 for name in listdir(_base_path) |
|
17 if (path.isdir(path.join(_base_path, name)) and |
|
18 not name.startswith("__"))} |
|
19 |
|
20 def ConnectorDialog(type, confnodesroot): |
|
21 if type not in connectors_dialog: |
|
22 return None |
|
23 |
|
24 connectorclass = connectors_dialog[type]["function"]() |
|
25 return connectorclass(confnodesroot) |
|
26 |
|
27 def GetConnectorFromURI(uri): |
|
28 typeOfConnector = None |
|
29 for t in connectors_dialog: |
|
30 connectorTypes = connectors_dialog[t]["URITypes"]() |
|
31 if connectorTypes and uri in connectorTypes: |
|
32 typeOfConnector = t |
|
33 break |
|
34 |
|
35 return typeOfConnector |
|