Added fallback java 8 version if not specified

This commit is contained in:
Michael Chen 2022-11-15 09:15:48 +01:00
parent 334f1f3e56
commit 8aa106d5bc
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import hashlib import hashlib
from typing import Any, Literal, TypedDict from typing import Any, Literal, NotRequired, TypedDict
from pathlib import Path from pathlib import Path
import urllib.request import urllib.request
import json import json
@ -52,7 +52,7 @@ class VersionManifestFull(TypedDict):
time: str time: str
releaseTime: str releaseTime: str
minimumLauncherVersion: int minimumLauncherVersion: int
javaVersion: JavaVersion javaVersion: NotRequired[JavaVersion]
downloads: VersionDownloads downloads: VersionDownloads
@ -147,13 +147,18 @@ def docker_buildx(repository: str, tags: list[str], build_platforms: list[Docker
subprocess.run(command) subprocess.run(command)
default_java_version: JavaVersion = {
"component": "jre",
"majorVersion": 8
}
def build_version(manifest: VersionManifest, version_id: str, repository: str = "hub.cnml.de/minecraft"): def build_version(manifest: VersionManifest, version_id: str, repository: str = "hub.cnml.de/minecraft"):
matching_version = list( matching_version = list(
filter(lambda v: v["id"] == version_id, manifest["versions"])) filter(lambda v: v["id"] == version_id, manifest["versions"]))
if len(matching_version) == 0: if len(matching_version) == 0:
raise Exception(f"Version {version_id} not found in manifest!") raise Exception(f"Version {version_id} not found in manifest!")
version = load_version_manifest(matching_version[0]) version = load_version_manifest(matching_version[0])
java_version = version['javaVersion'] java_version = version.get("javaVersion", default_java_version)
print( print(
f"Version [{version['type']}] {version['id']} requires java version {java_version['majorVersion']} ({java_version['component']})") f"Version [{version['type']}] {version['id']} requires java version {java_version['majorVersion']} ({java_version['component']})")
server_jar_file = Path("versions") / version['id'] / "server.jar" server_jar_file = Path("versions") / version['id'] / "server.jar"
@ -202,6 +207,8 @@ if __name__ == "__main__":
try: try:
build_version(manifest, version_id) build_version(manifest, version_id)
except Exception as e: except Exception as e:
print(f"Failed building images for version {version_id}:\n\t{e}") print(f"Failed building images for version {version_id}")
if not args.force: if args.force:
break print(e)
else:
raise