-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
updateQuilt.py
executable file
·82 lines (71 loc) · 3.09 KB
/
updateQuilt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python3
import os, requests
from cachecontrol import CacheControl
import datetime
import hashlib, json
import zipfile
from quiltutil import *
from cachecontrol.caches import FileCache
forever_cache = FileCache('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:
for block in iter(lambda: f.read(blocksize), b""):
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)
r.raise_for_status()
version_json = r.json()
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)
r.raise_for_status()
with open(path, 'wb') as f:
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)
tstamp = datetime.datetime.fromtimestamp(0)
with zipfile.ZipFile(jarPath, 'r') as jar:
allinfo = jar.infolist()
for info in allinfo:
tstampNew = datetime.datetime(*info.date_time)
if tstampNew > tstamp:
tstamp = tstampNew
data = QuiltJarInfo()
data.releaseTime = tstamp
data.sha1 = filehash(jarPath, hashlib.sha1)
data.sha256 = filehash(jarPath, hashlib.sha256)
data.size = os.path.getsize(jarPath)
with open(path + ".json", 'w') as outfile:
json.dump(data.to_json(), outfile, sort_keys=True, indent=4)
mkdirs("upstream/quilt/meta-v3")
mkdirs("upstream/quilt/loader-installer-json")
mkdirs("upstream/quilt/jars")
# get the version list for each component we are interested in
#for component in ["intermediary", "loader"]:
for component in ["loader"]:
index = get_json_file("upstream/quilt/meta-v3/" + component + ".json", "https://meta.quiltmc.org/v3/versions/" + component)
for it in index:
jarMavenUrl = get_maven_url(it["maven"], "https://maven.quiltmc.org/repository/release/", ".jar")
compute_jar_file("upstream/quilt/jars/" + it["maven"].replace(":", "."), jarMavenUrl)
# for each loader, download installer JSON file from maven
with open("upstream/quilt/meta-v3/loader.json", 'r', encoding='utf-8') as loaderVersionIndexFile:
loaderVersionIndex = json.load(loaderVersionIndexFile)
for it in loaderVersionIndex:
mavenUrl = get_maven_url(it["maven"], "https://maven.quiltmc.org/repository/release/", ".json")
get_json_file("upstream/quilt/loader-installer-json/" + it["version"] + ".json", mavenUrl)