From 010c0d0c209efe0eeca2e59f033ceffea23c74ea Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:43:22 +0200 Subject: [PATCH] Improve manifest script - Add configuration support for each depot - Add configurable vendor for each depot - Add size field for each depot (used for installer's progress callback) - Compute depot package checksum on the spot - Take manifest version input as string instead (used as tags) --- r5dev/resource/script/bld_man.py | 106 ++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 24 deletions(-) diff --git a/r5dev/resource/script/bld_man.py b/r5dev/resource/script/bld_man.py index 4b4de6f9..9a5cabf5 100644 --- a/r5dev/resource/script/bld_man.py +++ b/r5dev/resource/script/bld_man.py @@ -8,16 +8,20 @@ import hashlib # Compute the SHA-256 checksum of a file #------------------------------------------------------------------------------ def ComputeChecksum(filePath, blockSize=65536): - checksum = hashlib.sha256() + sha256 = hashlib.sha256() with open(filePath, "rb") as file: for block in iter(lambda: file.read(blockSize), b""): - checksum.update(block) - return checksum.hexdigest() + sha256.update(block) + + checksum = sha256.hexdigest() + print(f"*** computed checksum for '{filePath}': {checksum}") + + return checksum #------------------------------------------------------------------------------ # Compute checksums for all files in a directory #------------------------------------------------------------------------------ -def RecursiveComputeChecksum(directoryPath): +def RecursiveComputeChecksum(directoryPath, settings): checksums = {} scriptPath = os.path.abspath(__file__) @@ -32,42 +36,96 @@ def RecursiveComputeChecksum(directoryPath): continue checksum = ComputeChecksum(filePath) - checksums[normalizedPath] = checksum + checksums[normalizedPath] = { + "checksum": checksum, + "restart": False + } + + # Check if the file should be updated/installed during a restart + if settings and "restart" in settings: + restart_files = settings["restart"] + for file in restart_files: + if file in checksums: + checksums[file]["restart"] = True return checksums + +#------------------------------------------------------------------------------ +# Gets the settings for this depot +#------------------------------------------------------------------------------ +def GetDepotSettings(depotName): + settingsPath = os.path.join('devops', f'{depotName}.json') + print(f"{settingsPath}") + if not os.path.isfile(settingsPath): + settingsPath = os.path.join('devops', 'default.json') + if not os.path.isfile(settingsPath): + return None + + f = open(settingsPath) + if f.closed: + print(f"{settingsPath} = closed") + return None + + return json.load(f) + + #------------------------------------------------------------------------------ # Save the checksums to a manifest file #------------------------------------------------------------------------------ -def CreateManifest(version, depot, checksums, outManifestFile): +def CreateManifest(version, currentDirectory, outManifestFile): + depotList = [name for name in os.listdir(currentDirectory) if os.path.isdir(os.path.join(currentDirectory, name))] + manifest = { "version": version, - "depots": { - depot: { - "checksum": 0, - "optional": False, - "assets": checksums - } - } + "depot": {} } + + i = 0 + for depot in depotList: + fileName = f"{depot}.zip" + + # Each depot must have a release package !!! + zipFilePath = os.path.join(currentDirectory, 'release', fileName) + + print(f"{zipFilePath}") + if not os.path.isfile(zipFilePath): + continue + + # Each depot must have a configuration !!! + settings = GetDepotSettings(depot) + if not settings: + continue + + print(f"*** processing depot '{depot}'...") + + checksum = ComputeChecksum(zipFilePath) + size = os.path.getsize(zipFilePath) + + depotData = { + "name": fileName, + "size": size, + "checksum": checksum, + "optional": False, + "vendor": settings["vendor"], + "assets": RecursiveComputeChecksum(os.path.join(currentDirectory, depot), settings) + } + + manifest["depot"][i] = depotData + i+=1 + with open(outManifestFile, "w") as jsonFile: json.dump(manifest, jsonFile, indent=4) #------------------------------------------------------------------------------ if __name__ == "__main__": - if len(sys.argv) != 3: - print("Usage: bld_man.py ") + if len(sys.argv) != 2: + print(f"Usage: bld_man.py ") sys.exit(1) - try: - version = int(sys.argv[1]) - depot = sys.argv[2] - except ValueError: - print("Version must be an integer") - sys.exit(1) + version = sys.argv[1] - workingDirectory = os.getcwd() + currentDirectory = os.path.dirname(os.path.abspath(__file__)) outManifestFile = "manifest_patch.json" - checksums = RecursiveComputeChecksum(workingDirectory) - CreateManifest(version, depot, checksums, outManifestFile) + CreateManifest(version, currentDirectory, outManifestFile)