Merge branch 'master' into open-check
authorAlexander Popov <alex.popov@linux.com>
Sun, 2 Jun 2024 16:38:10 +0000 (19:38 +0300)
committerAlexander Popov <alex.popov@linux.com>
Sun, 2 Jun 2024 16:38:10 +0000 (19:38 +0300)
1  2 
kernel_hardening_checker/__init__.py

index 286f420ea5c016f72529647e44896223f65695de,91742c3923d78973a2d865b05adee609851c4568..614084e4e3a7ac7af704e76f4b7b2c6fd01ca4a5
@@@ -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'
  
 -    if file.endswith('.gz'):
 -        return gzip.open(file, 'rt', encoding='utf-8')
 -    return open(file, 'rt', encoding='utf-8')
+ def _open(file: str) -> TextIO:
-         return open_method(file, *args, **kwargs)
 +    try:
++        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():