27 |
27 |
28 |
28 |
29 from __future__ import absolute_import |
29 from __future__ import absolute_import |
30 from os import listdir, path |
30 from os import listdir, path |
31 import util.paths as paths |
31 import util.paths as paths |
|
32 from connectors.ConnectorBase import ConnectorBase |
|
33 from types import ClassType |
32 |
34 |
33 connectors_packages = ["PYRO","WAMP"] |
35 connectors_packages = ["PYRO","WAMP"] |
34 |
36 |
35 |
37 |
36 def _GetLocalConnectorClassFactory(name): |
38 def _GetLocalConnectorClassFactory(name): |
62 def ConnectorFactory(uri, confnodesroot): |
64 def ConnectorFactory(uri, confnodesroot): |
63 """ |
65 """ |
64 Return a connector corresponding to the URI |
66 Return a connector corresponding to the URI |
65 or None if cannot connect to URI |
67 or None if cannot connect to URI |
66 """ |
68 """ |
67 scheme = uri.split("://")[0].upper() |
69 _scheme = uri.split("://")[0].upper() |
68 if scheme == "LOCAL": |
70 if _scheme == "LOCAL": |
69 # Local is special case |
71 # Local is special case |
70 # pyro connection to local runtime |
72 # pyro connection to local runtime |
71 # started on demand, listening on random port |
73 # started on demand, listening on random port |
72 scheme = "PYRO" |
74 scheme = "PYRO" |
73 runtime_port = confnodesroot.AppFrame.StartLocalRuntime( |
75 runtime_port = confnodesroot.AppFrame.StartLocalRuntime( |
74 taskbaricon=True) |
76 taskbaricon=True) |
75 uri = "PYROLOC://127.0.0.1:" + str(runtime_port) |
77 uri = "PYROLOC://127.0.0.1:" + str(runtime_port) |
76 elif scheme in connectors: |
78 elif _scheme in connectors: |
77 pass |
79 scheme = _scheme |
78 elif scheme[-1] == 'S' and scheme[:-1] in connectors: |
80 elif _scheme[-1] == 'S' and _scheme[:-1] in connectors: |
79 scheme = scheme[:-1] |
81 scheme = _scheme[:-1] |
80 else: |
82 else: |
81 return None |
83 return None |
82 |
84 |
83 # import module according to uri type |
85 # import module according to uri type and get connector specific baseclass |
84 connectorclass = connectors[scheme]() |
86 # first call to import the module, |
85 return connectorclass(uri, confnodesroot) |
87 # then call with parameters to create the class |
|
88 connector_specific_class = connectors[scheme]()(uri, confnodesroot) |
86 |
89 |
|
90 # new class inheriting from generic and specific connector base classes |
|
91 return ClassType(_scheme + "_connector", |
|
92 (ConnectorBase, connector_specific_class), {})() |
87 |
93 |
88 def EditorClassFromScheme(scheme): |
94 def EditorClassFromScheme(scheme): |
89 _Import_Dialogs() |
95 _Import_Dialogs() |
90 return per_URI_connectors.get(scheme, None) |
96 return per_URI_connectors.get(scheme, None) |
91 |
97 |