[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:
Tobi-wan Kenobi 2016-12-10 11:33:35 +01:00
parent a045962d00
commit 72e375ac8b

View file

@ -45,6 +45,10 @@ class Module(bumblebee.engine.Module):
def _update_widgets(self, widgets):
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:
addr = []
state = "down"
@ -63,5 +67,10 @@ class Module(bumblebee.engine.Module):
widget.full_text("{} {} {}".format(intf, state, ", ".join(addr)))
widget.set("intf", intf)
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