diff --git a/enumerateForge.py b/enumerateForge.py index 2fa257c..06c5540 100755 --- a/enumerateForge.py +++ b/enumerateForge.py @@ -7,18 +7,20 @@ from metautil import * PMC_DIR = os.environ["PMC_DIR"] -#with open(PMC_DIR + '/index.json', 'r', encoding='utf-8') as index: - #packages = PolyMCPackageIndex(json.load(index)) -#for entry in packages.packages: - #print (entry) +# with open(PMC_DIR + '/index.json', 'r', encoding='utf-8') as index: +# packages = PolyMCPackageIndex(json.load(index)) + +# for entry in packages.packages: +# print (entry) class DownloadType(Enum): NORMAL = 1 FORGE_XZ = 2 + class DownloadEntry: - def __init__(self, url : str, kind : DownloadType, name : GradleSpecifier): + def __init__(self, url: str, kind: DownloadType, name: GradleSpecifier): self.name = name self.url = url self.kind = kind @@ -41,19 +43,21 @@ class DownloadEntry: def __repr__(self): return "DownloadEntry('" + self.toString() + "')" -class MojangLibrary (JsonObject): + +class MojangLibrary(JsonObject): extract = ObjectProperty(MojangLibraryExtractRules, exclude_if_none=True, default=None) - name = GradleSpecifierProperty(required = True) + name = GradleSpecifierProperty(required=True) downloads = ObjectProperty(MojangLibraryDownloads, exclude_if_none=True, default=None) natives = DictProperty(StringProperty, exclude_if_none=True, default=None) rules = ListProperty(MojangRule, exclude_if_none=True, default=None) -class PolyMCLibrary (MojangLibrary): + +class PolyMCLibrary(MojangLibrary): url = StringProperty(exclude_if_none=True, default=None) mmcHint = StringProperty(name="MMC-hint", exclude_if_none=True, default=None) # this is supposed to be MMC-hint! -def GetLibraryDownload (library : PolyMCLibrary): +def GetLibraryDownload(library: PolyMCLibrary): if library.natives: raise Exception('Natives are not handled yet') @@ -69,7 +73,6 @@ def GetLibraryDownload (library : PolyMCLibrary): if url.endswith('.zip'): name.extension = 'zip' - if library.downloads: url = library.downloads.artifact.url else: @@ -80,6 +83,7 @@ def GetLibraryDownload (library : PolyMCLibrary): return DownloadEntry(url, kind, name) + with open(PMC_DIR + '/net.minecraftforge/index.json', 'r', encoding='utf-8') as forgeIndex: forgeVersions = PolyMCVersionIndex(json.load(forgeIndex)) diff --git a/fabricutil.py b/fabricutil.py index 1133bc5..6a95900 100644 --- a/fabricutil.py +++ b/fabricutil.py @@ -7,14 +7,17 @@ class FabricInstallerArguments(JsonObject): common = ListProperty(StringProperty) server = ListProperty(StringProperty) + class FabricInstallerLaunchwrapper(JsonObject): tweakers = ObjectProperty(FabricInstallerArguments, required=True) + class FabricInstallerLibraries(JsonObject): client = ListProperty(PolyMCLibrary) common = ListProperty(PolyMCLibrary) server = ListProperty(PolyMCLibrary) + class FabricInstallerDataV1(JsonObject): version = IntegerProperty(required=True) libraries = ObjectProperty(FabricInstallerLibraries, required=True) @@ -22,6 +25,7 @@ class FabricInstallerDataV1(JsonObject): arguments = ObjectProperty(FabricInstallerArguments, required=False) launchwrapper = ObjectProperty(FabricInstallerLaunchwrapper, required=False) + class FabricJarInfo(JsonObject): releaseTime = ISOTimestampProperty() size = IntegerProperty() diff --git a/forgeutil.py b/forgeutil.py index 9455203..3c990e5 100644 --- a/forgeutil.py +++ b/forgeutil.py @@ -67,12 +67,13 @@ class ForgeVersion: if not majorVersionStr.isnumeric(): return False - #majorVersion = int(majorVersionStr) - #if majorVersion >= 37: + # majorVersion = int(majorVersionStr) + # if majorVersion >= 37: # return False return True + class ForgeFile(JsonObject): classifier = StringProperty(required=True) hash = StringProperty(required=True) @@ -82,7 +83,9 @@ class ForgeFile(JsonObject): return "%s-%s-%s.%s" % ("forge", longversion, self.classifier, self.extension) def url(self, longversion): - return "https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/%s" % (longversion, self.filename(longversion)) + return "https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/%s" % ( + longversion, self.filename(longversion)) + class ForgeEntry(JsonObject): longversion = StringProperty(required=True) @@ -94,15 +97,18 @@ class ForgeEntry(JsonObject): recommended = BooleanProperty() files = DictProperty(ForgeFile) + class ForgeMcVersionInfo(JsonObject): latest = StringProperty() recommended = StringProperty() versions = ListProperty(StringProperty()) + class DerivedForgeIndex(JsonObject): versions = DictProperty(ForgeEntry) by_mcversion = DictProperty(ForgeMcVersionInfo) + ''' FML library mappings - these are added to legacy Forge versions because Forge no longer can download these by itself - the locations have changed and some of this has to be rehosted on PolyMC servers. @@ -185,30 +191,35 @@ fmlLibsMapping["1.5.2"] = [ "modList":"none" }, ''' + + class ForgeInstallerProfileInstallSection(JsonObject): - profileName = StringProperty(required = True) - target = StringProperty(required = True) - path = GradleSpecifierProperty(required = True) - version = StringProperty(required = True) - filePath = StringProperty(required = True) - welcome = StringProperty(required = True) - minecraft = StringProperty(required = True) - logo = StringProperty(required = True) - mirrorList = StringProperty(required = True) + profileName = StringProperty(required=True) + target = StringProperty(required=True) + path = GradleSpecifierProperty(required=True) + version = StringProperty(required=True) + filePath = StringProperty(required=True) + welcome = StringProperty(required=True) + minecraft = StringProperty(required=True) + logo = StringProperty(required=True) + mirrorList = StringProperty(required=True) modList = StringProperty(exclude_if_none=True, default=None) -class ForgeLibrary (MojangLibrary): + +class ForgeLibrary(MojangLibrary): url = StringProperty(exclude_if_none=True) serverreq = BooleanProperty(exclude_if_none=True, default=None) clientreq = BooleanProperty(exclude_if_none=True, default=None) checksums = ListProperty(StringProperty) comment = StringProperty() -class ForgeVersionFile (MojangVersionFile): - libraries = ListProperty(ForgeLibrary, exclude_if_none=True, default=None) # overrides Mojang libraries + +class ForgeVersionFile(MojangVersionFile): + libraries = ListProperty(ForgeLibrary, exclude_if_none=True, default=None) # overrides Mojang libraries inheritsFrom = StringProperty() jar = StringProperty() + ''' "optionals": [ { @@ -224,7 +235,9 @@ class ForgeVersionFile (MojangVersionFile): } ] ''' -class ForgeOptional (JsonObject): + + +class ForgeOptional(JsonObject): name = StringProperty() client = BooleanProperty() server = BooleanProperty() @@ -235,24 +248,29 @@ class ForgeOptional (JsonObject): artifact = GradleSpecifierProperty() maven = StringProperty() + class ForgeInstallerProfile(JsonObject): - install = ObjectProperty(ForgeInstallerProfileInstallSection, required = True) - versionInfo = ObjectProperty(ForgeVersionFile, required = True) + install = ObjectProperty(ForgeInstallerProfileInstallSection, required=True) + versionInfo = ObjectProperty(ForgeVersionFile, required=True) optionals = ListProperty(ForgeOptional) + class ForgeLegacyInfo(JsonObject): releaseTime = ISOTimestampProperty() size = IntegerProperty() sha256 = StringProperty() sha1 = StringProperty() + class ForgeLegacyInfoList(JsonObject): number = DictProperty(ForgeLegacyInfo) + class DataSpec(JsonObject): client = StringProperty() server = StringProperty() + class ProcessorSpec(JsonObject): jar = StringProperty() classpath = ListProperty(StringProperty) @@ -260,6 +278,7 @@ class ProcessorSpec(JsonObject): outputs = DictProperty(StringProperty) sides = ListProperty(StringProperty, exclude_if_none=True, default=None) + # Note: This is only used in one version (1.12.2-14.23.5.2851) and we don't even use the installer profile in it. # It's here just so it parses and we can continue... class ForgeInstallerProfileV1_5(JsonObject): @@ -279,6 +298,7 @@ class ForgeInstallerProfileV1_5(JsonObject): libraries = ListProperty(MojangLibrary) mirrorList = StringProperty(exclude_if_none=True, default=None) + class ForgeInstallerProfileV2(JsonObject): _comment = ListProperty(StringProperty) spec = IntegerProperty() @@ -296,6 +316,7 @@ class ForgeInstallerProfileV2(JsonObject): mirrorList = StringProperty(exclude_if_none=True, default=None) serverJarPath = StringProperty(exclude_if_none=True, default=None) + class InstallerInfo(JsonObject): sha1hash = StringProperty() sha256hash = StringProperty() diff --git a/generateFabric.py b/generateFabric.py index fac96d0..8dd292d 100755 --- a/generateFabric.py +++ b/generateFabric.py @@ -9,17 +9,22 @@ loaderVersions = [] intermediaryRecommended = [] intermediaryVersions = [] + def mkdirs(path): if not os.path.exists(path): os.makedirs(path) + mkdirs(PMC_DIR + "/net.fabricmc.fabric-loader") mkdirs(PMC_DIR + "/net.fabricmc.intermediary") + def loadJarInfo(mavenKey): - with open(UPSTREAM_DIR + "/fabric/jars/" + mavenKey.replace(":", ".") + ".json", 'r', encoding='utf-8') as jarInfoFile: + with open(UPSTREAM_DIR + "/fabric/jars/" + mavenKey.replace(":", ".") + ".json", 'r', + encoding='utf-8') as jarInfoFile: return FabricJarInfo(json.load(jarInfoFile)) + def processLoaderVersion(loaderVersion, it, loaderData): verStable = it["stable"] if (len(loaderRecommended) < 1) and verStable: @@ -41,6 +46,7 @@ def processLoaderVersion(loaderVersion, it, loaderData): version.libraries.append(loaderLib) loaderVersions.append(version) + def processIntermediaryVersion(it): intermediaryRecommended.append(it["version"]) versionJarInfo = loadJarInfo(it["maven"]) @@ -55,11 +61,13 @@ def processIntermediaryVersion(it): version.libraries.append(mappingLib) intermediaryVersions.append(version) + with open(UPSTREAM_DIR + "/fabric/meta-v2/loader.json", 'r', encoding='utf-8') as loaderVersionIndexFile: loaderVersionIndex = json.load(loaderVersionIndexFile) for it in loaderVersionIndex: version = it["version"] - with open(UPSTREAM_DIR + "/fabric/loader-installer-json/" + version + ".json", 'r', encoding='utf-8') as loaderVersionFile: + with open(UPSTREAM_DIR + "/fabric/loader-installer-json/" + version + ".json", 'r', + encoding='utf-8') as loaderVersionFile: ldata = json.load(loaderVersionFile) ldata = FabricInstallerDataV1(ldata) processLoaderVersion(version, it, ldata) @@ -74,7 +82,7 @@ for version in loaderVersions: with open(outFilepath, 'w') as outfile: json.dump(version.to_json(), outfile, sort_keys=True, indent=4) -sharedData = PolyMCSharedPackageData(uid = 'net.fabricmc.fabric-loader', name = 'Fabric Loader') +sharedData = PolyMCSharedPackageData(uid='net.fabricmc.fabric-loader', name='Fabric Loader') sharedData.recommended = loaderRecommended sharedData.description = "Fabric Loader is a tool to load Fabric-compatible mods in game environments." sharedData.projectUrl = "https://fabricmc.net" @@ -86,7 +94,7 @@ for version in intermediaryVersions: with open(outFilepath, 'w') as outfile: json.dump(version.to_json(), outfile, sort_keys=True, indent=4) -sharedData = PolyMCSharedPackageData(uid = 'net.fabricmc.intermediary', name = 'Intermediary Mappings') +sharedData = PolyMCSharedPackageData(uid='net.fabricmc.intermediary', name='Intermediary Mappings') sharedData.recommended = intermediaryRecommended sharedData.description = "Intermediary mappings allow using Fabric Loader with mods for Minecraft in a more compatible manner." sharedData.projectUrl = "https://fabricmc.net" diff --git a/generateForge.py b/generateForge.py index 7be9f43..b464f9d 100755 --- a/generateForge.py +++ b/generateForge.py @@ -8,11 +8,15 @@ from metautil import * PMC_DIR = os.environ["PMC_DIR"] UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] + def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) + # Contruct a set of libraries out of a Minecraft version file, for filtering. mcVersionCache = {} + + def loadMcVersionFilter(version): if version in mcVersionCache: return mcVersionCache[version] @@ -24,11 +28,14 @@ def loadMcVersionFilter(version): mcVersionCache[version] = libSet return libSet + ''' Match a library coordinate to a set of library coordinates. * Block those that pass completely. * For others, block those with lower versions than in the set. ''' + + def shouldIgnoreArtifact(libSet, match): for ver in libSet: if ver.group == match.group and ver.artifact == match.artifact and ver.classifier == match.classifier: @@ -45,8 +52,9 @@ def shouldIgnoreArtifact(libSet, match): # No match found in the set - we need to keep this return False + def versionFromProfile(profile, version): - result = PolyMCVersionFile({"name":"Forge", "version":version.rawVersion, "uid":"net.minecraftforge" }) + result = PolyMCVersionFile({"name": "Forge", "version": version.rawVersion, "uid": "net.minecraftforge"}) mcversion = profile.install.minecraft result.requires = [DependencyEntry(uid='net.minecraft', equals=mcversion)] result.mainClass = profile.versionInfo.mainClass @@ -85,16 +93,17 @@ def versionFromProfile(profile, version): ourLib.url = "https://maven.minecraftforge.net/" else: ourLib.url = forgeLib.url - #if forgeLib.checksums and len(forgeLib.checksums) == 2: + # 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 : MojangVersionFile, version: ForgeVersion): + +def versionFromModernizedInstaller(installerVersion: MojangVersionFile, version: ForgeVersion): eprint("Generating Modernized Forge %s." % version.longVersion) - result = PolyMCVersionFile({"name":"Forge", "version":version.rawVersion, "uid":"net.minecraftforge" }) + result = PolyMCVersionFile({"name": "Forge", "version": version.rawVersion, "uid": "net.minecraftforge"}) mcversion = version.mcversion result.requires = [DependencyEntry(uid='net.minecraft', equals=mcversion)] result.mainClass = installerVersion.mainClass @@ -146,8 +155,9 @@ def versionFromModernizedInstaller(installerVersion : MojangVersionFile, version result.order = 5 return result -def versionFromLegacy(version, legacyinfo : ForgeLegacyInfo): - result = PolyMCVersionFile({"name":"Forge", "version":version.rawVersion, "uid":"net.minecraftforge" }) + +def versionFromLegacy(version, legacyinfo: ForgeLegacyInfo): + result = PolyMCVersionFile({"name": "Forge", "version": version.rawVersion, "uid": "net.minecraftforge"}) mcversion = version.mcversion_sane result.requires = [DependencyEntry(uid='net.minecraft', equals=mcversion)] result.releaseTime = legacyinfo.releaseTime @@ -160,8 +170,8 @@ def versionFromLegacy(version, legacyinfo : ForgeLegacyInfo): classifier = "universal" else: classifier = "client" - coord = GradleSpecifier("net.minecraftforge:forge:%s:%s" % (version.longVersion,classifier)) - mainmod = PolyMCLibrary(name = coord) + coord = GradleSpecifier("net.minecraftforge:forge:%s:%s" % (version.longVersion, classifier)) + mainmod = PolyMCLibrary(name=coord) mainmod.downloads = MojangLibraryDownloads() mainmod.downloads.artifact = MojangArtifact() mainmod.downloads.artifact.path = None @@ -171,9 +181,11 @@ def versionFromLegacy(version, legacyinfo : ForgeLegacyInfo): result.jarMods = [mainmod] return result -def versionFromBuildSystemInstaller(installerVersion : MojangVersionFile, installerProfile: ForgeInstallerProfileV2, version: ForgeVersion): + +def versionFromBuildSystemInstaller(installerVersion: MojangVersionFile, installerProfile: ForgeInstallerProfileV2, + version: ForgeVersion): eprint("Generating Forge %s." % version.longVersion) - result = PolyMCVersionFile({"name":"Forge", "version":version.rawVersion, "uid":"net.minecraftforge" }) + result = PolyMCVersionFile({"name": "Forge", "version": version.rawVersion, "uid": "net.minecraftforge"}) result.requires = [DependencyEntry(uid='net.minecraft', equals=version.mcversion_sane)] result.mainClass = "io.github.zekerzhayard.forgewrapper.installer.Main" @@ -183,10 +195,12 @@ def versionFromBuildSystemInstaller(installerVersion : MojangVersionFile, instal # load the locally cached installer file info and use it to add the installer entry in the json with open(UPSTREAM_DIR + "/forge/installer_info/%s.json" % version.longVersion, 'r', encoding='utf-8') as f: installerInfo = InstallerInfo(json.load(f)) - InstallerLib = PolyMCLibrary(name=GradleSpecifier("net.minecraftforge:forge:%s:installer" % (version.longVersion))) + InstallerLib = PolyMCLibrary( + name=GradleSpecifier("net.minecraftforge:forge:%s:installer" % (version.longVersion))) InstallerLib.downloads = MojangLibraryDownloads() InstallerLib.downloads.artifact = MojangArtifact() - InstallerLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % (InstallerLib.name.getPath()) + InstallerLib.downloads.artifact.url = "https://files.minecraftforge.net/maven/%s" % ( + InstallerLib.name.getPath()) InstallerLib.downloads.artifact.sha1 = installerInfo.sha1hash InstallerLib.downloads.artifact.size = installerInfo.size mavenLibs.append(InstallerLib) @@ -206,61 +220,61 @@ def versionFromBuildSystemInstaller(installerVersion : MojangVersionFile, instal result.mavenFiles = mavenLibs libraries = [] - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.4.1")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "82f01de97e29ba34be9fc628084b6d10ce2235c5" - #wrapperLib.downloads.artifact.size = 14351 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.4.1")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "82f01de97e29ba34be9fc628084b6d10ce2235c5" + # wrapperLib.downloads.artifact.size = 14351 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.4.2")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "79ff9c1530e8743450c5c3ebc6e07b535437aa6e" - #wrapperLib.downloads.artifact.size = 22346 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.4.2")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "79ff9c1530e8743450c5c3ebc6e07b535437aa6e" + # wrapperLib.downloads.artifact.size = 22346 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.1")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "90104e9aaa8fbedf6c3d1f6d0b90cabce080b5a9" - #wrapperLib.downloads.artifact.size = 29892 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.1")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "90104e9aaa8fbedf6c3d1f6d0b90cabce080b5a9" + # wrapperLib.downloads.artifact.size = 29892 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.3")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "2b0e06937349a209dbb90dca6381258daa456ad7" - #wrapperLib.downloads.artifact.size = 30486 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.3")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "2b0e06937349a209dbb90dca6381258daa456ad7" + # wrapperLib.downloads.artifact.size = 30486 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.4")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "e97805af76d4c1cebb753132eadbabd92e67a17b" - #wrapperLib.downloads.artifact.size = 34299 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.4")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "e97805af76d4c1cebb753132eadbabd92e67a17b" + # wrapperLib.downloads.artifact.size = 34299 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:pmc1")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "e8e0fe708742ecf15ab4af55ae8227fa4349362d" - #wrapperLib.downloads.artifact.size = 34628 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:pmc1")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "e8e0fe708742ecf15ab4af55ae8227fa4349362d" + # wrapperLib.downloads.artifact.size = 34628 + # libraries.append(wrapperLib) - #wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.5")) - #wrapperLib.downloads = MojangLibraryDownloads() - #wrapperLib.downloads.artifact = MojangArtifact() - #wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) - #wrapperLib.downloads.artifact.sha1 = "566dfd60aacffaa02884614835f1151d36f1f985" - #wrapperLib.downloads.artifact.size = 34331 - #libraries.append(wrapperLib) + # wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:1.5.5")) + # wrapperLib.downloads = MojangLibraryDownloads() + # wrapperLib.downloads.artifact = MojangArtifact() + # wrapperLib.downloads.artifact.url = "https://meta.polymc.org/maven/%s" % (wrapperLib.name.getPath()) + # wrapperLib.downloads.artifact.sha1 = "566dfd60aacffaa02884614835f1151d36f1f985" + # wrapperLib.downloads.artifact.size = 34331 + # libraries.append(wrapperLib) wrapperLib = PolyMCLibrary(name=GradleSpecifier("io.github.zekerzhayard:ForgeWrapper:pmc2")) wrapperLib.downloads = MojangLibraryDownloads() @@ -347,26 +361,26 @@ legacyVersions = [ for id, entry in remoteVersionlist.versions.items(): if entry.mcversion == None: - eprint ("Skipping %s with invalid MC version" % id) + eprint("Skipping %s with invalid MC version" % id) continue version = ForgeVersion(entry) if version.url() == None: - eprint ("Skipping %s with no valid files" % id) + eprint("Skipping %s with no valid files" % id) continue - eprint ("Processing Forge %s" % version.rawVersion) + eprint("Processing Forge %s" % version.rawVersion) versionElements = version.rawVersion.split('.') if len(versionElements) < 1: - eprint ("Skipping version %s with not enough version elements" % (id)) + eprint("Skipping version %s with not enough version elements" % (id)) continue majorVersionStr = versionElements[0] if not majorVersionStr.isnumeric(): - eprint ("Skipping version %s with non-numeric major version %s" % (id, majorVersionStr)) + eprint("Skipping version %s with non-numeric major version %s" % (id, majorVersionStr)) continue majorVersion = int(majorVersionStr) - #if majorVersion >= 37: + # if majorVersion >= 37: # eprint ("Skipping unsupported major version %d (%s)" % (majorVersion, id)) # continue @@ -375,7 +389,7 @@ for id, entry in remoteVersionlist.versions.items(): # If we do not have the corresponding Minecraft version, we ignore it if not os.path.isfile(PMC_DIR + "/net.minecraft/%s.json" % version.mcversion_sane): - eprint ("Skipping %s with no corresponding Minecraft version %s" % (id, version.mcversion_sane)) + eprint("Skipping %s with no corresponding Minecraft version %s" % (id, version.mcversion_sane)) continue outVersion = None @@ -399,7 +413,7 @@ for id, entry in remoteVersionlist.versions.items(): # 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) + eprint("Skipping %s with missing profile json" % id) continue with open(profileFilepath, 'r', encoding='utf-8') as profileFile: profile = ForgeInstallerProfile(json.load(profileFile)) @@ -421,9 +435,9 @@ for id, entry in remoteVersionlist.versions.items(): recommendedVersions.sort() -print ('Recommended versions:', recommendedVersions) +print('Recommended versions:', recommendedVersions) -sharedData = PolyMCSharedPackageData(uid = 'net.minecraftforge', name = "Forge") +sharedData = PolyMCSharedPackageData(uid='net.minecraftforge', name="Forge") sharedData.projectUrl = 'https://www.minecraftforge.net/forum/' sharedData.recommended = recommendedVersions sharedData.write() diff --git a/generateLiteloader.py b/generateLiteloader.py index b7834eb..3854aa8 100755 --- a/generateLiteloader.py +++ b/generateLiteloader.py @@ -3,13 +3,16 @@ from liteloaderutil import * PMC_DIR = os.environ["PMC_DIR"] UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] + # load the locally cached version list def loadLiteloaderJson(): with open(UPSTREAM_DIR + "/liteloader/versions.json", 'r', encoding='utf-8') as f: return LiteloaderIndex(json.load(f)) + remoteVersionlist = loadLiteloaderJson() + def processArtefacts(mcVersion, liteloader, notSnapshots): versions = [] lookup = {} @@ -39,7 +42,7 @@ def processArtefacts(mcVersion, liteloader, notSnapshots): lib.url = "http://repo.liteloader.com/" liteloaderLib = PolyMCLibrary( name=GradleSpecifier("com.mumfrey:liteloader:%s" % version.version), - url = "http://dl.liteloader.com/versions/" + url="http://dl.liteloader.com/versions/" ) if not notSnapshots: liteloaderLib.mmcHint = "always-stale" @@ -50,6 +53,7 @@ def processArtefacts(mcVersion, liteloader, notSnapshots): latest = lookup[latestVersion] return versions, latest + allVersions = [] recommended = [] for mcVersion, versionObject in remoteVersionlist.versions.items(): @@ -78,7 +82,7 @@ for version in allVersions: with open(outFilepath, 'w') as outfile: json.dump(version.to_json(), outfile, sort_keys=True, indent=4) -sharedData = PolyMCSharedPackageData(uid = 'com.mumfrey.liteloader', name = 'LiteLoader') +sharedData = PolyMCSharedPackageData(uid='com.mumfrey.liteloader', name='LiteLoader') sharedData.recommended = recommended sharedData.description = remoteVersionlist.meta.description sharedData.projectUrl = remoteVersionlist.meta.url diff --git a/generateMojang.py b/generateMojang.py index a5666f4..45fcbd5 100755 --- a/generateMojang.py +++ b/generateMojang.py @@ -25,32 +25,33 @@ LOG4J_HASHES = { "sha1": "ca499d751f4ddd8afb016ef698c30be0da1d09f7", "size": 21268 } -}; +} # LWJGL versions we want passVariants = [ - "41d3ed7a755d15ad9e2f5a8aea51481858d60763", # 3.2.2 (2021-12-10 03:36:38+00:00) - "57455f0bb479e07e5b554766f9f0310a6c245e10", # 3.1.2 (2018-06-21 12:57:11+00:00) - "abfbb7905498983ab3300ae2b897ccd3c11ab8bb", # 2.9.0 (2013-10-21 16:34:47+00:00) - "47fd9d3677d7a0bcdb280453a7e7ac1fdbdab70d", # 2.9.4-nightly-20150209 (2016-12-20 14:05:34+00:00) - "8ee2407d76c3af7882ab897b6ef25392839d2ab0", # 3.1.6 (2019-04-18 11:05:19+00:00) - "428282d96ee546aae07d0717fef71ab8213d1176", # 3.2.1 (2019-04-18 11:05:19+00:00) - "c7a84795ac3197bb476949665f3eda9c79436cf7", # 2.9.1 (2014-05-22 14:44:33+00:00) - "66a60d78abe20960f1befd0fd5819a8855100055", # 2.9.1-nightly-20131120 (2013-12-06 13:55:34+00:00) - "15a92ddad26186e720117fc0e318c6ddb8bae14e", # 2.9.3 (2015-01-30 11:58:24+00:00) + "41d3ed7a755d15ad9e2f5a8aea51481858d60763", # 3.2.2 (2021-12-10 03:36:38+00:00) + "57455f0bb479e07e5b554766f9f0310a6c245e10", # 3.1.2 (2018-06-21 12:57:11+00:00) + "abfbb7905498983ab3300ae2b897ccd3c11ab8bb", # 2.9.0 (2013-10-21 16:34:47+00:00) + "47fd9d3677d7a0bcdb280453a7e7ac1fdbdab70d", # 2.9.4-nightly-20150209 (2016-12-20 14:05:34+00:00) + "8ee2407d76c3af7882ab897b6ef25392839d2ab0", # 3.1.6 (2019-04-18 11:05:19+00:00) + "428282d96ee546aae07d0717fef71ab8213d1176", # 3.2.1 (2019-04-18 11:05:19+00:00) + "c7a84795ac3197bb476949665f3eda9c79436cf7", # 2.9.1 (2014-05-22 14:44:33+00:00) + "66a60d78abe20960f1befd0fd5819a8855100055", # 2.9.1-nightly-20131120 (2013-12-06 13:55:34+00:00) + "15a92ddad26186e720117fc0e318c6ddb8bae14e", # 2.9.3 (2015-01-30 11:58:24+00:00) ] # LWJGL versions we def. don't want! badVariants = [ - "089446ef48f6ac70a3e2bc4a02cd1f34060d31bd", # 3.2.2 (2021-08-25 14:41:57+00:00) - "6a0aaa55846ebccae9cf69e1ac2e284b3f0d81d0", # 3.2.2 (2019-07-19 09:25:47+00:00) - "e3ecb31817e009ebfb3a8ed41b7b779d31e55b43", # 3.2.2 (2019-07-04 14:41:05+00:00) - "2d0b7aa8397278c5b5f7e9cd025544af5e820072", # 2.9.0 (2013-09-06 12:31:58+00:00) - "905c3a9d80a804c2d03a577775b75f45c1837263", # 2.9.0 (2011-03-30 22:00:00+00:00) - "d889b127fbabd3493115beb228730146072549a4", # 3.1.6 (2018-11-29 13:11:38+00:00) - "0034e86cec334f9142ca4ace843c91eb649017fd", # 3.2.1 (2019-02-13 16:12:08+00:00) + "089446ef48f6ac70a3e2bc4a02cd1f34060d31bd", # 3.2.2 (2021-08-25 14:41:57+00:00) + "6a0aaa55846ebccae9cf69e1ac2e284b3f0d81d0", # 3.2.2 (2019-07-19 09:25:47+00:00) + "e3ecb31817e009ebfb3a8ed41b7b779d31e55b43", # 3.2.2 (2019-07-04 14:41:05+00:00) + "2d0b7aa8397278c5b5f7e9cd025544af5e820072", # 2.9.0 (2013-09-06 12:31:58+00:00) + "905c3a9d80a804c2d03a577775b75f45c1837263", # 2.9.0 (2011-03-30 22:00:00+00:00) + "d889b127fbabd3493115beb228730146072549a4", # 3.1.6 (2018-11-29 13:11:38+00:00) + "0034e86cec334f9142ca4ace843c91eb649017fd", # 3.2.1 (2019-02-13 16:12:08+00:00) ] + def addOrGetBucket(buckets, rules): ruleHash = None if rules: @@ -71,18 +72,22 @@ def addOrGetBucket(buckets, rules): buckets[ruleHash] = bucket return bucket + def hashVersion(lwjgl): lwjglObjectCopy = copy.deepcopy(lwjgl) lwjglObjectCopy.releaseTime = datetime.datetime.fromtimestamp(0) return hashlib.sha1(json.dumps(lwjglObjectCopy.to_json(), sort_keys=True).encode("utf-8", "strict")).hexdigest() + def sort_libs_by_name(library): return library.name + LWJGLEntry = namedtuple('LWJGLEntry', ('version', 'sha1')) lwjglVersionVariants = defaultdict(list) + def addLWJGLVersion(versionVariants, lwjglObject): lwjglObjectCopy = copy.deepcopy(lwjglObject) libraries = list(lwjglObjectCopy.libraries) @@ -101,6 +106,7 @@ def addLWJGLVersion(versionVariants, lwjglObject): print("!!! New variant for LWJGL version %s" % (lwjglVersion)) versionVariants[lwjglVersion].append(LWJGLEntry(version=lwjglObjectCopy, sha1=lwjglObjectHash)) + def removePathsFromLib(lib): if pmcLib.downloads.artifact: pmcLib.downloads.artifact.path = None @@ -108,6 +114,7 @@ def removePathsFromLib(lib): for key, value in pmcLib.downloads.classifiers.items(): value.path = None + def adaptNewStyleArguments(arguments): outarr = [] # we ignore the jvm arguments entirely. @@ -128,10 +135,11 @@ def adaptNewStyleArguments(arguments): pprint(arg) return ' '.join(outarr) + def isOnlyMacOS(rules, specifier): allowsOSX = False allowsAll = False - #print("Considering", specifier, "rules", rules) + # print("Considering", specifier, "rules", rules) if rules: for rule in rules: if rule.action == "allow" and rule.os and rule.os.name == "osx": @@ -169,7 +177,7 @@ for filename in os.listdir(UPSTREAM_DIR + '/mojang/versions'): rules = pmcLib.rules pmcLib.rules = None if isOnlyMacOS(rules, specifier): - print("Candidate library ", specifier, " is only for macOS and is therefore ignored.") + print("Candidate library ", specifier, " is only for macOS and is therefore ignored.") continue bucket = addOrGetBucket(buckets, rules) if specifier.group == "org.lwjgl.lwjgl" and specifier.artifact == "lwjgl": @@ -185,7 +193,8 @@ for filename in os.listdir(UPSTREAM_DIR + '/mojang/versions'): else: # FIXME: workaround for insane log4j nonsense from December 2021. Probably needs adjustment. if pmcLib.name.isLog4j(): - replacementLib = PolyMCLibrary(name=GradleSpecifier("org.apache.logging.log4j:%s:%s" % (pmcLib.name.artifact, LOG4J_VERSION_OVERRIDE))) + replacementLib = PolyMCLibrary(name=GradleSpecifier( + "org.apache.logging.log4j:%s:%s" % (pmcLib.name.artifact, LOG4J_VERSION_OVERRIDE))) replacementLib.downloads = MojangLibraryDownloads() replacementLib.downloads.artifact = MojangArtifact() replacementLib.downloads.artifact.url = LOG4J_MAVEN_REPO % (replacementLib.name.getPath()) @@ -258,10 +267,11 @@ for filename in os.listdir(UPSTREAM_DIR + '/mojang/versions'): versionFile.minecraftArguments = adaptNewStyleArguments(mojangVersionFile.arguments) filenameOut = PMC_DIR + "/net.minecraft/%s.json" % versionFile.version if versionFile.version in staticVersionlist.versions: - ApplyLegacyOverride (versionFile, staticVersionlist.versions[versionFile.version]) + ApplyLegacyOverride(versionFile, staticVersionlist.versions[versionFile.version]) with open(filenameOut, 'w') as outfile: json.dump(versionFile.to_json(), outfile, sort_keys=True, indent=4) + def processSingleVariant(lwjglVariant): lwjglVersion = lwjglVariant.version versionObj = copy.deepcopy(lwjglVariant) @@ -276,7 +286,8 @@ def processSingleVariant(lwjglVariant): versionObj.uid = 'org.lwjgl3' versionObj.conflicts = [DependencyEntry(uid='org.lwjgl')] # remove jutils and jinput from LWJGL 3 -- this is a dependency that Mojang kept in, but doesn't belong there anymore - filteredLibraries = list(filter(lambda lib: not lib.name.artifact in ["jutils", "jinput"], versionObj.libraries)) + filteredLibraries = list( + filter(lambda lib: not lib.name.artifact in ["jutils", "jinput"], versionObj.libraries)) versionObj.libraries = filteredLibraries else: raise Exception("LWJGL version not recognized: %s" % versionObj.version) @@ -296,7 +307,8 @@ def processSingleVariant(lwjglVariant): for entry in checkedDict: bakedEntry = lib.natives[entry] if not bakedEntry in lib.downloads.classifiers: - print("Missing download for classifier!", versionObj.version, lib.name, bakedEntry, lib.downloads.classifiers.keys()) + print("Missing download for classifier!", versionObj.version, lib.name, bakedEntry, + lib.downloads.classifiers.keys()) good = False break if good: @@ -322,27 +334,28 @@ for lwjglVersionVariant in lwjglVersionVariants: passedVariants += 1 continue - print(f" \"{variant.sha1}\", # {lwjglVersionVariant} ({variant.version.releaseTime})") + print(f" \"{variant.sha1}\", # {lwjglVersionVariant} ({variant.version.releaseTime})") unknownVariants += 1 print("") if decidedVariant and passedVariants == 1 and unknownVariants == 0: processSingleVariant(decidedVariant.version) else: - raise Exception("No variant decided for version %s out of %d possible ones and %d unknown ones." % (lwjglVersionVariant, passedVariants, unknownVariants)) + raise Exception("No variant decided for version %s out of %d possible ones and %d unknown ones." % ( + lwjglVersionVariant, passedVariants, unknownVariants)) -lwjglSharedData = PolyMCSharedPackageData(uid = 'org.lwjgl', name = 'LWJGL 2') +lwjglSharedData = PolyMCSharedPackageData(uid='org.lwjgl', name='LWJGL 2') lwjglSharedData.recommended = ['2.9.4-nightly-20150209'] lwjglSharedData.write() if found_any_lwjgl3: - lwjglSharedData = PolyMCSharedPackageData(uid = 'org.lwjgl3', name = 'LWJGL 3') + lwjglSharedData = PolyMCSharedPackageData(uid='org.lwjgl3', name='LWJGL 3') lwjglSharedData.recommended = ['3.1.2'] lwjglSharedData.write() with open(UPSTREAM_DIR + "/mojang/version_manifest_v2.json", 'r', encoding='utf-8') as localIndexFile: localVersionlist = MojangIndexWrap(json.load(localIndexFile)) -mcSharedData = PolyMCSharedPackageData(uid = 'net.minecraft', name = 'Minecraft') +mcSharedData = PolyMCSharedPackageData(uid='net.minecraft', name='Minecraft') mcSharedData.recommended = [localVersionlist.latest['release']] mcSharedData.write() diff --git a/index.py b/index.py index 09eda05..8a989d4 100755 --- a/index.py +++ b/index.py @@ -5,6 +5,7 @@ from metautil import * PMC_DIR = os.environ["PMC_DIR"] + # take the hash type (like hashlib.md5) and filename, return hex string of hash def HashFile(hash, fname): hash_instance = hash() @@ -13,6 +14,7 @@ def HashFile(hash, fname): hash_instance.update(chunk) return hash_instance.hexdigest() + # ignore these files when indexing versions ignore = set(["index.json", "package.json", ".git"]) @@ -69,12 +71,12 @@ for package in sorted(os.listdir(PMC_DIR)): # insert entry into the package index packageEntry = PolyMCPackageIndexEntry( - { - "uid" : package, - "name" : sharedData.name, - "sha256": HashFile(hashlib.sha256, outFilePath) - } - ) + { + "uid": package, + "name": sharedData.name, + "sha256": HashFile(hashlib.sha256, outFilePath) + } + ) packages.packages.append(packageEntry) # write the repository package index diff --git a/jsonobject/api.py b/jsonobject/api.py index 641967d..8b9c476 100644 --- a/jsonobject/api.py +++ b/jsonobject/api.py @@ -8,7 +8,6 @@ import datetime from . import properties import re - re_date = re.compile(r'^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])$') re_time = re.compile( r'^([01]\d|2[0-3])\D?([0-5]\d)\D?([0-5]\d)?\D?(\d{3,6})?$') diff --git a/jsonobject/base.py b/jsonobject/base.py index afd5f3e..90a5f44 100644 --- a/jsonobject/base.py +++ b/jsonobject/base.py @@ -10,7 +10,6 @@ from .exceptions import ( from .base_properties import JsonProperty, DefaultProperty from .utils import check_type - JsonObjectClassSettings = namedtuple('JsonObjectClassSettings', ['type_config']) CLASS_SETTINGS_ATTR = '_$_class_settings' @@ -60,6 +59,7 @@ class TypeConfig(object): instead of the default. """ + def __init__(self, properties=None, string_conversions=None): self._properties = properties if properties is not None else {} @@ -108,11 +108,11 @@ class TypeConfig(object): result.append((pattern, conversion)) return result + META_ATTRS = ('properties', 'string_conversions', 'update_properties') class JsonObjectMeta(type): - class Meta(object): pass @@ -181,7 +181,6 @@ class _JsonObjectPrivateInstanceVariables(object): @six.add_metaclass(JsonObjectMeta) class JsonObjectBase(object): - _allow_dynamic_properties = False _validate_required_lazily = False @@ -305,9 +304,9 @@ class JsonObjectBase(object): def __is_dynamic_property(self, name): return ( - name not in self._properties_by_attr and - not name.startswith('_') and - not inspect.isdatadescriptor(getattr(self.__class__, name, None)) + name not in self._properties_by_attr and + not name.startswith('_') and + not inspect.isdatadescriptor(getattr(self.__class__, name, None)) ) def __setattr__(self, name, value): diff --git a/jsonobject/base_properties.py b/jsonobject/base_properties.py index 93b631c..72b0ed7 100644 --- a/jsonobject/base_properties.py +++ b/jsonobject/base_properties.py @@ -13,7 +13,6 @@ else: class JsonProperty(object): - default = None type_config = None @@ -124,7 +123,6 @@ class JsonProperty(object): class JsonContainerProperty(JsonProperty): - _type = default = None container_class = None @@ -259,7 +257,7 @@ class DefaultProperty(JsonProperty): if convert is not None: try: - #sometimes regex fail so return value + # sometimes regex fail so return value value = convert(value) except Exception: pass @@ -290,7 +288,6 @@ class AssertTypeProperty(JsonProperty): class AbstractDateProperty(JsonProperty): - _type = None def __init__(self, exact=False, *args, **kwargs): diff --git a/jsonobject/containers.py b/jsonobject/containers.py index 14dc5bd..1150ab9 100644 --- a/jsonobject/containers.py +++ b/jsonobject/containers.py @@ -3,6 +3,7 @@ from .base_properties import DefaultProperty from .utils import check_type, SimpleDict import copy + class JsonArray(list): def __init__(self, _obj=None, wrapper=None, type_config=None): super(JsonArray, self).__init__() @@ -12,8 +13,8 @@ class JsonArray(list): assert type_config is not None self._type_config = type_config self._wrapper = ( - wrapper or - DefaultProperty(type_config=self._type_config) + wrapper or + DefaultProperty(type_config=self._type_config) ) for item in self._obj: super(JsonArray, self).append(self._wrapper.wrap(item)) @@ -118,8 +119,8 @@ class JsonDict(SimpleDict): assert type_config is not None self._type_config = type_config self._wrapper = ( - wrapper or - DefaultProperty(type_config=self._type_config) + wrapper or + DefaultProperty(type_config=self._type_config) ) for key, value in self._obj.items(): self[key] = self.__wrap(key, value) @@ -161,8 +162,8 @@ class JsonSet(set): assert type_config is not None self._type_config = type_config self._wrapper = ( - wrapper or - DefaultProperty(type_config=self._type_config) + wrapper or + DefaultProperty(type_config=self._type_config) ) for item in self._obj: super(JsonSet, self).add(self._wrapper.wrap(item)) diff --git a/jsonobject/properties.py b/jsonobject/properties.py index 8775e45..05bba86 100644 --- a/jsonobject/properties.py +++ b/jsonobject/properties.py @@ -14,7 +14,6 @@ from .base_properties import ( ) from .containers import JsonArray, JsonDict, JsonSet - if sys.version > '3': unicode = str long = int @@ -62,7 +61,6 @@ class DecimalProperty(JsonProperty): class DateProperty(AbstractDateProperty): - _type = datetime.date def _wrap(self, value): @@ -77,7 +75,6 @@ class DateProperty(AbstractDateProperty): class DateTimeProperty(AbstractDateProperty): - _type = datetime.datetime def _wrap(self, value): @@ -103,7 +100,6 @@ class DateTimeProperty(AbstractDateProperty): class TimeProperty(AbstractDateProperty): - _type = datetime.time def _wrap(self, value): @@ -124,7 +120,6 @@ class TimeProperty(AbstractDateProperty): class ObjectProperty(JsonContainerProperty): - default = lambda self: self.item_type() def wrap(self, obj, string_conversions=None): @@ -137,7 +132,6 @@ class ObjectProperty(JsonContainerProperty): class ListProperty(JsonContainerProperty): - _type = default = list container_class = JsonArray @@ -146,7 +140,6 @@ class ListProperty(JsonContainerProperty): class DictProperty(JsonContainerProperty): - _type = default = dict container_class = JsonDict @@ -155,7 +148,6 @@ class DictProperty(JsonContainerProperty): class SetProperty(JsonContainerProperty): - _type = default = set container_class = JsonSet diff --git a/jsonobject/utils.py b/jsonobject/utils.py index 0e052bf..9ee8569 100644 --- a/jsonobject/utils.py +++ b/jsonobject/utils.py @@ -16,6 +16,7 @@ class SimpleDict(dict): Re-implements destructive methods of dict to use only setitem and getitem and delitem """ + def update(self, E=None, **F): for dct in (E, F): if dct: diff --git a/liteloaderutil.py b/liteloaderutil.py index 54f7a11..2e86e8a 100644 --- a/liteloaderutil.py +++ b/liteloaderutil.py @@ -1,6 +1,5 @@ from metautil import * - ''' "repo":{ "stream":"RELEASE", @@ -9,12 +8,15 @@ from metautil import * "classifier":"" }, ''' + + class LiteloaderRepo(JsonObject): stream = StringProperty(required=True) type = StringProperty(required=True) url = StringProperty(required=True) classifier = StringProperty(required=True) + ''' "53639d52340479ccf206a04f5e16606f":{ "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", @@ -36,6 +38,8 @@ class LiteloaderRepo(JsonObject): "timestamp":"1367366420" }, ''' + + class LiteloaderArtefact(JsonObject): tweakClass = StringProperty(required=True) libraries = ListProperty(PolyMCLibrary, required=True) @@ -48,21 +52,26 @@ class LiteloaderArtefact(JsonObject): srcJar = StringProperty(default=None, exclude_if_none=True) mcpJar = StringProperty(default=None, exclude_if_none=True) + class LiteloaderDev(JsonObject): - fgVersion = StringProperty(default=None ,exclude_if_none=True) + fgVersion = StringProperty(default=None, exclude_if_none=True) mappings = StringProperty(required=None, exclude_if_none=True) mcp = StringProperty(default=None, exclude_if_none=True) + class LiteloaderArtefacts(JsonObject): liteloader = DictProperty(LiteloaderArtefact, name="com.mumfrey:liteloader", required=True) + class LiteloaderSnapshot(LiteloaderArtefact): lastSuccessfulBuild = IntegerProperty() + class LiteloaderSnapshots(JsonObject): libraries = ListProperty(PolyMCLibrary, required=True) liteloader = DictProperty(LiteloaderSnapshot, name="com.mumfrey:liteloader", required=True) + ''' "1.10.2":{ "dev": { ... }, @@ -75,12 +84,15 @@ class LiteloaderSnapshots(JsonObject): ... } ''' + + class LiteloaderEntry(JsonObject): dev = ObjectProperty(LiteloaderDev, default=None, exclude_if_none=True) repo = ObjectProperty(LiteloaderRepo, required=True) artefacts = ObjectProperty(LiteloaderArtefacts, default=None, exclude_if_none=True) snapshots = ObjectProperty(LiteloaderSnapshots, default=None, exclude_if_none=True) + ''' "meta":{ "description":"LiteLoader is a lightweight mod bootstrap designed to provide basic loader functionality for mods which don't need to modify game mechanics.", @@ -90,6 +102,8 @@ class LiteloaderEntry(JsonObject): "updatedTime":1487763247 }, ''' + + class LiteloaderMeta(JsonObject): description = StringProperty(required=True) authors = StringProperty(required=True) @@ -97,6 +111,7 @@ class LiteloaderMeta(JsonObject): updated = ISOTimestampProperty(required=True) updatedTime = IntegerProperty(required=True) + # The raw Forge version index class LiteloaderIndex(JsonObject): meta = ObjectProperty(LiteloaderMeta, required=True) diff --git a/metautil.py b/metautil.py index 3515ca2..8666e98 100644 --- a/metautil.py +++ b/metautil.py @@ -7,8 +7,8 @@ from jsonobject import * PMC_DIR = os.environ["PMC_DIR"] -class ISOTimestampProperty(AbstractDateProperty): +class ISOTimestampProperty(AbstractDateProperty): _type = datetime.datetime def _wrap(self, value): @@ -63,12 +63,11 @@ class GradleSpecifier: return "%s-%s.%s" % (self.artifact, self.version, self.extension) def getBase(self): - return "%s/%s/%s/" % (self.group.replace('.','/'), self.artifact, self.version) + return "%s/%s/%s/" % (self.group.replace('.', '/'), self.artifact, self.version) def getPath(self): return self.getBase() + self.getFilename() - def __repr__(self): return "GradleSpecifier('" + self.toString() + "')" @@ -78,7 +77,6 @@ class GradleSpecifier: def isLog4j(self): return self.group == "org.apache.logging.log4j" - def __lt__(self, other): return self.toString() < other.toString() @@ -91,6 +89,7 @@ class GradleSpecifier: def __hash__(self): return self.toString().__hash__() + class GradleSpecifierProperty(JsonProperty): def wrap(self, value): return GradleSpecifier(value) @@ -98,6 +97,7 @@ class GradleSpecifierProperty(JsonProperty): def unwrap(self, value): return value, value.toString() + ''' Mojang index files look like this: { @@ -119,6 +119,7 @@ Mojang index files look like this: } ''' + class MojangIndexEntry(JsonObject): id = StringProperty() releaseTime = ISOTimestampProperty() @@ -128,10 +129,12 @@ class MojangIndexEntry(JsonObject): sha1 = StringProperty(exclude_if_none=True, default=None) complianceLevel = IntegerProperty(exclude_if_none=True, default=None) + class MojangIndex(JsonObject): latest = DictProperty(StringProperty) versions = ListProperty(MojangIndexEntry) + class MojangIndexWrap: def __init__(self, json): self.index = MojangIndex.wrap(json) @@ -142,25 +145,30 @@ class MojangIndexWrap: self.versions = versionsDict -class MojangArtifactBase (JsonObject): +class MojangArtifactBase(JsonObject): sha1 = StringProperty(exclude_if_none=True, default=None) size = IntegerProperty(exclude_if_none=True, default=None) url = StringProperty() -class MojangArtifact (MojangArtifactBase): + +class MojangArtifact(MojangArtifactBase): path = StringProperty(exclude_if_none=True, default=None) -class MojangAssets (MojangArtifactBase): + +class MojangAssets(MojangArtifactBase): id = StringProperty() totalSize = IntegerProperty() + class MojangLibraryDownloads(JsonObject): artifact = ObjectProperty(MojangArtifact, exclude_if_none=True, default=None) classifiers = DictProperty(MojangArtifact, exclude_if_none=True, default=None) + class MojangLibraryExtractRules(JsonObject): exclude = ListProperty(StringProperty) + ''' "rules": [ { @@ -175,52 +183,64 @@ class MojangLibraryExtractRules(JsonObject): ] ''' -class OSRule (JsonObject): - name = StringProperty(choices=["osx", "linux", "windows"], required = True) + +class OSRule(JsonObject): + name = StringProperty(choices=["osx", "linux", "windows"], required=True) version = StringProperty(exclude_if_none=True, default=None) -class MojangRule (JsonObject): - action = StringProperty(choices=["allow", "disallow"], required = True) + +class MojangRule(JsonObject): + action = StringProperty(choices=["allow", "disallow"], required=True) os = ObjectProperty(OSRule, exclude_if_none=True, default=None) -class MojangLibrary (JsonObject): + +class MojangLibrary(JsonObject): extract = ObjectProperty(MojangLibraryExtractRules, exclude_if_none=True, default=None) - name = GradleSpecifierProperty(required = True) + name = GradleSpecifierProperty(required=True) downloads = ObjectProperty(MojangLibraryDownloads, exclude_if_none=True, default=None) natives = DictProperty(StringProperty, exclude_if_none=True, default=None) rules = ListProperty(MojangRule, exclude_if_none=True, default=None) -class MojangLoggingArtifact (MojangArtifactBase): + +class MojangLoggingArtifact(MojangArtifactBase): id = StringProperty() -class MojangLogging (JsonObject): - file = ObjectProperty(MojangLoggingArtifact, required = True) - argument = StringProperty(required = True) - type = StringProperty(required = True, choices=["log4j2-xml"]) -class MojangArguments (JsonObject): +class MojangLogging(JsonObject): + file = ObjectProperty(MojangLoggingArtifact, required=True) + argument = StringProperty(required=True) + type = StringProperty(required=True, choices=["log4j2-xml"]) + + +class MojangArguments(JsonObject): game = ListProperty(exclude_if_none=True, default=None) jvm = ListProperty(exclude_if_none=True, default=None) -class JavaVersion (JsonObject): + +class JavaVersion(JsonObject): component = StringProperty(default="jre-legacy") majorVersion = IntegerProperty(default=8) + class UnknownVersionException(Exception): """Exception raised for unknown Mojang version file format versions. Attributes: message -- explanation of the error """ + def __init__(self, message): self.message = message + def validateSupportedMojangVersion(version): supportedVersion = 21 if version > supportedVersion: - raise UnknownVersionException("Unsupported Mojang format version: %d. Max supported is: %d" % (version, supportedVersion)) + raise UnknownVersionException( + "Unsupported Mojang format version: %d. Max supported is: %d" % (version, supportedVersion)) -class MojangVersionFile (JsonObject): + +class MojangVersionFile(JsonObject): arguments = ObjectProperty(MojangArguments, exclude_if_none=True, default=None) assetIndex = ObjectProperty(MojangAssets, exclude_if_none=True, default=None) assets = StringProperty(exclude_if_none=True, default=None) @@ -230,7 +250,8 @@ class MojangVersionFile (JsonObject): mainClass = StringProperty(exclude_if_none=True, default=None) processArguments = StringProperty(exclude_if_none=True, default=None) minecraftArguments = StringProperty(exclude_if_none=True, default=None) - minimumLauncherVersion = IntegerProperty(exclude_if_none=True, default=None, validators=validateSupportedMojangVersion) + minimumLauncherVersion = IntegerProperty(exclude_if_none=True, default=None, + validators=validateSupportedMojangVersion) releaseTime = ISOTimestampProperty(exclude_if_none=True, default=None) time = ISOTimestampProperty(exclude_if_none=True, default=None) type = StringProperty(exclude_if_none=True, default=None) @@ -239,24 +260,32 @@ class MojangVersionFile (JsonObject): complianceLevel = IntegerProperty(exclude_if_none=True, default=None) javaVersion = ObjectProperty(JavaVersion, exclude_if_none=True, default=None) + CurrentPolyMCFormatVersion = 1 + + def validateSupportedPolyMCVersion(version): if version > CurrentPolyMCFormatVersion: - raise UnknownVersionException("Unsupported PolyMC format version: %d. Max supported is: %d" % (version, CurrentPolyMCFormatVersion)) + raise UnknownVersionException( + "Unsupported PolyMC format version: %d. Max supported is: %d" % (version, CurrentPolyMCFormatVersion)) -class PolyMCLibrary (MojangLibrary): + +class PolyMCLibrary(MojangLibrary): url = StringProperty(exclude_if_none=True, default=None) mmcHint = StringProperty(name="MMC-hint", exclude_if_none=True, default=None) # this is supposed to be MMC-hint! + class VersionedJsonObject(JsonObject): formatVersion = IntegerProperty(default=CurrentPolyMCFormatVersion, validators=validateSupportedPolyMCVersion) -class DependencyEntry (JsonObject): + +class DependencyEntry(JsonObject): uid = StringProperty(required=True) equals = StringProperty(exclude_if_none=True, default=None) suggests = StringProperty(exclude_if_none=True, default=None) -class PolyMCVersionFile (VersionedJsonObject): + +class PolyMCVersionFile(VersionedJsonObject): name = StringProperty(required=True) version = StringProperty(required=True) uid = StringProperty(required=True) @@ -277,18 +306,20 @@ class PolyMCVersionFile (VersionedJsonObject): addTweakers = ListProperty(StringProperty, name="+tweakers", exclude_if_none=True, default=None) order = IntegerProperty(exclude_if_none=True, default=None) + class UnknownComplianceLevelException(Exception): """Exception raised for unknown Mojang compliance level Attributes: message -- explanation of the error """ + def __init__(self, message): self.message = message # Convert Mojang version file object to a PolyMC version file object -def MojangToPolyMC (file, name, uid, version): +def MojangToPolyMC(file, name, uid, version): pmcFile = PolyMCVersionFile( { "name": name, @@ -327,9 +358,11 @@ def MojangToPolyMC (file, name, uid, version): pmcFile.addTraits = [] pmcFile.addTraits.append("XR:Initial") else: - raise UnknownComplianceLevelException("Unsupported Mojang compliance level: %d. Max supported is: %d" % (file.complianceLevel, maxSupportedLevel)) + raise UnknownComplianceLevelException("Unsupported Mojang compliance level: %d. Max supported is: %d" % ( + file.complianceLevel, maxSupportedLevel)) return pmcFile + class PolyMCSharedPackageData(VersionedJsonObject): name = StringProperty(required=True) uid = StringProperty(required=True) @@ -345,18 +378,21 @@ class PolyMCSharedPackageData(VersionedJsonObject): except EnvironmentError as e: print("Error while trying to save shared packaged data for %s:" % self.uid, e) + def writeSharedPackageData(uid, name): desc = PolyMCSharedPackageData({ 'name': name, 'uid': uid - }) + }) with open(PMC_DIR + "/%s/package.json" % uid, 'w') as file: json.dump(desc.to_json(), file, sort_keys=True, indent=4) + def readSharedPackageData(uid): with open(PMC_DIR + "/%s/package.json" % uid, 'r') as file: return PolyMCSharedPackageData(json.load(file)) + class PolyMCVersionIndexEntry(JsonObject): version = StringProperty() type = StringProperty(exclude_if_none=True, default=None) @@ -367,19 +403,23 @@ class PolyMCVersionIndexEntry(JsonObject): volatile = BooleanProperty(exclude_if_none=True, default=None) sha256 = StringProperty() + class PolyMCVersionIndex(VersionedJsonObject): name = StringProperty() uid = StringProperty() versions = ListProperty(PolyMCVersionIndexEntry) + class PolyMCPackageIndexEntry(JsonObject): name = StringProperty() uid = StringProperty() sha256 = StringProperty() + class PolyMCPackageIndex(VersionedJsonObject): packages = ListProperty(PolyMCPackageIndexEntry) + ''' The PolyMC static override file for legacy looks like this: { @@ -399,16 +439,19 @@ The PolyMC static override file for legacy looks like this: } ''' + class LegacyOverrideEntry(JsonObject): releaseTime = ISOTimestampProperty(exclude_if_none=True, default=None) mainClass = StringProperty(exclude_if_none=True, default=None) appletClass = StringProperty(exclude_if_none=True, default=None) addTraits = ListProperty(StringProperty, name="+traits", exclude_if_none=True, default=None) + class LegacyOverrideIndex(JsonObject): versions = DictProperty(LegacyOverrideEntry) -def ApplyLegacyOverride (pmcFile, legacyOverride): + +def ApplyLegacyOverride(pmcFile, legacyOverride): # simply hard override classes pmcFile.mainClass = legacyOverride.mainClass pmcFile.appletClass = legacyOverride.appletClass diff --git a/updateFabric.py b/updateFabric.py index 9635a44..95426f6 100755 --- a/updateFabric.py +++ b/updateFabric.py @@ -11,10 +11,12 @@ UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] forever_cache = FileCache('caches/http_cache', forever=True) sess = CacheControl(requests.Session(), forever_cache) + def mkdirs(path): if not os.path.exists(path): os.makedirs(path) + def filehash(filename, hashtype, blocksize=65536): hash = hashtype() with open(filename, "rb") as f: @@ -22,12 +24,14 @@ def filehash(filename, hashtype, blocksize=65536): hash.update(block) return hash.hexdigest() + def get_maven_url(mavenKey, server, ext): mavenParts = mavenKey.split(":", 3) mavenVerUrl = server + mavenParts[0].replace(".", "/") + "/" + mavenParts[1] + "/" + mavenParts[2] + "/" mavenUrl = mavenVerUrl + mavenParts[1] + "-" + mavenParts[2] + ext return mavenUrl + def get_json_file(path, url): with open(path, 'w', encoding='utf-8') as f: r = sess.get(url) @@ -36,6 +40,7 @@ def get_json_file(path, url): json.dump(version_json, f, sort_keys=True, indent=4) return version_json + def get_binary_file(path, url): with open(path, 'w', encoding='utf-8') as f: r = sess.get(url) @@ -44,6 +49,7 @@ def get_binary_file(path, url): for chunk in r.iter_content(chunk_size=128): f.write(chunk) + def compute_jar_file(path, url): jarPath = path + ".jar" get_binary_file(jarPath, url) @@ -62,13 +68,15 @@ def compute_jar_file(path, url): with open(path + ".json", 'w') as outfile: json.dump(data.to_json(), outfile, sort_keys=True, indent=4) + mkdirs(UPSTREAM_DIR + "/fabric/meta-v2") mkdirs(UPSTREAM_DIR + "/fabric/loader-installer-json") mkdirs(UPSTREAM_DIR + "/fabric/jars") # get the version list for each component we are interested in for component in ["intermediary", "loader"]: - index = get_json_file(UPSTREAM_DIR + "/fabric/meta-v2/" + component + ".json", "https://meta.fabricmc.net/v2/versions/" + component) + index = get_json_file(UPSTREAM_DIR + "/fabric/meta-v2/" + component + ".json", + "https://meta.fabricmc.net/v2/versions/" + component) for it in index: jarMavenUrl = get_maven_url(it["maven"], "https://maven.fabricmc.net/", ".jar") compute_jar_file(UPSTREAM_DIR + "/fabric/jars/" + it["maven"].replace(":", "."), jarMavenUrl) diff --git a/updateForge.py b/updateForge.py index ee0f5d4..9e82de7 100755 --- a/updateForge.py +++ b/updateForge.py @@ -18,9 +18,11 @@ from metautil import * UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] + def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) + def filehash(filename, hashtype, blocksize=65536): hash = hashtype() with open(filename, "rb") as f: @@ -28,6 +30,7 @@ def filehash(filename, hashtype, blocksize=65536): hash.update(block) return hash.hexdigest() + forever_cache = FileCache('caches/http_cache', forever=True) sess = CacheControl(requests.Session(), forever_cache) @@ -67,13 +70,15 @@ for promoKey, shortversion in promotions_json.get('promos').items(): continue elif match.group('promotion') == 'recommended': recommendedSet.add(shortversion) - print ('%s added to recommended set' % shortversion) + print('%s added to recommended set' % shortversion) elif match.group('promotion') == 'latest': pass else: assert False -versionExpression = re.compile("^(?P[0-9a-zA-Z_\\.]+)-(?P[0-9\\.]+\\.(?P[0-9]+))(-(?P[a-zA-Z0-9\\.]+))?$") +versionExpression = re.compile( + "^(?P[0-9a-zA-Z_\\.]+)-(?P[0-9\\.]+\\.(?P[0-9]+))(-(?P[a-zA-Z0-9\\.]+))?$") + def getSingleForgeFilesManifest(longversion): pathThing = UPSTREAM_DIR + "/forge/files_manifests/%s.json" % longversion @@ -81,7 +86,7 @@ def getSingleForgeFilesManifest(longversion): from_file = False if files_manifest_file.is_file(): with open(pathThing, 'r') as f: - files_json=json.load(f) + files_json = json.load(f) from_file = True else: fileUrl = 'https://files.minecraftforge.net/net/minecraftforge/forge/%s/meta.json' % longversion @@ -138,6 +143,7 @@ def getSingleForgeFilesManifest(longversion): return retDict + print("") print("Making dirs...") os.makedirs(UPSTREAM_DIR + "/forge/jars/", exist_ok=True) @@ -185,8 +191,8 @@ for mcversion, value in main_json.items(): newIndex.by_mcversion.setdefault(mcversion, ForgeMcVersionInfo()) newIndex.by_mcversion[mcversion].versions.append(longversion) # NOTE: we add this later after the fact. The forge promotions file lies about these. - #if entry.latest: - #newIndex.by_mcversion[mcversion].latest = longversion + # if entry.latest: + # newIndex.by_mcversion[mcversion].latest = longversion if entry.recommended: newIndex.by_mcversion[mcversion].recommended = longversion @@ -219,14 +225,14 @@ fuckedVersions = [] 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) + eprint("Updating Forge %s" % id) if entry.mcversion == None: - eprint ("Skipping %d with invalid MC version" % entry.build) + eprint("Skipping %d with invalid MC version" % entry.build) continue version = ForgeVersion(entry) if version.url() == None: - eprint ("Skipping %d with no valid files" % version.build) + eprint("Skipping %d with no valid files" % version.build) continue jarFilepath = UPSTREAM_DIR + "/forge/jars/%s" % version.filename() @@ -244,14 +250,14 @@ for id, entry in newIndex.versions.items(): if installerRefreshRequired: # grab the installer if it's not there if not os.path.isfile(jarFilepath): - eprint ("Downloading %s" % version.url()) + eprint("Downloading %s" % version.url()) rfile = sess.get(version.url(), stream=True) rfile.raise_for_status() with open(jarFilepath, 'wb') as f: for chunk in rfile.iter_content(chunk_size=128): f.write(chunk) - eprint ("Processing %s" % version.url()) + eprint("Processing %s" % version.url()) # harvestables from the installer if not os.path.isfile(profileFilepath): print(jarFilepath) @@ -299,7 +305,7 @@ for id, entry in newIndex.versions.items(): if version.isSupported(): raise exception else: - eprint ("Version %s is not supported and won't be generated later." % version.longVersion) + eprint("Version %s is not supported and won't be generated later." % version.longVersion) with open(profileFilepath, 'wb') as profileFile: profileFile.write(installProfileJsonData) @@ -308,13 +314,13 @@ for id, entry in newIndex.versions.items(): # installer info v1 if not os.path.isfile(installerInfoFilepath): installerInfo = InstallerInfo() - eprint ("SHA1 %s" % jarFilepath) + eprint("SHA1 %s" % jarFilepath) installerInfo.sha1hash = filehash(jarFilepath, hashlib.sha1) - eprint ("SHA256 %s" % jarFilepath) + eprint("SHA256 %s" % jarFilepath) installerInfo.sha256hash = filehash(jarFilepath, hashlib.sha256) - eprint ("SIZE %s" % jarFilepath) + eprint("SIZE %s" % jarFilepath) installerInfo.size = os.path.getsize(jarFilepath) - eprint ("DUMP %s" % jarFilepath) + eprint("DUMP %s" % jarFilepath) with open(installerInfoFilepath, 'w', encoding='utf-8') as installerInfoFile: json.dump(installerInfo.to_json(), installerInfoFile, sort_keys=True, indent=4) installerInfoFile.close() @@ -335,7 +341,7 @@ for id, entry in newIndex.versions.items(): for chunk in rfile.iter_content(chunk_size=128): f.write(chunk) # find the latest timestamp in the zip file - tstamp = datetime.datetime.fromtimestamp(0) + tstamp = datetime.datetime.fromtimestamp(0) with zipfile.ZipFile(jarFilepath, 'r') as jar: allinfo = jar.infolist() for info in allinfo: diff --git a/updateLiteloader.py b/updateLiteloader.py index 8d44fe1..e610eca 100755 --- a/updateLiteloader.py +++ b/updateLiteloader.py @@ -11,13 +11,14 @@ from liteloaderutil import * UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] + def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) + forever_cache = FileCache('caches/http_cache', forever=True) sess = CacheControl(requests.Session(), forever_cache) - # get the remote version list r = sess.get('http://dl.liteloader.com/versions/versions.json') r.raise_for_status() diff --git a/updateMojang.py b/updateMojang.py index 0f72d16..7aca856 100755 --- a/updateMojang.py +++ b/updateMojang.py @@ -8,6 +8,7 @@ UPSTREAM_DIR = os.environ["UPSTREAM_DIR"] forever_cache = FileCache('caches/http_cache', forever=True) sess = CacheControl(requests.Session(), forever_cache) + def get_version_file(path, url): with open(path, 'w', encoding='utf-8') as f: r = sess.get(url) @@ -18,6 +19,7 @@ def get_version_file(path, url): json.dump(version_json, f, sort_keys=True, indent=4) return assetId, assetUrl + def get_file(path, url): with open(path, 'w', encoding='utf-8') as f: r = sess.get(url) @@ -25,6 +27,7 @@ def get_file(path, url): version_json = r.json() json.dump(version_json, f, sort_keys=True, indent=4) + # get the local version list localVersionlist = None try: @@ -60,12 +63,12 @@ assets = {} for id in updatedIDs: version = remoteVersionlist.versions[id] print("Updating " + version.id + " to timestamp " + version.releaseTime.strftime('%s')) - assetId, assetUrl = get_version_file( UPSTREAM_DIR + "/mojang/versions/" + id + '.json', version.url) + assetId, assetUrl = get_version_file(UPSTREAM_DIR + "/mojang/versions/" + id + '.json', version.url) assets[assetId] = assetUrl for assetId, assetUrl in iter(assets.items()): print("assets", assetId, assetUrl) - get_file( UPSTREAM_DIR + "/mojang/assets/" + assetId + '.json', assetUrl) + get_file(UPSTREAM_DIR + "/mojang/assets/" + assetId + '.json', assetUrl) with open(UPSTREAM_DIR + "/mojang/version_manifest_v2.json", 'w', encoding='utf-8') as f: json.dump(main_json, f, sort_keys=True, indent=4)