Fix usbguard-notify.py

This commit is contained in:
2026-02-27 23:38:39 -08:00
parent 304be63652
commit 5c35e4dfdc

View File

@ -11,10 +11,7 @@ DUNSTIFY_EXEC_NAME = shutil.which("dunstify")
open_notifications = {}
def parse_event_type_and_id(stream):
line = stream.readline()
if not line:
return None, True
def parse_event_type_and_id(line):
if not line.startswith("[device] "):
return None, False
event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line)
@ -107,12 +104,8 @@ with Popen(
first_line = (
usbguard_proc.stdout.readline()
) # get rid of initial connection message
if not first_line:
sys.exit()
while True:
event_type_result, eof = parse_event_type_and_id(usbguard_proc.stdout)
if eof:
sys.exit()
for line in usbguard_proc.stdout:
event_type_result = parse_event_type_and_id(line)
if event_type_result is None:
continue
event_type, dev_id = event_type_result