diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-02-20 13:59:04 -0800 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-02-20 13:59:04 -0800 |
commit | a25f5b90664f635afafd50ed2700f04783ee9c4a (patch) | |
tree | 69dfde124f903f7da77ae996a03338d95f51ac57 /panel.py | |
parent | d8fb197876f30f8f539a9d8f0b7f0c0a77ec2752 (diff) | |
download | panel-a25f5b90664f635afafd50ed2700f04783ee9c4a.tar.gz panel-a25f5b90664f635afafd50ed2700f04783ee9c4a.tar.xz |
support matching multiple network interfaces via regex
Diffstat (limited to 'panel.py')
-rwxr-xr-x | panel.py | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -5,6 +5,7 @@ import os import psutil import queue +import re import subprocess import threading import time @@ -341,14 +342,19 @@ class ModInterval(Mod): self.timer.run() class ModNetIf(ModInterval): - def __init__(self, ifname, label=None, **kwargs): + def __init__(self, ifname, label=None, regex=False, **kwargs): super().__init__(**kwargs) self.ifname = ifname + self.regex = regex self.label = label or ifname def refresh(self): - stats = psutil.net_if_stats().get(self.ifname) - state = 'up' if stats and stats.isup else 'down' + stats = psutil.net_if_stats() + if self.regex: + arr = [v for k, v in stats.items() if re.fullmatch(self.ifname, k)] + else: + arr = [x] if (x := stats.get(self.ifname)) else [] + state = 'up' if any(x.isup for x in arr) else 'down' self.out = Fmt.labelled(self.label, state) class ModCPU(ModInterval): @@ -410,7 +416,7 @@ Panel( ModInputAvail( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', unavail_text='NO KEYBOARD'), - ModNetIf('wg0', interval=1), + ModNetIf('wg.*', regex=True, label='wg*', interval=1), ModCPU(interval=0.5), ModMem(interval=0.5), ModDate( |