Suppress errors when no gateways are found
This commit is contained in:
parent
3031077713
commit
5dec1adc97
1 changed files with 22 additions and 13 deletions
|
@ -16,12 +16,16 @@ class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config)
|
super(Module, self).__init__(engine, config)
|
||||||
|
|
||||||
|
try:
|
||||||
self._bandwidth = BandwidthInfo()
|
self._bandwidth = BandwidthInfo()
|
||||||
|
|
||||||
self._download_tx = self._bandwidth.bytes_recv()
|
self._download_tx = self._bandwidth.bytes_recv()
|
||||||
self._upload_tx = self._bandwidth.bytes_sent()
|
self._upload_tx = self._bandwidth.bytes_sent()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
|
try:
|
||||||
download_tx = self._bandwidth.bytes_recv()
|
download_tx = self._bandwidth.bytes_recv()
|
||||||
upload_tx = self._bandwidth.bytes_sent()
|
upload_tx = self._bandwidth.bytes_sent()
|
||||||
|
|
||||||
|
@ -31,6 +35,8 @@ class Module(bumblebee.engine.Module):
|
||||||
self.update_widgets(widgets, download_rate, upload_rate)
|
self.update_widgets(widgets, download_rate, upload_rate)
|
||||||
|
|
||||||
self._download_tx, self._upload_tx = download_tx, upload_tx
|
self._download_tx, self._upload_tx = download_tx, upload_tx
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def update_widgets(self, widgets, download_rate, upload_rate):
|
def update_widgets(self, widgets, download_rate, upload_rate):
|
||||||
del widgets[:]
|
del widgets[:]
|
||||||
|
@ -43,8 +49,7 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
class BandwidthInfo(object):
|
class BandwidthInfo(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
io_counters = self.io_counters()
|
self.bandwidth()
|
||||||
self.network = io_counters[self.default_network_adapter()]
|
|
||||||
|
|
||||||
def bytes_recv(self):
|
def bytes_recv(self):
|
||||||
return self.bandwidth().bytes_recv
|
return self.bandwidth().bytes_recv
|
||||||
|
@ -57,8 +62,12 @@ class BandwidthInfo(object):
|
||||||
return io_counters[self.default_network_adapter()]
|
return io_counters[self.default_network_adapter()]
|
||||||
|
|
||||||
def default_network_adapter(self):
|
def default_network_adapter(self):
|
||||||
gateways = netifaces.gateways()
|
gateway = netifaces.gateways()['default']
|
||||||
return gateways['default'][netifaces.AF_INET][1]
|
|
||||||
|
if (len(gateway) == 0):
|
||||||
|
raise 'No default gateway found'
|
||||||
|
|
||||||
|
return gateway[netifaces.AF_INET][1]
|
||||||
|
|
||||||
def io_counters(self):
|
def io_counters(self):
|
||||||
return psutil.net_io_counters(pernic=True)
|
return psutil.net_io_counters(pernic=True)
|
||||||
|
|
Loading…
Reference in a new issue