From fbe854cb9a717d1c4155f0ac66b3bcd908a9bda5 Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Fri, 1 Mar 2024 13:38:47 +0100 Subject: [PATCH] refactor: remove the blacklist file loop. Signed-off-by: NikOverflow --- src/main.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 7ad8601..30422a6 100644 --- a/src/main.py +++ b/src/main.py @@ -36,10 +36,9 @@ def is_running(): global process_blacklist if process_blacklist is not None: for process in psutil.process_iter(): - for name in process_blacklist: - if process.name() == name.strip(): - print(f"Blacklisted process '{name.strip()}' detected!") - return True + if process.name() in process_blacklist: + print(f"Blacklisted process '{process.name()}' detected!") + return True return False argument_parser = argparse.ArgumentParser() @@ -51,7 +50,7 @@ def is_running(): else: try: process_blacklist_file = open(arguments.blacklist, "r") - process_blacklist = set(process_blacklist_file.readlines()) + process_blacklist = set(line.strip() for line in process_blacklist_file.readlines()) print(f"Blacklist '{arguments.blacklist}' loaded.") except Exception: print(f"File '{arguments.blacklist}' not found or no permission!")