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
|
#!/usr/bin/env python3
"""Fill an installer template with one published artifact's details.
Usage: render-installer.py <template> <output> <version> <binary> <sha256> <url>
The Linux template embeds the application icon so the installer works offline.
"""
from __future__ import annotations
import pathlib
import sys
def main(argv: list[str]) -> int:
if len(argv) != 7:
print(
"usage: render-installer.py <template> <output> <version> "
"<binary> <sha256> <url>",
file=sys.stderr,
)
return 2
template, output, version, binary, sha256, url = argv[1:]
root = pathlib.Path(__file__).resolve().parent.parent
icon = (root / "gui" / "assets" / "zagan-bet.svg").read_text()
text = pathlib.Path(template).read_text()
replacements = {
"__VERSION__": version,
"__BINARY__": binary,
"__SHA256__": sha256,
"__URL__": url,
"__ICON__": icon.rstrip("\n"),
}
for placeholder, value in replacements.items():
text = text.replace(placeholder, value)
destination = pathlib.Path(output)
destination.write_text(text)
if destination.suffix == ".sh":
destination.chmod(0o755)
print(f" {destination} ({destination.stat().st_size} bytes)")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv))
|