diff options
| -rwxr-xr-x | generateFabric.py | 4 | ||||
| -rwxr-xr-x | generateForge.py | 446 | ||||
| -rw-r--r-- | meta/common/__init__.py | 2 | ||||
| -rw-r--r-- | meta/common/fabric.py | 2 | ||||
| -rw-r--r-- | meta/model/fabric.py | 2 | ||||
| -rw-r--r-- | meta/model/forge.py | 160 | ||||
| -rw-r--r-- | meta/model/mojang.py | 2 | ||||
| -rwxr-xr-x | updateFabric.py | 4 | ||||
| -rwxr-xr-x | updateForge.py | 168 |
9 files changed, 384 insertions, 406 deletions
diff --git a/generateFabric.py b/generateFabric.py index fb1c133bf1..dc81036ec3 100755 --- a/generateFabric.py +++ b/generateFabric.py @@ -9,8 +9,8 @@ from meta.model.fabric import FabricJarInfo, FabricInstallerDataV1, FabricMainCl PMC_DIR = polymc_path() UPSTREAM_DIR = upstream_path() -ensure_component_dir("net.fabricmc.fabric-loader") -ensure_component_dir("net.fabricmc.intermediary") +ensure_component_dir(LOADER_COMPONENT) +ensure_component_dir(INTERMEDIARY_COMPONENT) def load_jar_info(artifact_key) -> FabricJarInfo: diff --git a/generateForge.py b/generateForge.py index 6327c112da..b7057597d5 100755 --- a/generateForge.py +++ b/generateForge.py @@ -2,6 +2,8 @@ import os import re import sys from distutils.version import LooseVersion +from operator import attrgetter +from typing import Collection from meta.common import ensure_component_dir, polymc_path, upstream_path, static_path from meta.common.forge import FORGE_COMPONENT, INSTALLER_MANIFEST_DIR, VERSION_MANIFEST_DIR, DERIVED_INDEX_FILE, \ @@ -10,7 +12,7 @@ from meta.common.mojang import MINECRAFT_COMPONENT from meta.model import MetaVersion, Dependency, Library, GradleSpecifier, MojangLibraryDownloads, MojangArtifact, \ MetaPackage from meta.model.forge import ForgeVersion, ForgeInstallerProfile, ForgeLegacyInfo, fml_libs_for_version, \ - ForgeInstallerProfileV2, InstallerInfo, DerivedForgeIndex, ForgeLegacyInfoList + ForgeInstallerProfileV2, InstallerInfo, DerivedForgeIndex, ForgeLegacyInfoList, ForgeLibrary from meta.model.mojang import MojangVersion PMC_DIR = polymc_path() @@ -25,18 +27,16 @@ def eprint(*args, **kwargs): # Contruct a set of libraries out of a Minecraft version file, for filtering. -mcVersionCache = {} +mc_version_cache = {} -def loadMcVersionFilter(version): - if version in mcVersionCache: - return mcVersionCache[version] - libSet = set() - mcVersion = MetaVersion.parse_file(os.path.join(PMC_DIR, MINECRAFT_COMPONENT, f"{version}.json")) - for lib in mcVersion.libraries: - libSet.add(lib.name) - mcVersionCache[version] = libSet - return libSet +def load_mc_version_filter(version: str): + if version in mc_version_cache: + return mc_version_cache[version] + v = MetaVersion.parse_file(os.path.join(PMC_DIR, MINECRAFT_COMPONENT, f"{version}.json")) + libs = set(map(attrgetter("name"), v.libraries)) + mc_version_cache[version] = libs + return libs ''' @@ -46,31 +46,32 @@ Match a library coordinate to a set of library coordinates. ''' -def shouldIgnoreArtifact(libSet, match): - for ver in libSet: +def should_ignore_artifact(libs: Collection[GradleSpecifier], match: GradleSpecifier): + for ver in libs: if ver.group == match.group and ver.artifact == match.artifact and ver.classifier == match.classifier: if ver.version == match.version: # Everything is matched perfectly - this one will be ignored return True + elif LooseVersion(ver.version) > LooseVersion(match.version): + # eprint ("Lower version on %s:%s:%s: OLD=%s NEW=%s" % (ver.group, ver.artifact, ver.classifier, ver.version, match.version)) + return True else: - # We say the lib matches (is the same) also when the new version is lower than the old one - if LooseVersion(ver.version) > LooseVersion(match.version): - # eprint ("Lower version on %s:%s:%s: OLD=%s NEW=%s" % (ver.group, ver.artifact, ver.classifier, ver.version, match.version)) - return True # Otherwise it did not match - new version is higher and this is an upgrade return False # No match found in the set - we need to keep this return False -def versionFromProfile(profile: ForgeInstallerProfile, version): - result = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) - mcversion = profile.install.minecraft - result.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mcversion)] - result.main_class = profile.versionInfo.main_class - args = profile.versionInfo.minecraft_arguments +def version_from_profile(profile: ForgeInstallerProfile, version: ForgeVersion) -> MetaVersion: + v = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) + mc_version = profile.install.minecraft + v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mc_version)] + v.main_class = profile.version_info.main_class + v.release_time = profile.version_info.time + + args = profile.version_info.minecraft_arguments tweakers = [] - expression = re.compile("--tweakClass ([a-zA-Z0-9\\.]+)") + expression = re.compile(r"--tweakClass ([a-zA-Z0-9.]+)") match = expression.search(args) while match is not None: tweakers.append(match.group(1)) @@ -78,48 +79,48 @@ def versionFromProfile(profile: ForgeInstallerProfile, version): match = expression.search(args) if len(tweakers) > 0: args = args.strip() - result.additional_tweakers = tweakers - # result.minecraftArguments = args - result.release_time = profile.versionInfo.time - libs = [] - mcFilter = loadMcVersionFilter(mcversion) - for forgeLib in profile.versionInfo.libraries: - if forgeLib.name.is_lwjgl(): - continue - if forgeLib.name.is_log4j(): - continue - if shouldIgnoreArtifact(mcFilter, forgeLib.name): + v.additional_tweakers = tweakers + # v.minecraftArguments = args + + v.libraries = [] + mc_filter = load_mc_version_filter(mc_version) + for forge_lib in profile.version_info.libraries: + if forge_lib.name.is_lwjgl() or forge_lib.name.is_log4j() or should_ignore_artifact(mc_filter, forge_lib.name): continue - fixedName = forgeLib.name - if fixedName.group == "net.minecraftforge": - if fixedName.artifact == "minecraftforge": - fixedName.artifact = "forge" - fixedName.classifier = "universal" - fixedName.version = "%s-%s" % (mcversion, fixedName.version) - elif fixedName.artifact == "forge": - fixedName.classifier = "universal" - ourLib = Library(name=fixedName) - if forgeLib.url == "http://files.minecraftforge.net/maven/": - ourLib.url = "https://maven.minecraftforge.net/" + + overridden_name = forge_lib.name + if overridden_name.group == "net.minecraftforge": + if overridden_name.artifact == "minecraftforge": + overridden_name.artifact = "forge" + overridden_name.version = "%s-%s" % (mc_version, overridden_name.version) + + overridden_name.classifier = "universal" + elif overridden_name.artifact == "forge": + overridden_name.classifier = "universal" + + overridden_lib = Library(name=overridden_name) + if forge_lib.url == "http://files.minecraftforge.net/maven/": + overridden_lib.url = "https://maven.minecraftforge.net/" else: - ourLib.url = forgeLib.url - # if forgeLib.checksums and len(forgeLib.checksums) == 2: - # ourLib.mmcHint = "forge-pack-xz" - libs.append(ourLib) - result.libraries = libs - result.order = 5 - return result - - -def versionFromModernizedInstaller(installerVersion: MojangVersion, version: ForgeVersion): - eprint("Generating Modernized Forge %s." % version.longVersion) - result = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) - mcversion = version.mcversion - result.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mcversion)] - result.main_class = installerVersion.main_class - args = installerVersion.minecraft_arguments + overridden_lib.url = forge_lib.url + # if forge_lib.checksums and len(forge_lib.checksums) == 2: + # overridden_lib.mmcHint = "forge-pack-xz" + v.libraries.append(overridden_lib) + + v.order = 5 + return v + + +def version_from_modernized_installer(installer: MojangVersion, version: ForgeVersion) -> MetaVersion: + v = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) + mc_version = version.mc_version + v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mc_version)] + v.main_class = installer.main_class + v.release_time = installer.release_time + + args = installer.minecraft_arguments tweakers = [] - expression = re.compile("--tweakClass ([a-zA-Z0-9\\.]+)") + expression = re.compile("--tweakClass ([a-zA-Z0-9.]+)") match = expression.search(args) while match is not None: tweakers.append(match.group(1)) @@ -127,146 +128,132 @@ def versionFromModernizedInstaller(installerVersion: MojangVersion, version: For match = expression.search(args) if len(tweakers) > 0: args = args.strip() - result.additional_tweakers = tweakers - # result.minecraftArguments = args - result.release_time = installerVersion.release_time - libs = [] - mcFilter = loadMcVersionFilter(mcversion) - for upstreamLib in installerVersion.libraries: - pmcLib = Library.parse_obj(upstreamLib.dict()) - if pmcLib.name.is_lwjgl(): - continue - if pmcLib.name.is_log4j(): - continue - if shouldIgnoreArtifact(mcFilter, pmcLib.name): + v.additional_tweakers = tweakers + # v.minecraftArguments = args + + v.libraries = [] + + mc_filter = load_mc_version_filter(mc_version) + for upstream_lib in installer.libraries: + forge_lib = Library.parse_obj(upstream_lib.dict()) # "cast" MojangLibrary to Library + if forge_lib.name.is_lwjgl() or forge_lib.name.is_log4j() or should_ignore_artifact(mc_filter, forge_lib.name): continue - if pmcLib.name.group == "net.minecraftforge": - if pmcLib.name.artifact == "forge": - fixedName = pmcLib.name - fixedName.classifier = "universal" - pmcLib.downloads.artifact.path = fixedName.path() - pmcLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % fixedName.path() - pmcLib.name = fixedName - libs.append(pmcLib) - continue - elif pmcLib.name.artifact == "minecraftforge": - fixedName = pmcLib.name - fixedName.artifact = "forge" - fixedName.classifier = "universal" - fixedName.version = "%s-%s" % (mcversion, fixedName.version) - pmcLib.downloads.artifact.path = fixedName.path() - pmcLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % fixedName.path() - pmcLib.name = fixedName - libs.append(pmcLib) - continue - libs.append(pmcLib) - - result.libraries = libs - result.order = 5 - return result - - -def versionFromLegacy(version: ForgeVersion, legacyinfo: ForgeLegacyInfo): - result = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) - mcversion = version.mcversion_sane - result.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mcversion)] - result.release_time = legacyinfo.releaseTime - result.order = 5 - if fml_libs_for_version(mcversion): # WHY, WHY DID I WASTE MY TIME REWRITING FMLLIBSMAPPING - result.additional_traits = ["legacyFML"] - url = version.url() - if "universal" in url: + + if forge_lib.name.group == "net.minecraftforge": + if forge_lib.name.artifact == "forge": + overridden_name = forge_lib.name + overridden_name.classifier = "universal" + forge_lib.downloads.artifact.path = overridden_name.path() + forge_lib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % overridden_name.path() + forge_lib.name = overridden_name + + elif forge_lib.name.artifact == "minecraftforge": + overridden_name = forge_lib.name + overridden_name.artifact = "forge" + overridden_name.classifier = "universal" + overridden_name.version = "%s-%s" % (mc_version, overridden_name.version) + forge_lib.downloads.artifact.path = overridden_name.path() + forge_lib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % overridden_name.path() + forge_lib.name = overridden_name + + v.libraries.append(forge_lib) + + v.order = 5 + return v + + +def version_from_legacy(info: ForgeLegacyInfo, version: ForgeVersion) -> MetaVersion: + v = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) + mc_version = version.mc_version_sane + v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=mc_version)] + v.release_time = info.release_time + v.order = 5 + if fml_libs_for_version(mc_version): # WHY, WHY DID I WASTE MY TIME REWRITING FMLLIBSMAPPING + v.additional_traits = ["legacyFML"] + + classifier = "client" + if "universal" in version.url(): classifier = "universal" - else: - classifier = "client" - coord = GradleSpecifier("net.minecraftforge", "forge", version.longVersion, classifier) - mainmod = Library(name=coord) - mainmod.downloads = MojangLibraryDownloads() - mainmod.downloads.artifact = MojangArtifact(url=version.url(), sha1=legacyinfo.sha1, size=legacyinfo.size) - mainmod.downloads.artifact.path = None - result.jar_mods = [mainmod] - return result - - -def versionFromBuildSystemInstaller(installerVersion: MojangVersion, installerProfile: ForgeInstallerProfileV2, - version: ForgeVersion): - eprint("Generating Forge %s." % version.longVersion) - result = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) - result.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=version.mcversion_sane)] - result.main_class = "io.github.zekerzhayard.forgewrapper.installer.Main" + + main_mod = Library(name=GradleSpecifier("net.minecraftforge", "forge", version.long_version, classifier)) + main_mod.downloads = MojangLibraryDownloads() + main_mod.downloads.artifact = MojangArtifact(url=version.url(), sha1=info.sha1, size=info.size) + main_mod.downloads.artifact.path = None + v.jar_mods = [main_mod] + return v + + +def version_from_build_system_installer(installer: MojangVersion, profile: ForgeInstallerProfileV2, + version: ForgeVersion) -> MetaVersion: + v = MetaVersion(name="Forge", version=version.rawVersion, uid=FORGE_COMPONENT) + v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=version.mc_version_sane)] + v.main_class = "io.github.zekerzhayard.forgewrapper.installer.Main" # FIXME: Add the size and hash here - mavenLibs = [] + v.maven_files = [] # load the locally cached installer file info and use it to add the installer entry in the json - installerInfo = InstallerInfo.parse_file( - os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{version.longVersion}.json")) - InstallerLib = Library( - name=GradleSpecifier("net.minecraftforge", "forge", version.longVersion, "installer")) - InstallerLib.downloads = MojangLibraryDownloads() - InstallerLib.downloads.artifact = MojangArtifact( - url="https://files.minecraftforge.net/maven/%s" % (InstallerLib.name.path()), - sha1=installerInfo.sha1hash, - size=installerInfo.size) - mavenLibs.append(InstallerLib) - - for upstreamLib in installerProfile.libraries: - pmcLib = Library.parse_obj(upstreamLib.dict()) - if pmcLib.name.group == "net.minecraftforge": - if pmcLib.name.artifact == "forge": - if pmcLib.name.classifier == "universal": - pmcLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % pmcLib.name.path() - mavenLibs.append(pmcLib) - continue - if pmcLib.name.is_log4j(): + info = InstallerInfo.parse_file( + os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{version.long_version}.json")) + installer_lib = Library( + name=GradleSpecifier("net.minecraftforge", "forge", version.long_version, "installer")) + installer_lib.downloads = MojangLibraryDownloads() + installer_lib.downloads.artifact = MojangArtifact( + url="https://files.minecraftforge.net/maven/%s" % (installer_lib.name.path()), + sha1=info.sha1hash, + size=info.size) + v.maven_files.append(installer_lib) + + for upstream_lib in profile.libraries: + forge_lib = Library.parse_obj(upstream_lib.dict()) + if forge_lib.name.is_log4j(): continue - mavenLibs.append(pmcLib) - - result.maven_files = mavenLibs - - libraries = [] - - wrapperLib = Library(name=GradleSpecifier("io.github.zekerzhayard", "ForgeWrapper", "mmc2")) - wrapperLib.downloads = MojangLibraryDownloads() - wrapperLib.downloads.artifact = MojangArtifact(url=FORGEWRAPPER_MAVEN % (wrapperLib.name.path()), - sha1="4ee5f25cc9c7efbf54aff4c695da1054c1a1d7a3", - size=34444) - libraries.append(wrapperLib) - - for upstreamLib in installerVersion.libraries: - pmcLib = Library.parse_obj(upstreamLib.dict()) - if pmcLib.name.group == "net.minecraftforge": - if pmcLib.name.artifact == "forge": - fixedName = pmcLib.name - fixedName.classifier = "launcher" - pmcLib.downloads.artifact.path = fixedName.path() - pmcLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % fixedName.path() - pmcLib.name = fixedName - libraries.append(pmcLib) - continue - if pmcLib.name.is_log4j(): + + if forge_lib.name.group == "net.minecraftforge" and forge_lib.name.artifact == "forge" \ + and forge_lib.name.classifier == "universal": + forge_lib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % forge_lib.name.path() + v.maven_files.append(forge_lib) + + v.libraries = [] + + wrapper_lib = Library(name=GradleSpecifier("io.github.zekerzhayard", "ForgeWrapper", "mmc2")) + wrapper_lib.downloads = MojangLibraryDownloads() + wrapper_lib.downloads.artifact = MojangArtifact(url=FORGEWRAPPER_MAVEN % (wrapper_lib.name.path()), + sha1="4ee5f25cc9c7efbf54aff4c695da1054c1a1d7a3", + size=34444) + v.libraries.append(wrapper_lib) + + for upstream_lib in installer.libraries: + forge_lib = Library.parse_obj(upstream_lib.dict()) + if forge_lib.name.is_log4j(): continue - libraries.append(pmcLib) - result.libraries = libraries - result.release_time = installerVersion.release_time - result.order = 5 - mcArgs = "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}" - for arg in installerVersion.arguments.game: - mcArgs += " %s" % arg - result.minecraft_arguments = mcArgs - return result + if forge_lib.name.group == "net.minecraftforge": + if forge_lib.name.artifact == "forge": + forge_lib.name.classifier = "launcher" + forge_lib.downloads.artifact.path = forge_lib.name.path() + forge_lib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % forge_lib.name.path() + forge_lib.name = forge_lib.name + v.libraries.append(forge_lib) + + v.release_time = installer.release_time + v.order = 5 + mc_args = "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} " \ + "--assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} " \ + "--accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}" + for arg in installer.arguments.game: + mc_args += f" {arg}" + v.minecraft_arguments = mc_args + return v def main(): # load the locally cached version list - remoteVersionlist = DerivedForgeIndex.parse_file(os.path.join(UPSTREAM_DIR, DERIVED_INDEX_FILE)) + remote_versions = DerivedForgeIndex.parse_file(os.path.join(UPSTREAM_DIR, DERIVED_INDEX_FILE)) + recommended_versions = [] - recommendedVersions = [] - - legacyinfolist = ForgeLegacyInfoList.parse_file(os.path.join(STATIC_DIR, STATIC_LEGACYINFO_FILE)) - - legacyVersions = [ + legacy_info_list = ForgeLegacyInfoList.parse_file(os.path.join(STATIC_DIR, STATIC_LEGACYINFO_FILE)) + legacy_versions = [ "1.1", "1.2.3", "1.2.4", @@ -303,90 +290,87 @@ def main(): "1.12.2", ] - for id, entry in remoteVersionlist.versions.items(): - if entry.mcversion is None: - eprint("Skipping %s with invalid MC version" % id) + for key, entry in remote_versions.versions.items(): + if entry.mc_version is None: + eprint("Skipping %s with invalid MC version" % key) continue version = ForgeVersion(entry) - if version.longVersion in BAD_VERSIONS: + if version.long_version in BAD_VERSIONS: # Version 1.12.2-14.23.5.2851 is ultra cringe, I can't imagine why you would even spend one second on # actually adding support for this version. # It is cringe, because it's installer info is broken af - eprint(f"Skipping bad version {version.longVersion}") + eprint(f"Skipping bad version {version.long_version}") continue if version.url() is None: - eprint("Skipping %s with no valid files" % id) + eprint("Skipping %s with no valid files" % key) continue eprint("Processing Forge %s" % version.rawVersion) - versionElements = version.rawVersion.split('.') - if len(versionElements) < 1: - eprint("Skipping version %s with not enough version elements" % (id)) + version_elements = version.rawVersion.split('.') + if len(version_elements) < 1: + eprint("Skipping version %s with not enough version elements" % key) continue - majorVersionStr = versionElements[0] - if not majorVersionStr.isnumeric(): - eprint("Skipping version %s with non-numeric major version %s" % (id, majorVersionStr)) + major_version_str = version_elements[0] + if not major_version_str.isnumeric(): + eprint("Skipping version %s with non-numeric major version %s" % (key, major_version_str)) continue - majorVersion = int(majorVersionStr) - # if majorVersion >= 37: - # eprint ("Skipping unsupported major version %d (%s)" % (majorVersion, id)) + major_version = int(major_version_str) + # if major_version >= 37: + # eprint ("Skipping unsupported major version %d (%s)" % (major_version, key)) # continue if entry.recommended: - recommendedVersions.append(version.rawVersion) + recommended_versions.append(version.rawVersion) # If we do not have the corresponding Minecraft version, we ignore it - if not os.path.isfile(os.path.join(PMC_DIR, MINECRAFT_COMPONENT, f"{version.mcversion_sane}.json")): - eprint("Skipping %s with no corresponding Minecraft version %s" % (id, version.mcversion_sane)) + if not os.path.isfile(os.path.join(PMC_DIR, MINECRAFT_COMPONENT, f"{version.mc_version_sane}.json")): + eprint("Skipping %s with no corresponding Minecraft version %s" % (key, version.mc_version_sane)) continue - outVersion = None - # Path for new-style build system based installers - installerVersionFilepath = os.path.join(UPSTREAM_DIR, VERSION_MANIFEST_DIR, f"{version.longVersion}.json") - profileFilepath = os.path.join(UPSTREAM_DIR, INSTALLER_MANIFEST_DIR, f"{version.longVersion}.json") - - eprint(installerVersionFilepath) - if os.path.isfile(installerVersionFilepath): - installerVersion = MojangVersion.parse_file(installerVersionFilepath) - if entry.mcversion in legacyVersions: - outVersion = versionFromModernizedInstaller(installerVersion, version) + installer_version_filepath = os.path.join(UPSTREAM_DIR, VERSION_MANIFEST_DIR, f"{version.long_version}.json") + profile_filepath = os.path.join(UPSTREAM_DIR, INSTALLER_MANIFEST_DIR, f"{version.long_version}.json") + + eprint(installer_version_filepath) + if os.path.isfile(installer_version_filepath): + installer = MojangVersion.parse_file(installer_version_filepath) + if entry.mc_version in legacy_versions: + v = version_from_modernized_installer(installer, version) else: - installerProfile = ForgeInstallerProfileV2.parse_file(profileFilepath) - outVersion = versionFromBuildSystemInstaller(installerVersion, installerProfile, version) + profile = ForgeInstallerProfileV2.parse_file(profile_filepath) + v = version_from_build_system_installer(installer, profile, version) else: if version.uses_installer(): # If we do not have the Forge json, we ignore this version - if not os.path.isfile(profileFilepath): - eprint("Skipping %s with missing profile json" % id) + if not os.path.isfile(profile_filepath): + eprint("Skipping %s with missing profile json" % key) continue - profile = ForgeInstallerProfile.parse_file(profileFilepath) - outVersion = versionFromProfile(profile, version) + profile = ForgeInstallerProfile.parse_file(profile_filepath) + v = version_from_profile(profile, version) else: # Generate json for legacy here - if version.mcversion_sane == "1.6.1": + if version.mc_version_sane == "1.6.1": continue build = version.build - if not str(build).encode('utf-8').decode('utf8') in legacyinfolist.number: + if not str(build).encode('utf-8').decode('utf8') in legacy_info_list.number: eprint("Legacy build %d is missing in legacy info. Ignoring." % build) continue - outVersion = versionFromLegacy(version, legacyinfolist.number[str(build)]) + v = version_from_legacy(legacy_info_list.number[str(build)], version) - outFilepath = os.path.join(PMC_DIR, FORGE_COMPONENT, f"{outVersion.version}.json") - outVersion.write(outFilepath) + v.write(os.path.join(PMC_DIR, FORGE_COMPONENT, f"{v.version}.json")) - recommendedVersions.sort() + recommended_versions.sort() - print('Recommended versions:', recommendedVersions) + print('Recommended versions:', recommended_versions) package = MetaPackage(uid=FORGE_COMPONENT, name="Forge", project_url="https://www.minecraftforge.net/forum/") - package.recommended = recommendedVersions + package.recommended = recommended_versions package.write(os.path.join(PMC_DIR, FORGE_COMPONENT, "package.json")) diff --git a/meta/common/__init__.py b/meta/common/__init__.py index d072287277..4db3c57b61 100644 --- a/meta/common/__init__.py +++ b/meta/common/__init__.py @@ -1,8 +1,6 @@ import os import datetime -DATETIME_FORMAT_HTTP = "%a, %d %b %Y %H:%M:%S %Z" - def serialize_datetime(dt: datetime.datetime): if dt.tzinfo is None: diff --git a/meta/common/fabric.py b/meta/common/fabric.py index a306f15a16..2a35695cf1 100644 --- a/meta/common/fabric.py +++ b/meta/common/fabric.py @@ -8,3 +8,5 @@ META_DIR = join(BASE_DIR, "meta-v2") LOADER_COMPONENT = "net.fabricmc.fabric-loader" INTERMEDIARY_COMPONENT = "net.fabricmc.intermediary" + +DATETIME_FORMAT_HTTP = "%a, %d %b %Y %H:%M:%S %Z" diff --git a/meta/model/fabric.py b/meta/model/fabric.py index cd326e54c2..3ae557bf85 100644 --- a/meta/model/fabric.py +++ b/meta/model/fabric.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Optional, List, Union, Dict +from typing import Optional, List, Union from pydantic import Field diff --git a/meta/model/forge.py b/meta/model/forge.py index 6290cc8dff..35af76b3ad 100644 --- a/meta/model/forge.py +++ b/meta/model/forge.py @@ -12,17 +12,17 @@ class ForgeFile(MetaBase): hash: str extension: str - def filename(self, longversion): - return "%s-%s-%s.%s" % ("forge", longversion, self.classifier, self.extension) + def filename(self, long_version): + return "%s-%s-%s.%s" % ("forge", long_version, self.classifier, self.extension) - def url(self, longversion): + def url(self, long_version): return "https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/%s" % ( - longversion, self.filename(longversion)) + long_version, self.filename(long_version)) class ForgeEntry(MetaBase): - longversion: str - mcversion: str + long_version: str = Field(alias="longversion") + mc_version: str = Field(alias="mcversion") version: str build: int branch: Optional[str] @@ -39,7 +39,7 @@ class ForgeMCVersionInfo(MetaBase): class DerivedForgeIndex(MetaBase): versions: Dict[str, ForgeEntry] = Field({}) - by_mcversion: Dict[str, ForgeMCVersionInfo] = Field({}) + by_mc_version: Dict[str, ForgeMCVersionInfo] = Field({}, alias="by_mcversion") class FMLLib(MetaBase): # old ugly stuff. Maybe merge this with Library or MojangLibrary later @@ -74,29 +74,29 @@ class ForgeInstallerProfileInstallSection(MetaBase): "modList":"none" }, """ - profileName: str + profile_name: str = Field(alias="profileName") target: str path: GradleSpecifier version: str - filePath: str + file_path: str = Field(alias="filePath") welcome: str minecraft: str logo: str - mirrorList: str - modList: Optional[str] + mirror_list: str = Field(alias="mirrorList") + mod_list: Optional[str] = Field(alias="modList") class ForgeLibrary(MojangLibrary): url: Optional[str] - serverreq: Optional[bool] - clientreq: Optional[bool] + server_req: Optional[bool] = Field(alias="serverreq") + client_req: Optional[bool] = Field(alias="clientreq") checksums: Optional[List[str]] comment: Optional[str] class ForgeVersionFile(MojangVersion): libraries: Optional[List[ForgeLibrary]] # overrides Mojang libraries - inheritsFrom: Optional[str] + inherits_from: Optional[str] = Field("inheritsFrom") jar: Optional[str] @@ -129,12 +129,12 @@ class ForgeOptional(MetaBase): class ForgeInstallerProfile(MetaBase): install: ForgeInstallerProfileInstallSection - versionInfo: ForgeVersionFile + version_info: ForgeVersionFile = Field(alias="versionInfo") optionals: Optional[List[ForgeOptional]] class ForgeLegacyInfo(MetaBase): - releaseTime: Optional[datetime] + release_time: Optional[datetime] = Field(alias="releaseTime") size: Optional[int] sha256: Optional[str] sha1: Optional[str] @@ -171,8 +171,8 @@ class ForgeInstallerProfileV2(MetaBase): data: Optional[Dict[str, DataSpec]] processors: Optional[List[ProcessorSpec]] libraries: Optional[List[MojangLibrary]] - mirrorList: Optional[str] - serverJarPath: Optional[str] + mirror_list: Optional[str] = Field(alias="mirrorList") + server_jar_path: Optional[str] = Field(alias="serverJarPath") class InstallerInfo(MetaBase): @@ -181,83 +181,28 @@ class InstallerInfo(MetaBase): size: Optional[int] -def fml_libs_for_version(mc_version: str) -> List[FMLLib]: - argo_2_25 = FMLLib(filename="argo-2.25.jar", - checksum="bb672829fde76cb163004752b86b0484bd0a7f4b", - ours=False) - argo_small_3_2 = FMLLib(filename="argo-small-3.2.jar", - checksum="58912ea2858d168c50781f956fa5b59f0f7c6b51", - ours=False) - guava_12_0_1 = FMLLib(filename="guava-12.0.1.jar", - checksum="b8e78b9af7bf45900e14c6f958486b6ca682195f", - ours=False) - guava_14_0_rc3 = FMLLib(filename="guava-14.0-rc3.jar", - checksum="931ae21fa8014c3ce686aaa621eae565fefb1a6a", - ours=False) - asm_all_4_0 = FMLLib(filename="asm-all-4.0.jar", - checksum="98308890597acb64047f7e896638e0d98753ae82", - ours=False) - asm_all_4_1 = FMLLib(filename="asm-all-4.1.jar", - checksum="054986e962b88d8660ae4566475658469595ef58", - ours=False) - bcprov_jdk15on_147 = FMLLib(filename="bcprov-jdk15on-147.jar", - checksum="b6f5d9926b0afbde9f4dbe3db88c5247be7794bb", - ours=False) - bcprov_jdk15on_148 = FMLLib(filename="bcprov-jdk15on-148.jar", - checksum="960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", - ours=True) - scala_library = FMLLib(filename="scala-library.jar", - checksum="458d046151ad179c85429ed7420ffb1eaf6ddf85", - ours=True) - - deobfuscation_data_1_5 = FMLLib(filename="deobfuscation_data_1.5.zip", - checksum="5f7c142d53776f16304c0bbe10542014abad6af8", - ours=False) - - deobfuscation_data_1_5_1 = FMLLib(filename="deobfuscation_data_1.5.1.zip", - checksum="22e221a0d89516c1f721d6cab056a7e37471d0a6", - ours=False) - deobfuscation_data_1_5_2 = FMLLib(filename="deobfuscation_data_1.5.2.zip", - checksum="446e55cd986582c70fcf12cb27bc00114c5adfd9", - ours=False) - if mc_version == "1.3.2": - return [argo_2_25, guava_12_0_1, asm_all_4_0] - elif mc_version in ["1.4", "1.4.1", "1.4.2", "1.4.3", "1.4.4", "1.4.5", "1.4.6", "1.4.7"]: - return [argo_2_25, guava_12_0_1, asm_all_4_0, bcprov_jdk15on_147] - elif mc_version == "1.5": - return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5, - scala_library] - elif mc_version == "1.5.1": - return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5_1, - scala_library] - elif mc_version == "1.5.2": - return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5_2, - scala_library] - return [] - - # A post-processed entry constructed from the reconstructed Forge version index class ForgeVersion: def __init__(self, entry: ForgeEntry): self.build = entry.build self.rawVersion = entry.version - self.mcversion = entry.mcversion - self.mcversion_sane = self.mcversion.replace("_pre", "-pre", 1) + self.mc_version = entry.mc_version + self.mc_version_sane = self.mc_version.replace("_pre", "-pre", 1) self.branch = entry.branch self.installer_filename = None self.installer_url = None self.universal_filename = None self.universal_url = None self.changelog_url = None - self.longVersion = "%s-%s" % (self.mcversion, self.rawVersion) + self.long_version = "%s-%s" % (self.mc_version, self.rawVersion) if self.branch is not None: - self.longVersion = self.longVersion + "-%s" % self.branch + self.long_version = self.long_version + "-%s" % self.branch # this comment's whole purpose is to say this: cringe for classifier, file in entry.files.items(): extension = file.extension - filename = file.filename(self.longVersion) - url = file.url(self.longVersion) + filename = file.filename(self.long_version) + url = file.url(self.long_version) if (classifier == "installer") and (extension == "jar"): self.installer_filename = filename self.installer_url = url @@ -273,7 +218,7 @@ class ForgeVersion: def uses_installer(self): if self.installer_url is None: return False - if self.mcversion == "1.5.2": + if self.mc_version == "1.5.2": return False return True @@ -304,3 +249,58 @@ class ForgeVersion: # return False return True + + +def fml_libs_for_version(mc_version: str) -> List[FMLLib]: + argo_2_25 = FMLLib(filename="argo-2.25.jar", + checksum="bb672829fde76cb163004752b86b0484bd0a7f4b", + ours=False) + argo_small_3_2 = FMLLib(filename="argo-small-3.2.jar", + checksum="58912ea2858d168c50781f956fa5b59f0f7c6b51", + ours=False) + guava_12_0_1 = FMLLib(filename="guava-12.0.1.jar", + checksum="b8e78b9af7bf45900e14c6f958486b6ca682195f", + ours=False) + guava_14_0_rc3 = FMLLib(filename="guava-14.0-rc3.jar", + checksum="931ae21fa8014c3ce686aaa621eae565fefb1a6a", + ours=False) + asm_all_4_0 = FMLLib(filename="asm-all-4.0.jar", + checksum="98308890597acb64047f7e896638e0d98753ae82", + ours=False) + asm_all_4_1 = FMLLib(filename="asm-all-4.1.jar", + checksum="054986e962b88d8660ae4566475658469595ef58", + ours=False) + bcprov_jdk15on_147 = FMLLib(filename="bcprov-jdk15on-147.jar", + checksum="b6f5d9926b0afbde9f4dbe3db88c5247be7794bb", + ours=False) + bcprov_jdk15on_148 = FMLLib(filename="bcprov-jdk15on-148.jar", + checksum="960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", + ours=True) + scala_library = FMLLib(filename="scala-library.jar", + checksum="458d046151ad179c85429ed7420ffb1eaf6ddf85", + ours=True) + + deobfuscation_data_1_5 = FMLLib(filename="deobfuscation_data_1.5.zip", + checksum="5f7c142d53776f16304c0bbe10542014abad6af8", + ours=False) + + deobfuscation_data_1_5_1 = FMLLib(filename="deobfuscation_data_1.5.1.zip", + checksum="22e221a0d89516c1f721d6cab056a7e37471d0a6", + ours=False) + deobfuscation_data_1_5_2 = FMLLib(filename="deobfuscation_data_1.5.2.zip", + checksum="446e55cd986582c70fcf12cb27bc00114c5adfd9", + ours=False) + if mc_version == "1.3.2": + return [argo_2_25, guava_12_0_1, asm_all_4_0] + elif mc_version in ["1.4", "1.4.1", "1.4.2", "1.4.3", "1.4.4", "1.4.5", "1.4.6", "1.4.7"]: + return [argo_2_25, guava_12_0_1, asm_all_4_0, bcprov_jdk15on_147] + elif mc_version == "1.5": + return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5, + scala_library] + elif mc_version == "1.5.1": + return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5_1, + scala_library] + elif mc_version == "1.5.2": + return [argo_small_3_2, guava_14_0_rc3, asm_all_4_1, bcprov_jdk15on_148, deobfuscation_data_1_5_2, + scala_library] + return [] diff --git a/meta/model/mojang.py b/meta/model/mojang.py index 0df4cbcfc0..e5ea072acd 100644 --- a/meta/model/mojang.py +++ b/meta/model/mojang.py @@ -156,7 +156,7 @@ class MojangVersion(MetaBase): release_time: Optional[datetime] = Field(alias="releaseTime") time: Optional[datetime] type: Optional[str] - inheritsFrom: Optional[str] + inherits_from: Optional[str] = Field("inheritsFrom") logging: Optional[Dict[str, MojangLogging]] # TODO improve this? compliance_level: Optional[int] = Field(alias="complianceLevel") javaVersion: Optional[JavaVersion] diff --git a/updateFabric.py b/updateFabric.py index 3d707797bd..2f9ac262dd 100755 --- a/updateFabric.py +++ b/updateFabric.py @@ -8,8 +8,8 @@ import requests from cachecontrol import CacheControl from cachecontrol.caches import FileCache -from meta.common import DATETIME_FORMAT_HTTP, upstream_path, ensure_upstream_dir, transform_maven_key -from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR +from meta.common import upstream_path, ensure_upstream_dir, transform_maven_key +from meta.common.fabric import JARS_DIR, INSTALLER_INFO_DIR, META_DIR, DATETIME_FORMAT_HTTP from meta.model.fabric import FabricJarInfo UPSTREAM_DIR = upstream_path() diff --git a/updateForge.py b/updateForge.py index 0492339b83..4106bd8a8b 100755 --- a/updateForge.py +++ b/updateForge.py @@ -167,55 +167,55 @@ def main(): print("") print("Processing versions:") - for mcversion, value in main_json.items(): - assert type(mcversion) == str + for mc_version, value in main_json.items(): + assert type(mc_version) == str assert type(value) == list - for longversion in value: - assert type(longversion) == str - match = versionExpression.match(longversion) + for long_version in value: + assert type(long_version) == str + match = versionExpression.match(long_version) if not match: - pprint(longversion) + pprint(long_version) assert match - assert match.group('mc') == mcversion + assert match.group('mc') == mc_version - files = get_single_forge_files_manifest(longversion) + files = get_single_forge_files_manifest(long_version) build = int(match.group('build')) version = match.group('ver') branch = match.group('branch') - isRecommended = (version in recommendedSet) + is_recommended = (version in recommendedSet) entry = ForgeEntry( - longversion=longversion, - mcversion=mcversion, + long_version=long_version, + mc_version=mc_version, version=version, build=build, branch=branch, # NOTE: we add this later after the fact. The forge promotions file lies about these. latest=False, - recommended=isRecommended, + recommended=is_recommended, files=files ) - newIndex.versions[longversion] = entry - if not newIndex.by_mcversion: - newIndex.by_mcversion = dict() - if not mcversion in newIndex.by_mcversion: - newIndex.by_mcversion.setdefault(mcversion, ForgeMCVersionInfo()) - newIndex.by_mcversion[mcversion].versions.append(longversion) + newIndex.versions[long_version] = entry + if not newIndex.by_mc_version: + newIndex.by_mc_version = dict() + if mc_version not in newIndex.by_mc_version: + newIndex.by_mc_version.setdefault(mc_version, ForgeMCVersionInfo()) + newIndex.by_mc_version[mc_version].versions.append(long_version) # NOTE: we add this later after the fact. The forge promotions file lies about these. # if entry.latest: - # newIndex.by_mcversion[mcversion].latest = longversion + # newIndex.by_mc_version[mc_version].latest = long_version if entry.recommended: - newIndex.by_mcversion[mcversion].recommended = longversion + newIndex.by_mc_version[mc_version].recommended = long_version print("") print("Post processing promotions and adding missing 'latest':") - for mcversion, info in newIndex.by_mcversion.items(): - latestVersion = info.versions[-1] - info.latest = latestVersion - newIndex.versions[latestVersion].latest = True - print("Added %s as latest for %s" % (latestVersion, mcversion)) + for mc_version, info in newIndex.by_mc_version.items(): + latest_version = info.versions[-1] + info.latest = latest_version + newIndex.versions[latest_version].latest = True + print("Added %s as latest for %s" % (latest_version, mc_version)) print("") print("Dumping index files...") @@ -228,13 +228,13 @@ def main(): newIndex.write(UPSTREAM_DIR + "/forge/derived_index.json") - legacyinfolist = ForgeLegacyInfoList() + legacy_info_list = ForgeLegacyInfoList() print("Grabbing installers and dumping installer profiles...") # get the installer jars - if needed - and get the installer profiles out of them - for id, entry in newIndex.versions.items(): - eprint("Updating Forge %s" % id) - if entry.mcversion is None: + for key, entry in newIndex.versions.items(): + eprint("Updating Forge %s" % key) + if entry.mc_version is None: eprint("Skipping %d with invalid MC version" % entry.build) continue @@ -242,118 +242,112 @@ def main(): if version.url() is None: eprint("Skipping %d with no valid files" % version.build) continue - if version.longVersion in BAD_VERSIONS: - eprint(f"Skipping bad version {version.longVersion}") + if version.long_version in BAD_VERSIONS: + eprint(f"Skipping bad version {version.long_version}") continue - jarFilepath = UPSTREAM_DIR + "/forge/jars/%s" % version.filename() + jar_path = os.path.join(UPSTREAM_DIR, JARS_DIR, version.filename()) if version.uses_installer(): - installerInfoFilepath = UPSTREAM_DIR + "/forge/installer_info/%s.json" % version.longVersion - profileFilepath = UPSTREAM_DIR + "/forge/installer_manifests/%s.json" % version.longVersion - versionJsonFilepath = UPSTREAM_DIR + "/forge/version_manifests/%s.json" % version.longVersion - installerRefreshRequired = False - if not os.path.isfile(profileFilepath): - installerRefreshRequired = True - if not os.path.isfile(installerInfoFilepath): - installerRefreshRequired = True - - if installerRefreshRequired: + installer_info_path = UPSTREAM_DIR + "/forge/installer_info/%s.json" % version.long_version + profile_path = UPSTREAM_DIR + "/forge/installer_manifests/%s.json" % version.long_version + version_file_path = UPSTREAM_DIR + "/forge/version_manifests/%s.json" % version.long_version + + installer_refresh_required = not os.path.isfile(profile_path) or not os.path.isfile(installer_info_path) + + if installer_refresh_required: # grab the installer if it's not there - if not os.path.isfile(jarFilepath): + if not os.path.isfile(jar_path): eprint("Downloading %s" % version.url()) rfile = sess.get(version.url(), stream=True) rfile.raise_for_status() - with open(jarFilepath, 'wb') as f: + with open(jar_path, 'wb') as f: for chunk in rfile.iter_content(chunk_size=128): f.write(chunk) eprint("Processing %s" % version.url()) # harvestables from the installer - if not os.path.isfile(profileFilepath): - print(jarFilepath) - with zipfile.ZipFile(jarFilepath, 'r') as jar: + if not os.path.isfile(profile_path): + print(jar_path) + with zipfile.ZipFile(jar_path, 'r') as jar: with suppress(KeyError): - with jar.open('version.json', 'r') as profileZipEntry: - versionJsonData = profileZipEntry.read() - profileZipEntry.close() + with jar.open('version.json', 'r') as profile_zip_entry: + version_data = profile_zip_entry.read() # Process: does it parse? - doesItParse = MojangVersion.parse_raw(versionJsonData) + MojangVersion.parse_raw(version_data) - with open(versionJsonFilepath, 'wb') as versionJsonFile: - versionJsonFile.write(versionJsonData) + with open(version_file_path, 'wb') as versionJsonFile: + versionJsonFile.write(version_data) versionJsonFile.close() - with jar.open('install_profile.json', 'r') as profileZipEntry: - installProfileJsonData = profileZipEntry.read() - profileZipEntry.close() + with jar.open('install_profile.json', 'r') as profile_zip_entry: + install_profile_data = profile_zip_entry.read() # Process: does it parse? - atLeastOneFormatWorked = False + is_parsable = False exception = None try: - ForgeInstallerProfile.parse_raw(installProfileJsonData) - atLeastOneFormatWorked = True + ForgeInstallerProfile.parse_raw(install_profile_data) + is_parsable = True except ValidationError as err: exception = err try: - ForgeInstallerProfileV2.parse_raw(installProfileJsonData) - atLeastOneFormatWorked = True + ForgeInstallerProfileV2.parse_raw(install_profile_data) + is_parsable = True except ValidationError as err: exception = err - if not atLeastOneFormatWorked: + if not is_parsable: if version.is_supported(): raise exception else: eprint( - "Version %s is not supported and won't be generated later." % version.longVersion) + "Version %s is not supported and won't be generated later." % version.long_version) - with open(profileFilepath, 'wb') as profileFile: - profileFile.write(installProfileJsonData) + with open(profile_path, 'wb') as profileFile: + profileFile.write(install_profile_data) profileFile.close() # installer info v1 - if not os.path.isfile(installerInfoFilepath): - installerInfo = InstallerInfo() - installerInfo.sha1hash = filehash(jarFilepath, hashlib.sha1) - installerInfo.sha256hash = filehash(jarFilepath, hashlib.sha256) - installerInfo.size = os.path.getsize(jarFilepath) - installerInfo.write(installerInfoFilepath) + if not os.path.isfile(installer_info_path): + installer_info = InstallerInfo() + installer_info.sha1hash = filehash(jar_path, hashlib.sha1) + installer_info.sha256hash = filehash(jar_path, hashlib.sha256) + installer_info.size = os.path.getsize(jar_path) + installer_info.write(installer_info_path) else: # ignore the two versions without install manifests and jar mod class files # TODO: fix those versions? - if version.mcversion_sane == "1.6.1": + if version.mc_version_sane == "1.6.1": continue # only gather legacy info if it's missing if not os.path.isfile(LEGACYINFO_PATH): # grab the jar/zip if it's not there - if not os.path.isfile(jarFilepath): + if not os.path.isfile(jar_path): rfile = sess.get(version.url(), stream=True) rfile.raise_for_status() - with open(jarFilepath, 'wb') as f: + with open(jar_path, 'wb') as f: for chunk in rfile.iter_content(chunk_size=128): f.write(chunk) # find the latest timestamp in the zip file tstamp = datetime.fromtimestamp(0) - with zipfile.ZipFile(jarFilepath, 'r') as jar: - allinfo = jar.infolist() - for info in allinfo: - tstampNew = datetime(*info.date_time) - if tstampNew > tstamp: - tstamp = tstampNew - legacyInfo = ForgeLegacyInfo() - legacyInfo.releaseTime = tstamp - legacyInfo.sha1 = filehash(jarFilepath, hashlib.sha1) - legacyInfo.sha256 = filehash(jarFilepath, hashlib.sha256) - legacyInfo.size = os.path.getsize(jarFilepath) - legacyinfolist.number[id] = legacyInfo + with zipfile.ZipFile(jar_path, 'r') as jar: + for info in jar.infolist(): + tstamp_new = datetime(*info.date_time) + if tstamp_new > tstamp: + tstamp = tstamp_new + legacy_info = ForgeLegacyInfo() + legacy_info.release_time = tstamp + legacy_info.sha1 = filehash(jar_path, hashlib.sha1) + legacy_info.sha256 = filehash(jar_path, hashlib.sha256) + legacy_info.size = os.path.getsize(jar_path) + legacy_info_list.number[key] = legacy_info # only write legacy info if it's missing if not os.path.isfile(LEGACYINFO_PATH): - legacyinfolist.write(LEGACYINFO_PATH) + legacy_info_list.write(LEGACYINFO_PATH) if __name__ == '__main__': |
