From e83e260db7820bb06b17558580eef392fe21509a Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 9 Feb 2023 17:59:53 -0700 Subject: [PATCH] Fix Constants type suggestion --- resources/arguments.py | 5 +++-- resources/defaults.py | 4 ++-- resources/global_settings.py | 11 ++++++----- resources/kdk_handler.py | 7 +++---- resources/main.py | 2 +- resources/reroute_payloads.py | 4 ++-- resources/sys_patch/sys_patch.py | 15 ++++++++++++--- resources/sys_patch/sys_patch_auto.py | 4 ++-- resources/sys_patch/sys_patch_detect.py | 4 ++-- resources/sys_patch/sys_patch_helpers.py | 4 ++-- resources/updates.py | 4 ++-- resources/validation.py | 4 ++-- 12 files changed, 39 insertions(+), 29 deletions(-) diff --git a/resources/arguments.py b/resources/arguments.py index 8f7d0884d..a0eb71f88 100644 --- a/resources/arguments.py +++ b/resources/arguments.py @@ -11,8 +11,9 @@ from data import model_array # Generic building args class arguments: - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants self.args = utilities.check_cli_args() diff --git a/resources/defaults.py b/resources/defaults.py index d067d01fd..51dbb7dbc 100644 --- a/resources/defaults.py +++ b/resources/defaults.py @@ -17,8 +17,8 @@ from data import ( class GenerateDefaults: - def __init__(self, model: str, host_is_target: bool, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, model: str, host_is_target: bool, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants self.model = model self.host_is_target = host_is_target diff --git a/resources/global_settings.py b/resources/global_settings.py index 36d56b5e9..60b4925db 100644 --- a/resources/global_settings.py +++ b/resources/global_settings.py @@ -12,15 +12,16 @@ import subprocess class global_settings: def __init__(self): - self.file_name = ".com.dortania.opencore-legacy-patcher.plist" - self.global_settings_folder = "/Users/Shared" - self.global_settings_plist = f"{self.global_settings_folder}/{self.file_name}" + self.file_name: str = ".com.dortania.opencore-legacy-patcher.plist" + self.global_settings_folder: str = "/Users/Shared" + self.global_settings_plist: str = f"{self.global_settings_folder}/{self.file_name}" + self._generate_settings_file() self._convert_defaults_to_global_settings() self._fix_file_permission() - def read_property(self, property_name): + def read_property(self, property_name: str): """ Reads a property from the global settings file """ @@ -32,7 +33,7 @@ class global_settings: return None - def write_property(self, property_name, property_value): + def write_property(self, property_name: str, property_value): """ Writes a property to the global settings file """ diff --git a/resources/kdk_handler.py b/resources/kdk_handler.py index bfd1be59c..7d9df9bee 100644 --- a/resources/kdk_handler.py +++ b/resources/kdk_handler.py @@ -15,8 +15,7 @@ import os import logging -from resources import utilities, network_handler -from resources.constants import Constants +from resources import utilities, network_handler, constants from data import os_data KDK_INSTALL_PATH: str = "/Library/Developer/KDKs" @@ -50,8 +49,8 @@ class KernelDebugKitObject: """ - def __init__(self, constants: Constants, host_build: str, host_version: str, ignore_installed: bool = False, passive: bool = False): - self.constants: Constants = constants + def __init__(self, global_constants: constants.Constants, host_build: str, host_version: str, ignore_installed: bool = False, passive: bool = False): + self.constants: constants.Constants = global_constants self.host_build: str = host_build # ex. 20A5384c self.host_version: str = host_version # ex. 11.0.1 diff --git a/resources/main.py b/resources/main.py index 0435561b9..f52dada98 100644 --- a/resources/main.py +++ b/resources/main.py @@ -28,7 +28,7 @@ class OpenCoreLegacyPatcher: def __init__(self): logging_handler.InitializeLoggingSupport() - self.constants: constants = constants.Constants() + self.constants: constants.Constants = constants.Constants() self.constants.wxpython_variant: bool = True diff --git a/resources/reroute_payloads.py b/resources/reroute_payloads.py index f6f35a8de..6f3624ec5 100644 --- a/resources/reroute_payloads.py +++ b/resources/reroute_payloads.py @@ -13,8 +13,8 @@ from resources import constants class RoutePayloadDiskImage: - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants self._setup_tmp_disk_image() diff --git a/resources/sys_patch/sys_patch.py b/resources/sys_patch/sys_patch.py index 7f80bbc2a..82e2e70b8 100644 --- a/resources/sys_patch/sys_patch.py +++ b/resources/sys_patch/sys_patch.py @@ -46,9 +46,9 @@ from data import os_data class PatchSysVolume: - def __init__(self, model, versions, hardware_details=None): + def __init__(self, model: str, global_constants: constants.Constants, hardware_details: list = None): self.model = model - self.constants: constants.Constants() = versions + self.constants: constants.Constants = global_constants self.computer = self.constants.computer self.root_mount_path = None self.root_supports_snapshot = utilities.check_if_root_is_apfs_snapshot() @@ -72,7 +72,15 @@ class PatchSysVolume: if Path(self.constants.payload_local_binaries_root_path).exists(): shutil.rmtree(self.constants.payload_local_binaries_root_path) - def _init_pathing(self, custom_root_mount_path=None, custom_data_mount_path=None): + def _init_pathing(self, custom_root_mount_path: Path = None, custom_data_mount_path: Path = None): + """ + Initializes the pathing for root volume patching + + Parameters: + custom_root_mount_path (Path): Custom path to mount the root volume + custom_data_mount_path (Path): Custom path to mount the data volume + + """ if custom_root_mount_path and custom_data_mount_path: self.mount_location = custom_root_mount_path self.data_mount_location = custom_data_mount_path @@ -83,6 +91,7 @@ class PatchSysVolume: else: self.mount_location = "" self.mount_location_data = "" + self.mount_extensions = f"{self.mount_location}/System/Library/Extensions" self.mount_application_support = f"{self.mount_location_data}/Library/Application Support" diff --git a/resources/sys_patch/sys_patch_auto.py b/resources/sys_patch/sys_patch_auto.py index 391953d6b..52ddfcd10 100644 --- a/resources/sys_patch/sys_patch_auto.py +++ b/resources/sys_patch/sys_patch_auto.py @@ -19,8 +19,8 @@ from resources.gui import gui_main class AutomaticSysPatch: - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants def start_auto_patch(self): diff --git a/resources/sys_patch/sys_patch_detect.py b/resources/sys_patch/sys_patch_detect.py index 221fa69da..0619bb8d3 100644 --- a/resources/sys_patch/sys_patch_detect.py +++ b/resources/sys_patch/sys_patch_detect.py @@ -27,9 +27,9 @@ from data import ( class detect_root_patch: - def __init__(self, model: str, versions: constants.Constants()): + def __init__(self, model: str, global_constants: constants.Constants): self.model = model - self.constants: constants.Constants() = versions + self.constants: constants.Constants = global_constants self.computer = self.constants.computer # GPU Patch Detection diff --git a/resources/sys_patch/sys_patch_helpers.py b/resources/sys_patch/sys_patch_helpers.py index f18b0e2ee..a256d54a4 100644 --- a/resources/sys_patch/sys_patch_helpers.py +++ b/resources/sys_patch/sys_patch_helpers.py @@ -14,8 +14,8 @@ from resources import bplist, constants, generate_smbios, utilities class sys_patch_helpers: - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants def snb_board_id_patch(self, source_files_path): diff --git a/resources/updates.py b/resources/updates.py index 300d23521..8ab1fb1c3 100644 --- a/resources/updates.py +++ b/resources/updates.py @@ -11,8 +11,8 @@ REPO_LATEST_RELEASE_URL: str = "https://api.github.com/repos/dortania/OpenCore-L class check_binary_updates: - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants self.binary_version = self.constants.patcher_version self.binary_version_array = [int(x) for x in self.binary_version.split(".")] diff --git a/resources/validation.py b/resources/validation.py index ad55c36c5..a2e8320a3 100644 --- a/resources/validation.py +++ b/resources/validation.py @@ -15,8 +15,8 @@ class PatcherValidation: Primarily for Continuous Integration """ - def __init__(self, global_constants: constants.Constants()): - self.constants: constants.Constants() = global_constants + def __init__(self, global_constants: constants.Constants): + self.constants: constants.Constants = global_constants self.constants.validate = True