forked from Kippiii/jabberwocky-container-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
94 lines (80 loc) · 2.27 KB
/
build.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
92
93
94
import hashlib
import shutil
import subprocess
from os import chdir, makedirs, pathsep
from os.path import basename, exists
from pathlib import Path
from platform import machine
from sys import argv, executable, exit, platform
from src.system.filezilla import fzpath
EXE_FILE_EXTEN = ".exe" if platform == "win32" else ""
root = Path(__file__).parent.absolute()
build = root / "build/"
contrib = root / "contrib/"
target_run = root / "run.py"
target_server = root / "server.py"
target_install = root / "installer.py"
installer_name = f"installer-{platform}-{machine()}"
installer_file = build / "dist" / (installer_name + EXE_FILE_EXTEN)
ignore_missing_contrib = "--ignore-missing-contrib" in argv
if ignore_missing_contrib:
if not exists(contrib):
makedirs(contrib)
elif not fzpath() or not fzpath().exists():
print("FileZilla is missing.")
print("Run download_prerequisies.py before building.")
print("OR build with --ignore-missing-contrib.")
exit(-1)
# Clean previous build
if build.is_dir():
shutil.rmtree(build)
makedirs(build)
chdir(build)
# Build
pyinstaller = [executable, "-m", "PyInstaller"]
build_options = ["--workpath", "work", "--specpath", "spec", "--distpath", "dist"]
subprocess.run(
[
*pyinstaller,
"--name",
"jab",
*build_options,
target_run,
],
check=True,
)
subprocess.run(
[
*pyinstaller,
"--noconsole",
*build_options,
target_server,
],
check=True,
)
shutil.make_archive(build / "dist", "tar", build / "dist")
shutil.make_archive(build / "contrib", "tar", contrib)
shutil.make_archive(build / "scripts", "tar", root / "scripts")
subprocess.run(
[
*pyinstaller,
f"--console",
f"--onefile",
f"--name",
installer_name,
f"--add-data",
f"{build / 'dist.tar'}{pathsep}.",
f"--add-data",
f"{root / 'LICENSE'}{pathsep}.",
f"--add-data",
f"{build / 'contrib.tar'}{pathsep}.",
f"--add-data",
f"{build / 'scripts.tar'}{pathsep}.",
*build_options,
target_install,
],
check=True,
)
with open(installer_file, "rb") as fin:
sha256 = hashlib.sha256(fin.read()).hexdigest()
print(f"{basename(installer_file).ljust(25)} SHA256: {sha256}")