[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)
This commit is contained in:
parent
a8b28cd0bf
commit
d0ee1b06e4
1 changed files with 14 additions and 10 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue