From: Alexander Popov Date: Sun, 2 Jun 2024 16:38:10 +0000 (+0300) Subject: Merge branch 'master' into open-check X-Git-Tag: v0.6.10~59^2~4 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=35fb52c57d444f55e3ce59771bfb61009479c33c;p=kconfig-hardened-check.git Merge branch 'master' into open-check --- 35fb52c57d444f55e3ce59771bfb61009479c33c diff --cc kernel_hardening_checker/__init__.py index 286f420,91742c3..614084e --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@@ -13,28 -13,26 +13,29 @@@ This module performs input/output import gzip import sys from argparse import ArgumentParser - from collections import OrderedDict + from typing import List, Tuple, Dict, TextIO import re import json - from .__about__ import __version__ from .checks import add_kconfig_checks, add_cmdline_checks, normalize_cmdline_options, add_sysctl_checks - from .engine import populate_with_data, perform_checks, override_expected_value + from .engine import StrOrNone, TupleOrNone, ChecklistObjType + from .engine import print_unknown_options, populate_with_data, perform_checks, override_expected_value - def _open(file: str, *args, **kwargs): - open_method = open - if file.endswith('.gz'): - open_method = gzip.open + # kernel-hardening-checker version + __version__ = '0.6.6' + + def _open(file: str) -> TextIO: - if file.endswith('.gz'): - return gzip.open(file, 'rt', encoding='utf-8') - return open(file, 'rt', encoding='utf-8') + try: - return open_method(file, *args, **kwargs) ++ if file.endswith('.gz'): ++ return gzip.open(file, 'rt', encoding='utf-8') ++ return open(file, 'rt', encoding='utf-8') + except FileNotFoundError: + sys.exit(f'[!] ERROR: unable to open {file}, are you sure it exists?') - - def detect_arch(fname, archs): - with _open(fname, 'rt', encoding='utf-8') as f: + def detect_arch(fname: str, archs: List[str]) -> Tuple[StrOrNone, str]: + with _open(fname) as f: arch_pattern = re.compile(r"CONFIG_[a-zA-Z0-9_]+=y$") arch = None for line in f.readlines():