author | laurent |
Wed, 30 May 2012 13:05:18 +0200 | |
changeset 754 | a8c258f7bdcf |
parent 733 | 915be999f3f0 |
child 763 | c1104099c151 |
permissions | -rwxr-xr-x |
203 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
# |
|
4 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
5 |
# |
|
6 |
#See COPYING file for copyrights details. |
|
7 |
# |
|
8 |
#This library is free software; you can redistribute it and/or |
|
9 |
#modify it under the terms of the GNU General Public |
|
10 |
#License as published by the Free Software Foundation; either |
|
11 |
#version 2.1 of the License, or (at your option) any later version. |
|
12 |
# |
|
13 |
#This library is distributed in the hope that it will be useful, |
|
14 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
#General Public License for more details. |
|
17 |
# |
|
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 |
|
20 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
||
22 |
# Package initialisation |
|
23 |
||
24 |
from os import listdir, path |
|
25 |
||
399 | 26 |
|
203 | 27 |
_base_path = path.split(__file__)[0] |
28 |
||
399 | 29 |
|
30 |
# a dict from a DNS-SD service type to a connector module that support it |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
31 |
dnssd_connectors = {"_PYRO._tcp.local.":"PYRO"} |
399 | 32 |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
33 |
def _GetLocalConnectorClassFactory(name): |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
34 |
return lambda:getattr(__import__(name,globals(),locals()), name + "_connector_factory") |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
35 |
|
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
36 |
connectors = {name:_GetLocalConnectorClassFactory(name) |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
37 |
for name in listdir(_base_path) |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
38 |
if path.isdir(path.join(_base_path, name)) |
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
39 |
and not name.startswith("__")} |
203 | 40 |
|
717 | 41 |
def ConnectorFactory(uri, confnodesroot): |
203 | 42 |
""" |
43 |
Return a connector corresponding to the URI |
|
44 |
or None if cannot connect to URI |
|
45 |
""" |
|
46 |
servicetype = uri.split("://")[0] |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
47 |
if servicetype in connectors: |
203 | 48 |
# import module according to uri type |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
49 |
connectorclass = connectors[servicetype]() |
227
48c13b84505c
- Some improovements in debug data feedback data
etisserant
parents:
203
diff
changeset
|
50 |
elif servicetype == "LOCAL": |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
51 |
from PYRO import PYRO_connector_factory as connectorclass |
717 | 52 |
runtime_port = confnodesroot.AppFrame.StartLocalRuntime(taskbaricon=True) |
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
53 |
uri="PYRO://127.0.0.1:"+str(runtime_port) |
203 | 54 |
else : |
55 |
return None |
|
733
915be999f3f0
targets and connectors are nor extensible
Edouard Tisserant
parents:
717
diff
changeset
|
56 |
return connectorclass(uri, confnodesroot) |
203 | 57 |