BIOSUtilities v24.10.18

Removed all Python built-in library keyword arguments (#55)
This commit is contained in:
Plato Mavropoulos 2024-10-18 13:37:52 +03:00
parent 010b5a47d4
commit 35455f735c
27 changed files with 228 additions and 229 deletions

View file

@ -8,10 +8,9 @@ Copyright (C) 2018-2024 Plato Mavropoulos
"""
import os
import stat
from biosutilities.common.compression import szip_decompress
from biosutilities.common.paths import extract_folder, is_file, make_dirs, safe_name
from biosutilities.common.paths import clear_readonly, extract_folder, is_file, make_dirs, safe_name
from biosutilities.common.patterns import PAT_AWARD_LZH
from biosutilities.common.system import printer
from biosutilities.common.templates import BIOSUtility
@ -28,7 +27,7 @@ class AwardBiosExtract(BIOSUtility):
in_buffer: bytes = file_to_bytes(in_object=input_object)
return bool(PAT_AWARD_LZH.search(string=in_buffer))
return bool(PAT_AWARD_LZH.search(in_buffer))
def parse_format(self, input_object: str | bytes | bytearray, extract_path: str, padding: int = 0) -> bool:
""" Parse & Extract Award BIOS image """
@ -37,8 +36,8 @@ class AwardBiosExtract(BIOSUtility):
make_dirs(in_path=extract_path, delete=True)
for lzh_match in PAT_AWARD_LZH.finditer(string=input_buffer):
lzh_type: str = lzh_match.group(0).decode(encoding='utf-8')
for lzh_match in PAT_AWARD_LZH.finditer(input_buffer):
lzh_type: str = lzh_match.group(0).decode('utf-8')
lzh_text: str = f'LZH-{lzh_type.strip("-").upper()}'
@ -46,7 +45,7 @@ class AwardBiosExtract(BIOSUtility):
mod_bgn: int = lzh_bgn - 0x2
hdr_len: int = input_buffer[mod_bgn]
mod_len: int = int.from_bytes(bytes=input_buffer[mod_bgn + 0x7:mod_bgn + 0xB], byteorder='little')
mod_len: int = int.from_bytes(input_buffer[mod_bgn + 0x7:mod_bgn + 0xB], byteorder='little')
mod_end: int = lzh_bgn + hdr_len + mod_len
mod_bin: bytes = input_buffer[mod_bgn:mod_end]
@ -58,8 +57,7 @@ class AwardBiosExtract(BIOSUtility):
continue
if len(mod_bin) >= 0x16:
tag_txt: str = safe_name(in_name=mod_bin[0x16:0x16 + mod_bin[0x15]].decode(
encoding='utf-8', errors='ignore').strip())
tag_txt: str = safe_name(in_name=mod_bin[0x16:0x16 + mod_bin[0x15]].decode('utf-8', 'ignore').strip())
else:
tag_txt = f'{mod_bgn:X}_{mod_end:X}'
@ -69,7 +67,7 @@ class AwardBiosExtract(BIOSUtility):
lzh_path: str = f'{mod_path}.lzh'
with open(file=lzh_path, mode='wb') as lzh_file:
with open(lzh_path, 'wb') as lzh_file:
lzh_file.write(mod_bin) # Store LZH archive
# 7-Zip returns critical exit code (i.e. 2) if LZH CRC is wrong, do not check result
@ -78,9 +76,9 @@ class AwardBiosExtract(BIOSUtility):
# Manually check if 7-Zip extracted LZH due to its CRC check issue
if is_file(in_path=mod_path):
os.chmod(path=lzh_path, mode=stat.S_IWRITE)
clear_readonly(in_path=lzh_path)
os.remove(path=lzh_path) # Successful extraction, delete LZH archive
os.remove(lzh_path) # Successful extraction, delete LZH archive
# Extract any nested LZH archives
if self.check_format(input_object=mod_path):