BIOSUtilities v24.11.10

Re-written public attributes of Apple EFI ID
Improved memory consumption for all utilities
Adjusted README with consolidated requirements
This commit is contained in:
Plato Mavropoulos 2024-11-11 01:18:34 +02:00
parent 29dabc7401
commit 35564f31b7
19 changed files with 252 additions and 198 deletions

View file

@ -10,7 +10,7 @@ import subprocess
from typing import Final
from biosutilities.common.externals import szip_path, tiano_path
from biosutilities.common.paths import is_access, is_dir, is_file, is_empty_dir, path_size
from biosutilities.common.paths import is_dir, is_file_read, is_empty_dir, path_size
from biosutilities.common.system import printer
from biosutilities.common.texts import file_to_bytes
@ -118,7 +118,7 @@ def efi_decompress(in_path: str, out_path: str, padding: int = 0, silent: bool =
tiano_x: subprocess.CompletedProcess[bytes] = subprocess.run(tiano_c, check=False, stdout=subprocess.DEVNULL)
if tiano_x.returncode == 0 and is_file(in_path=out_path) and is_access(in_path=out_path):
if tiano_x.returncode == 0 and is_file_read(in_path=out_path):
if efi_header_info(in_object=in_path)['size_decompressed'] == path_size(in_path=out_path):
if not silent:
printer(message='Successful EFI decompression via TianoCompress!', padding=padding)

View file

@ -16,7 +16,7 @@ from importlib.util import module_from_spec, spec_from_file_location
from types import ModuleType
from typing import Type
from biosutilities.common.paths import is_dir, is_file, project_root
from biosutilities.common.paths import is_dir, is_file_read, project_root
from biosutilities.common.texts import to_string
@ -30,10 +30,10 @@ def get_external_path(cmd: str | list | tuple) -> str:
for command in cmd if isinstance(cmd, (list, tuple)) else [to_string(in_object=cmd)]:
command_path: str | None = shutil.which(command, path=external_path)
if command_path and is_file(in_path=command_path):
if command_path and is_file_read(in_path=command_path):
return command_path
raise OSError(f'{to_string(in_object=cmd, sep_char=", ")} could not be found!')
raise OSError(f'{to_string(in_object=cmd, sep_char=", ")} requirement could not be found!')
def big_script_tool() -> Type | None:

View file

@ -237,6 +237,18 @@ def is_access(in_path: str, access_mode: int = os.R_OK, follow_links: bool = Fal
return os.access(in_path, access_mode, follow_symlinks=follow_links)
def is_file_read(in_path: str) -> bool:
""" Check if path is a readable file """
return isinstance(in_path, str) and is_file(in_path=in_path) and is_access(in_path=in_path)
def is_dir_read(in_path: str) -> bool:
""" Check if path is a readable directory """
return isinstance(in_path, str) and is_dir(in_path=in_path) and is_access(in_path=in_path)
def is_empty_dir(in_path: str, follow_links: bool = False) -> bool:
""" Check if directory is empty (file-wise) """

View file

@ -5,6 +5,7 @@
Copyright (C) 2022-2024 Plato Mavropoulos
"""
from biosutilities.common.paths import runtime_root
from biosutilities.common.texts import file_to_bytes
@ -13,12 +14,22 @@ class BIOSUtility:
TITLE: str = 'BIOS Utility'
def __init__(self, input_object: str | bytes | bytearray = b'', extract_path: str = '', padding: int = 0) -> None:
def __init__(self, input_object: str | bytes | bytearray = b'', extract_path: str = runtime_root(),
padding: int = 0) -> None:
self.input_object: str | bytes | bytearray = input_object
self.extract_path: str = extract_path
self.padding: int = padding
self.input_buffer: bytes = file_to_bytes(in_object=self.input_object)
self.__input_buffer: bytes = b''
@property
def input_buffer(self) -> bytes:
""" Get input object buffer """
if not self.__input_buffer:
self.__input_buffer = file_to_bytes(in_object=self.input_object)
return self.__input_buffer
def check_format(self) -> bool:
""" Check if input object is of specific supported format """