Allow user to run browser without Zeroconf

This commit is contained in:
Nicolas Hennion 2014-11-25 11:42:24 +01:00
parent bd768aa4da
commit 6105c493e0

View File

@ -141,29 +141,32 @@ class GlancesAutoDiscoverServer(object):
try: try:
self.zeroconf = Zeroconf() self.zeroconf = Zeroconf()
except socker.error as e: except socker.error as e:
logger.critical("Can not start Zeroconf (%s)" % e) logger.error("Can not start Zeroconf (%s)" % e)
sys.exit(2) self.zeroconf_enable_tag = False
else:
self.listener = GlancesAutoDiscoverListener() self.listener = GlancesAutoDiscoverListener()
self.browser = ServiceBrowser( self.browser = ServiceBrowser(
self.zeroconf, zeroconf_type, self.listener) self.zeroconf, zeroconf_type, self.listener)
self.zeroconf_enable_tag = True
else: else:
logger.critical( logger.error(
"Can not start autodiscover mode (Zeroconf lib is not installed)") "Can not start autodiscover mode (Zeroconf lib is not installed)")
sys.exit(2) self.zeroconf_enable_tag = False
def get_servers_list(self): def get_servers_list(self):
"""Return the current server list (dict of dict)""" """Return the current server list (dict of dict)"""
if zeroconf_tag: if zeroconf_tag and self.zeroconf_enable_tag:
return self.listener.get_servers_list() return self.listener.get_servers_list()
else: else:
return [] return []
def set_server(self, server_pos, key, value): def set_server(self, server_pos, key, value):
"""Set the key to the value for the server_pos (position in the list)""" """Set the key to the value for the server_pos (position in the list)"""
if zeroconf_tag and self.zeroconf_enable_tag:
self.listener.set_server(server_pos, key, value) self.listener.set_server(server_pos, key, value)
def close(self): def close(self):
if zeroconf_tag: if zeroconf_tag and self.zeroconf_enable_tag:
self.zeroconf.close() self.zeroconf.close()