Drop some duplicated code (thanks to the coverage report)
authorAlexander Popov <alex.popov@linux.com>
Sun, 6 Oct 2024 17:42:32 +0000 (20:42 +0300)
committerAlexander Popov <alex.popov@linux.com>
Sun, 6 Oct 2024 18:01:27 +0000 (21:01 +0300)
kernel_hardening_checker/__init__.py

index 13094b257ad276809a3d8b56971a9d05c4b71c6e..694ffcb9df6cef3c1308548e9725039abdf3a514 100755 (executable)
@@ -193,10 +193,7 @@ def parse_kconfig_file(_mode: StrOrNone, parsed_options: Dict[str, str], fname:
 
 
 def parse_cmdline_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: str) -> None:
-    if not os.path.isfile(fname):
-        sys.exit(f'[!] ERROR: unable to open {fname}, are you sure it exists?')
-
-    with open(fname, 'r', encoding='utf-8') as f:
+    with _open(fname) as f:
         line = f.readline()
         if not line:
             sys.exit(f'[!] ERROR: empty cmdline file "{fname}"')
@@ -221,10 +218,7 @@ def parse_cmdline_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: s
 
 
 def parse_sysctl_file(mode: StrOrNone, parsed_options: Dict[str, str], fname: str) -> None:
-    if not os.path.isfile(fname):
-        sys.exit(f'[!] ERROR: unable to open {fname}, are you sure it exists?')
-
-    with open(fname, 'r', encoding='utf-8') as f:
+    with _open(fname) as f:
         if os.stat(fname).st_size == 0:
             sys.exit(f'[!] ERROR: empty sysctl file "{fname}"')