1
0
mirror of https://github.com/Mauler125/r5sdk.git synced 2025-02-09 19:15:03 +01:00

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)
This commit is contained in:
Kawe Mazidjatari 2023-08-03 16:43:22 +02:00
parent b8744a9ab8
commit 010c0d0c20

@ -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 <versionNum> <depotName>")
if len(sys.argv) != 2:
print(f"Usage: bld_man.py <version>")
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)