From eaa45bbd0965defe0c5426611bf5fa5add1f3311 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 6 Oct 2024 20:42:32 +0300 Subject: [PATCH] Drop some duplicated code (thanks to the coverage report) --- kernel_hardening_checker/__init__.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 13094b2..694ffcb 100755 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -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}"') -- 2.31.1