diff options
Diffstat (limited to 'updateForge.py')
| -rwxr-xr-x | updateForge.py | 141 |
1 files changed, 93 insertions, 48 deletions
diff --git a/updateForge.py b/updateForge.py index 64ccb6a0c6..8bae3768be 100755 --- a/updateForge.py +++ b/updateForge.py @@ -16,11 +16,27 @@ from pprint import pprint from pydantic import ValidationError from meta.common import upstream_path, ensure_upstream_dir, static_path, default_session -from meta.common.forge import JARS_DIR, INSTALLER_INFO_DIR, INSTALLER_MANIFEST_DIR, VERSION_MANIFEST_DIR, \ - FILE_MANIFEST_DIR, BAD_VERSIONS, STATIC_LEGACYINFO_FILE -from meta.model.forge import ForgeFile, ForgeEntry, ForgeMCVersionInfo, ForgeLegacyInfoList, DerivedForgeIndex, \ - ForgeVersion, ForgeInstallerProfile, ForgeInstallerProfileV2, InstallerInfo, \ - ForgeLegacyInfo +from meta.common.forge import ( + JARS_DIR, + INSTALLER_INFO_DIR, + INSTALLER_MANIFEST_DIR, + VERSION_MANIFEST_DIR, + FILE_MANIFEST_DIR, + BAD_VERSIONS, + STATIC_LEGACYINFO_FILE, +) +from meta.model.forge import ( + ForgeFile, + ForgeEntry, + ForgeMCVersionInfo, + ForgeLegacyInfoList, + DerivedForgeIndex, + ForgeVersion, + ForgeInstallerProfile, + ForgeInstallerProfileV2, + InstallerInfo, + ForgeLegacyInfo, +) from meta.model.mojang import MojangVersion UPSTREAM_DIR = upstream_path() @@ -55,18 +71,21 @@ def get_single_forge_files_manifest(longversion): files_manifest_file = Path(path_thing) from_file = False if files_manifest_file.is_file(): - with open(path_thing, 'r') as f: + with open(path_thing, "r") as f: files_json = json.load(f) from_file = True else: - file_url = 'https://files.minecraftforge.net/net/minecraftforge/forge/%s/meta.json' % longversion + file_url = ( + "https://files.minecraftforge.net/net/minecraftforge/forge/%s/meta.json" + % longversion + ) r = sess.get(file_url) r.raise_for_status() files_json = r.json() ret_dict = dict() - for classifier, extensionObj in files_json.get('classifiers').items(): + for classifier, extensionObj in files_json.get("classifiers").items(): assert type(classifier) == str assert type(extensionObj) == dict @@ -82,33 +101,40 @@ def get_single_forge_files_manifest(longversion): if not type(hashtype) == str: pprint(classifier) pprint(extensionObj) - print('%s: Skipping missing hash for extension %s:' % (longversion, extension)) + print( + "%s: Skipping missing hash for extension %s:" + % (longversion, extension) + ) index += 1 continue assert type(classifier) == str processed_hash = re.sub(r"\W", "", hashtype) if not len(processed_hash) == 32: - print('%s: Skipping invalid hash for extension %s:' % (longversion, extension)) + print( + "%s: Skipping invalid hash for extension %s:" + % (longversion, extension) + ) pprint(extensionObj) index += 1 continue file_obj = ForgeFile( - classifier=classifier, - hash=processed_hash, - extension=extension + classifier=classifier, hash=processed_hash, extension=extension ) if count == 0: ret_dict[classifier] = file_obj index += 1 count += 1 else: - print('%s: Multiple objects detected for classifier %s:' % (longversion, classifier)) + print( + "%s: Multiple objects detected for classifier %s:" + % (longversion, classifier) + ) pprint(extensionObj) assert False if not from_file: - with open(path_thing, 'w', encoding='utf-8') as f: + with open(path_thing, "w", encoding="utf-8") as f: json.dump(files_json, f, sort_keys=True, indent=4) return ret_dict @@ -116,18 +142,23 @@ def get_single_forge_files_manifest(longversion): def main(): # get the remote version list fragments - r = sess.get('https://files.minecraftforge.net/net/minecraftforge/forge/maven-metadata.json') + r = sess.get( + "https://files.minecraftforge.net/net/minecraftforge/forge/maven-metadata.json" + ) r.raise_for_status() main_json = r.json() assert type(main_json) == dict - r = sess.get('https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json') + r = sess.get( + "https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json" + ) r.raise_for_status() promotions_json = r.json() assert type(promotions_json) == dict promoted_key_expression = re.compile( - "(?P<mc>[^-]+)-(?P<promotion>(latest)|(recommended))(-(?P<branch>[a-zA-Z0-9\\.]+))?") + "(?P<mc>[^-]+)-(?P<promotion>(latest)|(recommended))(-(?P<branch>[a-zA-Z0-9\\.]+))?" + ) recommended_set = set() @@ -140,28 +171,31 @@ def main(): # Therefore we only use the short version part for later identification and filter out the branch-specific # promotions (among other errors). print("Processing promotions:") - for promoKey, shortversion in promotions_json.get('promos').items(): + for promoKey, shortversion in promotions_json.get("promos").items(): match = promoted_key_expression.match(promoKey) if not match: - print('Skipping promotion %s, the key did not parse:' % promoKey) + print("Skipping promotion %s, the key did not parse:" % promoKey) pprint(promoKey) assert match - if not match.group('mc'): - print('Skipping promotion %s, because it has no Minecraft version.' % promoKey) + if not match.group("mc"): + print( + "Skipping promotion %s, because it has no Minecraft version." % promoKey + ) continue - if match.group('branch'): - print('Skipping promotion %s, because it on a branch only.' % promoKey) + if match.group("branch"): + print("Skipping promotion %s, because it on a branch only." % promoKey) continue - elif match.group('promotion') == 'recommended': + elif match.group("promotion") == "recommended": recommended_set.add(shortversion) - print('%s added to recommended set' % shortversion) - elif match.group('promotion') == 'latest': + print("%s added to recommended set" % shortversion) + elif match.group("promotion") == "latest": pass else: assert False version_expression = re.compile( - "^(?P<mc>[0-9a-zA-Z_\\.]+)-(?P<ver>[0-9\\.]+\\.(?P<build>[0-9]+))(-(?P<branch>[a-zA-Z0-9\\.]+))?$") + "^(?P<mc>[0-9a-zA-Z_\\.]+)-(?P<ver>[0-9\\.]+\\.(?P<build>[0-9]+))(-(?P<branch>[a-zA-Z0-9\\.]+))?$" + ) print("") print("Processing versions:") @@ -174,15 +208,15 @@ def main(): if not match: pprint(long_version) assert match - assert match.group('mc') == mc_version + assert match.group("mc") == mc_version files = get_single_forge_files_manifest(long_version) - build = int(match.group('build')) - version = match.group('ver') - branch = match.group('branch') + build = int(match.group("build")) + version = match.group("ver") + branch = match.group("branch") - is_recommended = (version in recommended_set) + is_recommended = version in recommended_set entry = ForgeEntry( long_version=long_version, @@ -193,7 +227,7 @@ def main(): # NOTE: we add this later after the fact. The forge promotions file lies about these. latest=False, recommended=is_recommended, - files=files + files=files, ) new_index.versions[long_version] = entry if not new_index.by_mc_version: @@ -218,10 +252,10 @@ def main(): print("") print("Dumping index files...") - with open(UPSTREAM_DIR + "/forge/maven-metadata.json", 'w', encoding='utf-8') as f: + with open(UPSTREAM_DIR + "/forge/maven-metadata.json", "w", encoding="utf-8") as f: json.dump(main_json, f, sort_keys=True, indent=4) - with open(UPSTREAM_DIR + "/forge/promotions_slim.json", 'w', encoding='utf-8') as f: + with open(UPSTREAM_DIR + "/forge/promotions_slim.json", "w", encoding="utf-8") as f: json.dump(promotions_json, f, sort_keys=True, indent=4) new_index.write(UPSTREAM_DIR + "/forge/derived_index.json") @@ -247,11 +281,20 @@ def main(): jar_path = os.path.join(UPSTREAM_DIR, JARS_DIR, version.filename()) if version.uses_installer(): - 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_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) + 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 @@ -259,7 +302,7 @@ def main(): eprint("Downloading %s" % version.url()) rfile = sess.get(version.url(), stream=True) rfile.raise_for_status() - with open(jar_path, 'wb') as f: + with open(jar_path, "wb") as f: for chunk in rfile.iter_content(chunk_size=128): f.write(chunk) @@ -269,17 +312,17 @@ def main(): print(jar_path) with zipfile.ZipFile(jar_path) as jar: with suppress(KeyError): - with jar.open('version.json') as profile_zip_entry: + with jar.open("version.json") as profile_zip_entry: version_data = profile_zip_entry.read() # Process: does it parse? MojangVersion.parse_raw(version_data) - with open(version_file_path, 'wb') as versionJsonFile: + with open(version_file_path, "wb") as versionJsonFile: versionJsonFile.write(version_data) versionJsonFile.close() - with jar.open('install_profile.json') as profile_zip_entry: + with jar.open("install_profile.json") as profile_zip_entry: install_profile_data = profile_zip_entry.read() # Process: does it parse? @@ -301,9 +344,11 @@ def main(): raise exception else: eprint( - "Version %s is not supported and won't be generated later." % version.long_version) + "Version %s is not supported and won't be generated later." + % version.long_version + ) - with open(profile_path, 'wb') as profileFile: + with open(profile_path, "wb") as profileFile: profileFile.write(install_profile_data) profileFile.close() @@ -326,7 +371,7 @@ def main(): if not os.path.isfile(jar_path): rfile = sess.get(version.url(), stream=True) rfile.raise_for_status() - with open(jar_path, '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 @@ -348,5 +393,5 @@ def main(): legacy_info_list.write(LEGACYINFO_PATH) -if __name__ == '__main__': +if __name__ == "__main__": main() |
