-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_manifest.py
executable file
·91 lines (61 loc) · 2.23 KB
/
update_manifest.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
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
import hashlib
import json
import logging
import re
from string import Template
from typing import Any
from defs import *
logger = logging.getLogger(__name__)
FILE_URL_TEMPLATE = Template(
"https://github.com/Evergreen-lxl/evergreen-languages/releases/download/"
"$PLATFORM/$FILENAME"
)
def get_addons(manifest: dict) -> dict[str, dict]:
addons_dict = {}
addons = manifest.get("addons", {})
for addon in addons:
addons_dict[addon["id"].replace("evergreen_", "")] = addon
return addons_dict
def make_addon(name: str) -> dict[str, Any]:
return {
"id": f"evergreen_{name}",
"version": "0",
"mod_version": MODVERSION,
"type": "plugin",
"dependencies": {"evergreen": {}},
"files": [],
}
def bump_version(addon: dict):
addon["version"] = str(int(addon["version"]) + 1)
def update_file(files: list[dict], platform: str, filename: str, checksum: str):
entry = next((f for f in files if f["arch"] == platform), None)
if not entry:
logger.info(f"{name}: Created missing entry for {platform}")
entry = {"arch": platform}
files.append(entry)
else:
logger.info(f"{name}: Updated entry for {platform}")
entry["url"] = FILE_URL_TEMPLATE.substitute(PLATFORM=platform, FILENAME=filename)
entry["checksum"] = checksum
def make_manifest(addons: dict[str, dict]) -> dict:
addons_ls = sorted(addons.values(), key=lambda v: v["id"])
for addon in addons_ls:
addon["files"].sort(key=lambda v: v["arch"])
return {"addons": addons_ls}
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
with open(MANIFEST_FILE, "r") as f:
addons = get_addons(json.load(f))
updated: set[str] = set()
for file in sorted(DIST_DIR.iterdir()):
m = re.fullmatch(r"evergreen_(.*?)\-(.*).zip", file.name)
if not m:
continue
name, platform = m.groups()
entry = addons[name]
with open(file, "rb") as f:
checksum = hashlib.file_digest(f, "sha256").hexdigest()
update_file(entry["files"], platform, file.name, checksum)
with open(MANIFEST_FILE, "w") as f:
json.dump(make_manifest(addons), f, indent=4)