From f95624d801bb00c98feef6f011dedefa5ef2ef52 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sun, 24 Aug 2014 23:58:17 +0200 Subject: [PATCH] Added unknown_up parameter. Closes #103. --- i3pystatus/network.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/i3pystatus/network.py b/i3pystatus/network.py index 3fe5a99..ded6d1e 100644 --- a/i3pystatus/network.py +++ b/i3pystatus/network.py @@ -59,13 +59,13 @@ def get_bonded_slaves(): return slaves -def sysfs_interface_up(interface): +def sysfs_interface_up(interface, unknown_up = False): try: with open("/sys/class/net/{}/operstate".format(interface)) as f: status = f.read().strip() except FileNotFoundError: raise RuntimeError("Unknown interface {iface}!".format(iface=interface)) - return status == "up" + return status == "up" or unknown_up and status == "unknown" class Network(IntervalModule): @@ -94,6 +94,7 @@ class Network(IntervalModule): "format_up", "color_up", "format_down", "color_down", ("detached_down", "If the interface doesn't exist, display it as if it were down"), + ("unknown_up", "If the interface is in unknown state, display it as if it were up"), "name", ) @@ -103,6 +104,7 @@ class Network(IntervalModule): color_up = "#00FF00" color_down = "#FF0000" detached_down = True + unknown_up = False def init(self): if self.interface not in netifaces.interfaces() and not self.detached_down: @@ -122,14 +124,14 @@ class Network(IntervalModule): except KeyError: pass else: - if sysfs_interface_up(self.interface): + if sysfs_interface_up(self.interface, self.unknown_up): master_info = netifaces.ifaddresses(master) for af in (netifaces.AF_INET, netifaces.AF_INET6): try: info[af] = master_info[af] except KeyError: pass - up = sysfs_interface_up(self.interface) + up = sysfs_interface_up(self.interface, self.unknown_up) fdict = dict( zip_longest(["v4", "v4mask", "v4cidr", "v6", "v6mask", "v6cidr"], [], fillvalue=""))