From: Alexander Popov Date: Mon, 13 May 2024 11:57:26 +0000 (+0300) Subject: Move print_unknown_options() to engine.py X-Git-Tag: v0.6.10~67^2~14 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=5a977616f26cdaa334a71bc56265e117b9036a05;p=kconfig-hardened-check.git Move print_unknown_options() to engine.py That is better for specifying typing. --- diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index c466b36..3a30aef 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -19,7 +19,7 @@ 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 StrOrNone, TupleOrNone, populate_with_data, perform_checks, override_expected_value +from .engine import StrOrNone, TupleOrNone, print_unknown_options, populate_with_data, perform_checks, override_expected_value def _open(file: str, *args, **kwargs) -> TextIO: @@ -80,29 +80,6 @@ def detect_compiler(fname: str) -> Tuple[StrOrNone, str]: sys.exit(f'[!] ERROR: invalid GCC_VERSION and CLANG_VERSION: {gcc_version} {clang_version}') -def print_unknown_options(checklist: List, parsed_options: OrderedDict[str, str], opt_type: str) -> None: - known_options = [] - - for o1 in checklist: - if o1.opt_type != 'complex': - known_options.append(o1.name) - continue - for o2 in o1.opts: - if o2.opt_type != 'complex': - if hasattr(o2, 'name'): - known_options.append(o2.name) - continue - for o3 in o2.opts: - assert(o3.opt_type != 'complex'), \ - f'unexpected ComplexOptCheck inside {o2.name}' - if hasattr(o3, 'name'): - known_options.append(o3.name) - - for option, value in parsed_options.items(): - if option not in known_options: - print(f'[?] No check for {opt_type} option {option} ({value})') - - def print_checklist(mode: StrOrNone, checklist: List, with_results: bool) -> None: if mode == 'json': output = [] diff --git a/kernel_hardening_checker/engine.py b/kernel_hardening_checker/engine.py index f6282fe..9275fd2 100644 --- a/kernel_hardening_checker/engine.py +++ b/kernel_hardening_checker/engine.py @@ -13,7 +13,7 @@ This module is the engine of checks. import sys -from typing import Optional, Dict, Tuple +from typing import Optional, OrderedDict, Dict, List, Tuple StrOrNone = Optional[str] TupleOrNone = Optional[Tuple] @@ -353,3 +353,26 @@ def override_expected_value(checklist, name, new_val): def perform_checks(checklist): for opt in checklist: opt.check() + + +def print_unknown_options(checklist: List, parsed_options: OrderedDict[str, str], opt_type: str) -> None: + known_options = [] + + for o1 in checklist: + if o1.opt_type != 'complex': + known_options.append(o1.name) + continue + for o2 in o1.opts: + if o2.opt_type != 'complex': + if hasattr(o2, 'name'): + known_options.append(o2.name) + continue + for o3 in o2.opts: + assert(o3.opt_type != 'complex'), \ + f'unexpected ComplexOptCheck inside {o2.name}' + if hasattr(o3, 'name'): + known_options.append(o3.name) + + for option, value in parsed_options.items(): + if option not in known_options: + print(f'[?] No check for {opt_type} option {option} ({value})')