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 import PYRO |
|
27 |
26 _base_path = path.split(__file__)[0] |
28 _base_path = path.split(__file__)[0] |
27 |
29 |
28 connector_types = [name for name in listdir(_base_path) if path.isdir(path.join(_base_path, name)) and name.upper() != "CVS" and not name.startswith("__")] |
30 connector_types = [name for name in listdir(_base_path) |
|
31 if path.isdir(path.join(_base_path, name)) |
|
32 and name.upper() != "CVS" |
|
33 and not name.startswith("__")] |
|
34 |
|
35 # a dict from a URI scheme (connector name) to connector module |
|
36 connector_modules = {} |
|
37 |
|
38 # a dict from a DNS-SD service type to a connector module that support it |
|
39 dnssd_connectors = {} |
|
40 |
|
41 for t in connector_types: |
|
42 new_module = getattr(__import__("connectors." + t), t) |
|
43 connector_modules[t] = new_module |
|
44 |
|
45 if hasattr(new_module, "supported_dnssd_services"): |
|
46 for st in new_module.supported_dnssd_services: |
|
47 dnssd_connectors[st] = new_module |
29 |
48 |
30 def ConnectorFactory(uri, pluginsroot): |
49 def ConnectorFactory(uri, pluginsroot): |
31 """ |
50 """ |
32 Return a connector corresponding to the URI |
51 Return a connector corresponding to the URI |
33 or None if cannot connect to URI |
52 or None if cannot connect to URI |
34 """ |
53 """ |
35 servicetype = uri.split("://")[0] |
54 servicetype = uri.split("://")[0] |
36 if servicetype in connector_types: |
55 if servicetype in connector_types: |
37 # import module according to uri type |
56 # import module according to uri type |
38 connectormodule = getattr(__import__("connectors."+servicetype), servicetype) |
57 connectormodule = connector_modules[servicetype] |
39 factoryname = servicetype + "_connector_factory" |
58 factoryname = servicetype + "_connector_factory" |
40 return getattr(connectormodule, factoryname)(uri, pluginsroot) |
59 return getattr(connectormodule, factoryname)(uri, pluginsroot) |
41 elif servicetype == "LOCAL": |
60 elif servicetype == "LOCAL": |
42 #handle incompatibility with tray icon and svgui... |
61 runtime_port = pluginsroot.AppFrame.StartLocalRuntime(taskbaricon=True) |
43 poisoned_plugin = False |
|
44 for PlugIn in pluginsroot.IterChilds(): |
|
45 poisoned_plugin |= PlugIn.PlugType == "svgui" |
|
46 runtime_port = pluginsroot.AppFrame.StartLocalRuntime(taskbaricon = not poisoned_plugin) |
|
47 import PYRO |
|
48 return PYRO.PYRO_connector_factory( |
62 return PYRO.PYRO_connector_factory( |
49 "PYRO://127.0.0.1:"+str(runtime_port), |
63 "PYRO://127.0.0.1:"+str(runtime_port), |
50 pluginsroot) |
64 pluginsroot) |
51 else : |
65 else : |
52 return None |
66 return None |