build.py: Consolidate plist clean up into single loop

This commit is contained in:
Mykola Grymalyuk
2022-07-07 14:24:07 -06:00
parent 15e3ea06f0
commit a7cb63530e
+15 -24
View File
@@ -1351,28 +1351,19 @@ class BuildOpenCore:
def cleanup(self): def cleanup(self):
print("- Cleaning up files") print("- Cleaning up files")
# Remove unused entries # Remove unused entries
# TODO: Consolidate into a single for loop entries_to_clean = {
for entry in list(self.config["ACPI"]["Add"]): "ACPI": ["Add", "Delete", "Patch"],
if not entry["Enabled"]: "Booter": ["Patch"],
self.config["ACPI"]["Add"].remove(entry) "Kernel": ["Add", "Block", "Force", "Patch"],
for entry in list(self.config["ACPI"]["Patch"]): "Misc": ["Tools"],
if not entry["Enabled"]: "UEFI": ["Drivers"],
self.config["ACPI"]["Patch"].remove(entry) }
for entry in list(self.config["Booter"]["Patch"]):
if not entry["Enabled"]: for entry in entries_to_clean:
self.config["Booter"]["Patch"].remove(entry) for sub_entry in entries_to_clean[entry]:
for entry in list(self.config["Kernel"]["Add"]): for item in list(self.config[entry][sub_entry]):
if not entry["Enabled"]: if item["Enabled"] is False:
self.config["Kernel"]["Add"].remove(entry) self.config[entry][sub_entry].remove(item)
for entry in list(self.config["Kernel"]["Patch"]):
if not entry["Enabled"]:
self.config["Kernel"]["Patch"].remove(entry)
for entry in list(self.config["Misc"]["Tools"]):
if not entry["Enabled"]:
self.config["Misc"]["Tools"].remove(entry)
for entry in list(self.config["UEFI"]["Drivers"]):
if not entry["Enabled"]:
self.config["UEFI"]["Drivers"].remove(entry)
plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True) plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True)
for kext in self.constants.kexts_path.rglob("*.zip"): for kext in self.constants.kexts_path.rglob("*.zip"):
@@ -1409,7 +1400,7 @@ class BuildOpenCore:
if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")): if not Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")):
print("- OpenCore config file missing!!!") print("- OpenCore config file missing!!!")
raise Exception("OpenCore config file missing") raise Exception("OpenCore config file missing")
config_plist = plistlib.load(Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")).open("rb")) config_plist = plistlib.load(Path(self.constants.opencore_release_folder / Path("EFI/OC/config.plist")).open("rb"))
for acpi in config_plist["ACPI"]["Add"]: for acpi in config_plist["ACPI"]["Add"]:
@@ -1432,7 +1423,7 @@ class BuildOpenCore:
if not kext_plist_path.exists(): if not kext_plist_path.exists():
print(f"- Missing {kext['BundlePath']}'s plist: {kext_plist_path}") print(f"- Missing {kext['BundlePath']}'s plist: {kext_plist_path}")
raise Exception(f"Missing {kext_plist_path}") raise Exception(f"Missing {kext_plist_path}")
for tool in config_plist["Misc"]["Tools"]: for tool in config_plist["Misc"]["Tools"]:
# print(f" - Validating {tool['Path']}") # print(f" - Validating {tool['Path']}")
if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools") / Path(tool["Path"])).exists(): if not Path(self.constants.opencore_release_folder / Path("EFI/OC/Tools") / Path(tool["Path"])).exists():