-
Notifications
You must be signed in to change notification settings - Fork 156
/
build.py
218 lines (193 loc) · 6.58 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
"""
build.py - Build the program EXE.
Copyright (c) EDCD, All Rights Reserved
Licensed under the GNU General Public License.
See LICENSE file.
"""
import os
import shutil
import sys
import pathlib
from string import Template
import py2exe
from config import (
appcmdname,
appname,
appversion,
copyright,
git_shorthash_from_head,
_static_appversion,
update_interval
)
from update import check_for_fdev_updates
def iss_build(template_path: str, output_file: str) -> None:
"""Build the .iss file needed for building the installer EXE."""
sub_vals = {
"appver": _static_appversion,
"update_time": str(update_interval),
}
with open(template_path, encoding="UTF8") as template_file:
src = Template(template_file.read())
newfile = src.substitute(sub_vals)
with open(output_file, "w", encoding="UTF8") as new_file:
new_file.write(newfile)
def system_check(dist_dir: pathlib.Path) -> str:
"""Check if the system is able to build."""
if sys.version_info < (3, 11):
sys.exit(f"Unexpected Python version {sys.version}")
if sys.platform != "win32":
sys.exit(f"Unsupported platform {sys.platform}")
git_shorthash = git_shorthash_from_head()
if git_shorthash is None:
sys.exit("Invalid Git Hash")
gitversion_file = ".gitversion"
with open(gitversion_file, "w+", encoding="utf-8") as gvf:
gvf.write(git_shorthash)
print(f"Git short hash: {git_shorthash}")
if dist_dir and pathlib.Path.is_dir(dist_dir):
shutil.rmtree(dist_dir)
return gitversion_file
def generate_data_files(
app_name: str, gitversion_file: str, plugins: list[str]
) -> list[tuple[object, object]]:
"""Create the required datafiles to build."""
l10n_dir = "L10n"
fdevids_dir = pathlib.Path("FDevIDs")
license_dir = pathlib.Path("docs/Licenses")
data_files = [
(
"",
[
gitversion_file,
"WinSparkle.dll",
"WinSparkle.pdb",
"EUROCAPS.TTF",
"ChangeLog.md",
"snd_good.wav",
"snd_bad.wav",
"modules.json",
"ships.json",
f"{app_name}.ico",
f"resources/{appcmdname}.ico",
"EDMarketConnector - TRACE.bat",
"EDMarketConnector - localserver-auth.bat",
"EDMarketConnector - reset-ui.bat",
],
),
(
l10n_dir,
[pathlib.Path(l10n_dir) / x for x in os.listdir(l10n_dir) if x.endswith(".strings")]
),
(
fdevids_dir,
[
pathlib.Path(fdevids_dir / "commodity.csv"),
pathlib.Path(fdevids_dir / "rare_commodity.csv"),
],
),
("plugins", plugins),
]
# Add all files recursively from license directories
for root, dirs, files in os.walk(license_dir):
file_list = [os.path.join(root, f) for f in files]
dest_dir = os.path.join(license_dir, os.path.relpath(root, license_dir))
data_files.append((dest_dir, file_list))
return data_files
def build() -> None:
"""Build EDMarketConnector using Py2Exe."""
dist_dir: pathlib.Path = pathlib.Path("dist.win32")
gitversion_filename: str = system_check(dist_dir)
# Constants
plugins: list[str] = [
"plugins/coriolis.py",
"plugins/eddn.py",
"plugins/edsm.py",
"plugins/edsy.py",
"plugins/inara.py",
"plugins/spansh_core.py",
]
options: dict = {
"py2exe": {
"dist_dir": dist_dir,
"optimize": 2,
"packages": [
"asyncio",
"multiprocessing",
"pkg_resources._vendor.platformdirs",
"sqlite3",
"util",
],
"includes": ["dataclasses", "shutil", "timeout_session", "zipfile"],
"excludes": [
"distutils",
"_markerlib",
"optparse",
"simplejson",
"unittest",
"doctest",
"pdb",
"difflib",
],
}
}
# Function to generate DATA_FILES list
data_files: list[tuple[object, object]] = generate_data_files(
appname, gitversion_filename, plugins
)
version_info: dict = {
"description": "Elite Dangerous Market Connector (EDMC)",
"comments": "Downloads commodity market and other station data from the game"
" Elite Dangerous for use with all popular online and offline trading tools.",
"company_name": "EDCD", # Used by WinSparkle
"product_name": appname, # Used by WinSparkle
"version": str(appversion().truncate()),
"product_version": str(appversion()),
"copyright": copyright,
"language": "English (United States)",
}
windows_config: dict = {
"dest_base": appname,
"script": "EDMarketConnector.py",
"icon_resources": [(0, f"{appname}.ico")],
"other_resources": [
(24, 1, pathlib.Path(f"resources/{appname}.manifest").read_text(encoding="UTF8"))
],
}
console_config: dict = {
"dest_base": appcmdname,
"script": "EDMC.py",
"icon_resources": [(0, f"resources/{appcmdname}.ico")],
"other_resources": [
(24, 1, pathlib.Path(f"resources/{appcmdname}.manifest").read_text(encoding="UTF8"))
],
}
checker_config: dict = {
"dest_base": "EDMCSystemProfiler",
"script": "EDMCSystemProfiler.py",
"icon_resources": [(0, f"{appname}.ico")],
"other_resources": [
(24, 1, pathlib.Path(f"resources/{appname}.manifest").read_text(encoding="UTF8"))
],
}
try:
py2exe.freeze(
version_info=version_info,
windows=[windows_config, checker_config],
console=[console_config],
data_files=data_files,
options=options,
)
except FileNotFoundError as err:
print(err)
sys.exit(
"Build Failed due to Missing Files! Have you set up your submodules? \n"
"https://github.com/EDCD/EDMarketConnector/wiki/Running-from-source"
"#obtain-a-copy-of-the-application-source"
)
iss_template_path: str = "./resources/EDMC_Installer_Config_template.txt"
iss_file_path: str = "./EDMC_Installer_Config.iss"
# Build the ISS file
iss_build(iss_template_path, iss_file_path)
if __name__ == "__main__":
check_for_fdev_updates(local=True)
build()