22 from Pyro.errors import PyroError |
22 from Pyro.errors import PyroError |
23 import Pyro.util |
23 import Pyro.util |
24 import traceback |
24 import traceback |
25 from time import sleep |
25 from time import sleep |
26 import copy |
26 import copy |
|
27 import socket |
|
28 service_type = '_PYRO._tcp.local.' |
27 |
29 |
28 # this module attribute contains a list of DNS-SD (Zeroconf) service types |
30 # this module attribute contains a list of DNS-SD (Zeroconf) service types |
29 # supported by this connector confnode. |
31 # supported by this connector confnode. |
30 # |
32 # |
31 # for connectors that do not support DNS-SD, this attribute can be omitted |
33 # for connectors that do not support DNS-SD, this attribute can be omitted |
36 This returns the connector to Pyro style PLCobject |
38 This returns the connector to Pyro style PLCobject |
37 """ |
39 """ |
38 confnodesroot.logger.write(_("Connecting to URI : %s\n")%uri) |
40 confnodesroot.logger.write(_("Connecting to URI : %s\n")%uri) |
39 |
41 |
40 servicetype, location = uri.split("://") |
42 servicetype, location = uri.split("://") |
|
43 if location.find(service_type) != -1: |
|
44 try : |
|
45 from util.Zeroconf import Zeroconf |
|
46 r = Zeroconf() |
|
47 i=r.getServiceInfo(service_type, location) |
|
48 ip = str(socket.inet_ntoa(i.getAddress())) |
|
49 port = str(i.getPort()) |
|
50 newlocation = ip+':'+port |
|
51 confnodesroot.logger.write(_("'%s' is located at %s\n")%(location, newlocation)) |
|
52 location = newlocation |
|
53 r.close() |
|
54 except Exception, msg: |
|
55 confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n")%location) |
|
56 confnodesroot.logger.write_error(traceback.format_exc()) |
|
57 return None |
41 |
58 |
42 # Try to get the proxy object |
59 # Try to get the proxy object |
43 try : |
60 try : |
44 RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject") |
61 RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject") |
45 except Exception, msg: |
62 except Exception, msg: |
46 confnodesroot.logger.write_error(_("Wrong URI, please check it !\n")) |
63 confnodesroot.logger.write_error(_("Connection to '%s' failed.\n")%location) |
47 confnodesroot.logger.write_error(traceback.format_exc()) |
64 confnodesroot.logger.write_error(traceback.format_exc()) |
48 return None |
65 return None |
49 |
66 |
50 def PyroCatcher(func, default=None): |
67 def PyroCatcher(func, default=None): |
51 """ |
68 """ |