[modules/nic] Check for vanished interfaces
If a widget exists for an interface that is not there anymore (i.e. a tunnel interface that has been removed, or a USB device that has been unplugged), remove that widget from the list. see #23
This commit is contained in:
parent
a045962d00
commit
72e375ac8b
1 changed files with 9 additions and 0 deletions
|
@ -45,6 +45,10 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def _update_widgets(self, widgets):
|
def _update_widgets(self, widgets):
|
||||||
interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ]
|
interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ]
|
||||||
|
|
||||||
|
for widget in widgets:
|
||||||
|
widget.set("visited", False)
|
||||||
|
|
||||||
for intf in interfaces:
|
for intf in interfaces:
|
||||||
addr = []
|
addr = []
|
||||||
state = "down"
|
state = "down"
|
||||||
|
@ -63,5 +67,10 @@ class Module(bumblebee.engine.Module):
|
||||||
widget.full_text("{} {} {}".format(intf, state, ", ".join(addr)))
|
widget.full_text("{} {} {}".format(intf, state, ", ".join(addr)))
|
||||||
widget.set("intf", intf)
|
widget.set("intf", intf)
|
||||||
widget.set("state", state)
|
widget.set("state", state)
|
||||||
|
widget.set("visited", True)
|
||||||
|
|
||||||
|
for widget in widgets:
|
||||||
|
if widget.get("visited") == False:
|
||||||
|
widgets.remove(widget)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue