connectors/PYRO/__init__.py
branch1.1 Korean release
changeset 1280 72a826dfcfbb
parent 1116 300f98a8d4c6
child 1434 6e0cd0ceabb7
equal deleted inserted replaced
977:c8e008b8cefe 1280:72a826dfcfbb
    43     if location.find(service_type) != -1:
    43     if location.find(service_type) != -1:
    44         try :
    44         try :
    45             from util.Zeroconf import Zeroconf
    45             from util.Zeroconf import Zeroconf
    46             r = Zeroconf()
    46             r = Zeroconf()
    47             i=r.getServiceInfo(service_type, location)
    47             i=r.getServiceInfo(service_type, location)
       
    48             if i is None : raise Exception, "'%s' not found"%location
    48             ip = str(socket.inet_ntoa(i.getAddress()))
    49             ip = str(socket.inet_ntoa(i.getAddress()))
    49             port = str(i.getPort())
    50             port = str(i.getPort())
    50             newlocation = ip+':'+port
    51             newlocation = ip+':'+port
    51             confnodesroot.logger.write(_("'%s' is located at %s\n")%(location, newlocation))
    52             confnodesroot.logger.write(_("'%s' is located at %s\n")%(location, newlocation))
    52             location = newlocation
    53             location = newlocation
    70         and return defaul value when it happen
    71         and return defaul value when it happen
    71         """
    72         """
    72         def catcher_func(*args,**kwargs):
    73         def catcher_func(*args,**kwargs):
    73             try:
    74             try:
    74                 return func(*args,**kwargs)
    75                 return func(*args,**kwargs)
    75             except Pyro.errors.ProtocolError, e:
       
    76                 pass
       
    77             except Pyro.errors.ConnectionClosedError, e:
    76             except Pyro.errors.ConnectionClosedError, e:
    78                 confnodesroot.logger.write_error("Connection lost!\n")
    77                 confnodesroot.logger.write_error("Connection lost!\n")
    79                 confnodesroot._connector = None
    78                 confnodesroot._SetConnector(None)
       
    79             except Pyro.errors.ProtocolError, e:
       
    80                 confnodesroot.logger.write_error("Pyro exception: "+str(e)+"\n")
    80             except Exception,e:
    81             except Exception,e:
    81                 #confnodesroot.logger.write_error(traceback.format_exc())
    82                 #confnodesroot.logger.write_error(traceback.format_exc())
    82                 errmess = ''.join(Pyro.util.getPyroTraceback(e))
    83                 errmess = ''.join(Pyro.util.getPyroTraceback(e))
    83                 confnodesroot.logger.write_error(errmess+"\n")
    84                 confnodesroot.logger.write_error(errmess+"\n")
    84                 print errmess
    85                 print errmess
    85                 confnodesroot._connector = None
    86                 confnodesroot._SetConnector(None)
    86                 return default
    87             return default
    87         return catcher_func
    88         return catcher_func
    88 
    89 
    89     # Check connection is effective. 
    90     # Check connection is effective. 
    90     # lambda is for getattr of GetPLCstatus to happen inside catcher
    91     # lambda is for getattr of GetPLCstatus to happen inside catcher
    91     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() is None:
    92     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() is None: