Compare commits

...

2 Commits

Author SHA1 Message Date
Zander671 4d5ebe465e Merge branch 'main' of git.zander.im:Zander671/random-scripts 2026-02-27 23:39:08 -08:00
Zander671 5c35e4dfdc Fix usbguard-notify.py 2026-02-27 23:38:53 -08:00
+3 -10
View File
@@ -11,10 +11,7 @@ DUNSTIFY_EXEC_NAME = shutil.which("dunstify")
open_notifications = {} open_notifications = {}
def parse_event_type_and_id(stream): def parse_event_type_and_id(line):
line = stream.readline()
if not line:
return None, True
if not line.startswith("[device] "): if not line.startswith("[device] "):
return None, False return None, False
event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line) event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line)
@@ -107,12 +104,8 @@ with Popen(
first_line = ( first_line = (
usbguard_proc.stdout.readline() usbguard_proc.stdout.readline()
) # get rid of initial connection message ) # get rid of initial connection message
if not first_line: for line in usbguard_proc.stdout:
sys.exit() event_type_result = parse_event_type_and_id(line)
while True:
event_type_result, eof = parse_event_type_and_id(usbguard_proc.stdout)
if eof:
sys.exit()
if event_type_result is None: if event_type_result is None:
continue continue
event_type, dev_id = event_type_result event_type, dev_id = event_type_result