From d0ee1b06e4394e1f139226ee2b76b286bd7df1ec Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Mon, 30 Nov 2020 17:21:17 +0100 Subject: [PATCH] [modules/nic] make exclude list regular expression capable Allow the usage of regexps in the exclude list, but keep the "this is a prefix" logic for backwards compatibility. should address (see #738) --- bumblebee_status/modules/core/nic.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bumblebee_status/modules/core/nic.py b/bumblebee_status/modules/core/nic.py index 41607d9..667cffa 100644 --- a/bumblebee_status/modules/core/nic.py +++ b/bumblebee_status/modules/core/nic.py @@ -10,7 +10,7 @@ Requires the following executable: * (until and including 2.0.5: iwgetid) Parameters: - * nic.exclude: Comma-separated list of interface prefixes to exclude (defaults to 'lo,virbr,docker,vboxnet,veth,br') + * nic.exclude: Comma-separated list of interface prefixes (supporting regular expressions) to exclude (defaults to 'lo,virbr,docker,vboxnet,veth,br,.*:avahi') * nic.include: Comma-separated list of interfaces to include * nic.states: Comma-separated list of states to show (prefix with '^' to invert - i.e. ^down -> show all devices that are not in state down) * nic.format: Format string (defaults to '{intf} {state} {ip} {ssid}') @@ -32,13 +32,10 @@ class Module(core.module.Module): def __init__(self, config, theme): widgets = [] super().__init__(config, theme, widgets) - self._exclude = tuple( - filter( - len, - self.parameter("exclude", "lo,virbr,docker,vboxnet,veth,br").split(","), - ) + self._exclude = util.format.aslist( + self.parameter("exclude", "lo,virbr,docker,vboxnet,veth,br,.*:avahi") ) - self._include = self.parameter("include", "").split(",") + self._include = util.format.aslist(self.parameter("include", "")) self._states = {"include": [], "exclude": []} for state in tuple( @@ -90,11 +87,18 @@ class Module(core.module.Module): return [] return retval + def _excluded(self, intf): + for e in self._exclude: + if re.match(e, intf): + return True + return False + def _update_widgets(self, widgets): self.clear_widgets() - interfaces = [ - i for i in netifaces.interfaces() if not i.startswith(self._exclude) - ] + interfaces = [] + for i in netifaces.interfaces(): + if not self._excluded(i): + interfaces.append(i) interfaces.extend([i for i in netifaces.interfaces() if i in self._include]) for intf in interfaces: