forked from diogo-webber/vox-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
131 lines (90 loc) · 3.74 KB
/
build.py
File metadata and controls
131 lines (90 loc) · 3.74 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os, shutil
from pathlib import Path
import PyInstaller.__main__ as PyInstaller
import pyinstaller_versionfile
from app.constants import APP_VERSION
# ------------------------------------------------------------------------------ #
COLOR_TERM = os.getenv("COLORTERM")
TERMINAL_SUPPORT_COLORS = COLOR_TERM is not None and COLOR_TERM.lower() in ('truecolor', '256color')
YELLOW = TERMINAL_SUPPORT_COLORS and "\u001b[1m\u001b[38;5;214m" or ""
GREEN = TERMINAL_SUPPORT_COLORS and "\u001b[1m\u001b[38;5;64m" or ""
RESET = TERMINAL_SUPPORT_COLORS and "\u001b[0m" or ""
NEW_LINE = "\n"
def print_header(title, color):
TERMINAL_X = os.get_terminal_size().columns
PRETTY_LINE = "-" * TERMINAL_X
RESET_LINE = PRETTY_LINE + NEW_LINE + RESET
print(f"{NEW_LINE}{color}{PRETTY_LINE}{NEW_LINE}{title.center(TERMINAL_X)}{NEW_LINE}{RESET_LINE}")
# ------------------------------------------------------------------------------ #
# Note: Local assets paths and app icon path are relative to WORK_DIRECTORY.
ASSETS_DIRECTORY = "../app/assets"
ASSETS_TEMP_DIRECTORY = "assets"
LUA_DIRECTORY = "../app/lua"
LUA_TEMP_DIRECTORY = "lua"
LOGGING_CONFIG_FILE = "../app/logging_config.yaml"
LOGGING_CONFIG_TEMP_FILE = "."
STRINGS_DIRECTORY = "../app/localization"
STRINGS_DIRECTORY_FILE = "localization"
WORK_DIRECTORY = "builddata"
BUILD_DIRECTORY = "builds"
DATA_DIRECTORY = "appdata"
FILE = "app/main.py"
EXE_NAME = "Vox Launcher"
BUILD_NAME = APP_VERSION
ZIP_NAME = "VoxLauncher.zip"
ICON = "../app/assets/icon.ico"
VERSION_FILE_CREATE = "versionfile.txt"
VERSION_FILE = "../" + VERSION_FILE_CREATE
ONE_FILE = False
NO_CONSOLE = True
LOG_LEVEL = "WARN"
# ------------------------------------------------------------------------------ #
pyinstaller_versionfile.create_versionfile(
output_file=VERSION_FILE_CREATE,
version=APP_VERSION[1:],
file_description=EXE_NAME, # It's also the Task Bar "group" name.
internal_name=EXE_NAME,
legal_copyright="Open Source @ 2024",
product_name=EXE_NAME,
translations=[0x0409, 1200],
)
# ------------------------------------------------------------------------------ #
command_args = [
f"--add-data={LOGGING_CONFIG_FILE};{LOGGING_CONFIG_TEMP_FILE}",
f"--add-data={STRINGS_DIRECTORY};{STRINGS_DIRECTORY_FILE}",
f"--add-data={ASSETS_DIRECTORY};{ASSETS_TEMP_DIRECTORY}",
f"--add-data={LUA_DIRECTORY};{LUA_TEMP_DIRECTORY}",
ONE_FILE and "--onefile" or f"--contents-directory={DATA_DIRECTORY}",
NO_CONSOLE and "--noconsole" or "",
"--noconfirm",
"--clean",
f"--name={EXE_NAME}",
f"--icon={ICON}",
f"--distpath={BUILD_DIRECTORY}",
f"--workpath={WORK_DIRECTORY}",
f"--specpath={WORK_DIRECTORY}",
f"--version-file={VERSION_FILE}",
f"--log-level={LOG_LEVEL}",
FILE,
]
# ------------------------------------------------------------------------------ #
if __name__ == "__main__":
print_header(f"Building: {EXE_NAME}", color=YELLOW)
PyInstaller.run(command_args)
build_path = Path(BUILD_DIRECTORY) / EXE_NAME
zip_temp_path = Path(WORK_DIRECTORY) / ("temp" + ".zip")
zip_path = build_path / ZIP_NAME
if build_path.exists():
print(f"\nZipping file: {YELLOW}{ZIP_NAME}{RESET}...")
# Created a zip file.
shutil.make_archive(f"{WORK_DIRECTORY}/temp", 'zip', build_path)
# Rename and move the zip file to "zip_path".
zip_temp_path.rename(zip_path)
new_build_path = build_path.with_name(BUILD_NAME)
if new_build_path.exists():
shutil.rmtree(new_build_path)
# Rename the build folder to "new_build_path".
build_path.rename(new_build_path)
# Opens the directory in windows explorer.
os.startfile(new_build_path)
print_header("- Build Finished -", color=GREEN)