From: Alexander Popov Date: Sun, 6 Oct 2024 17:42:32 +0000 (+0300) Subject: Drop some duplicated code (thanks to the coverage report) X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=eaa45bbd0965defe0c5426611bf5fa5add1f3311;p=kconfig-hardened-check.git Drop some duplicated code (thanks to the coverage report) --- 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}"')