/
prepare_release.py
95 lines (78 loc) · 3.93 KB
/
prepare_release.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
# Prepare the release library
import os
import sys
import shutil
def compile_clean(name_overlay: str, game_folder: str, out_lib_name: str,
disable_console: bool = True, finalize_folder: bool = False):
"""Compile an overlay program and clean the building files.
Parameters
----------
name_overlay Name of this overlay executable.
game_folder Specific game folder name for the path.
out_lib_name Name of the output library.
disable_console True to disable the console output.
finalize_folder True to finalize the folder (copy additional files, zip, clean).
"""
icon = 'pictures/common/icon/salamander_sword_shield.ico' # icon for the library
# main nuitka command to run
main_command = ('cmd /c "python -m nuitka'
' --standalone'
' --plugin-enable=pyqt5'
f' --windows-icon-from-ico={icon}'
f' --include-data-file=common/*.py=common/'
f' --include-data-file={game_folder}/*.py={game_folder}/'
f' --include-data-dir=pictures/common=pictures/common'
f' --include-data-dir=pictures/{game_folder}=pictures/{game_folder}'
f' --include-data-dir=build_orders/{game_folder}=build_orders/{game_folder}')
if disable_console: # disable the console
command = main_command + ' --windows-disable-console' + f' {name_overlay}.py'
else: # show the console
command = main_command + f' {name_overlay}.py'
os.system(command) # compilation
# rename executable name for version with console
if not disable_console:
os.rename(os.path.join(f'{name_overlay}.dist', f'{name_overlay}.exe'),
os.path.join(f'{name_overlay}.dist', f'{name_overlay}_with_console.exe'))
# copy files in output directory
shutil.copytree(f'{name_overlay}.dist', out_lib_name, dirs_exist_ok=True)
# clean building files
shutil.rmtree(f'{name_overlay}.build')
shutil.rmtree(f'{name_overlay}.dist')
# finalize the output folder
if finalize_folder:
# copy readme, changelog, license and version
shutil.copy('Readme.md', out_lib_name)
shutil.copy('Changelog.md', out_lib_name)
shutil.copy('LICENSE', out_lib_name)
shutil.copy('version.json', out_lib_name)
shutil.copy('requirements.txt', out_lib_name)
# copy remaining source files
shutil.copy(f'{game_folder}_overlay.py', out_lib_name)
shutil.copy('prepare_release.py', out_lib_name)
# zip output folder
shutil.make_archive(out_lib_name, 'zip', out_lib_name)
shutil.rmtree(out_lib_name) # clean non-zipped files
if __name__ == '__main__':
compile_all = len(sys.argv) != 2 # compile all projects
project_selection = '' if compile_all else sys.argv[1]
# Age of Empires II
if compile_all or (project_selection == 'aoe2'):
aoe2_library_name = 'aoe2_overlay'
assert not os.path.isdir(aoe2_library_name)
os.mkdir(aoe2_library_name)
compile_clean(name_overlay='aoe2_overlay', game_folder='aoe2', out_lib_name=aoe2_library_name,
disable_console=True, finalize_folder=True)
# Age of Empires IV
if compile_all or (project_selection == 'aoe4'):
aoe4_library_name = 'aoe4_overlay'
assert not os.path.isdir(aoe4_library_name)
os.mkdir(aoe4_library_name)
compile_clean(name_overlay='aoe4_overlay', game_folder='aoe4', out_lib_name=aoe4_library_name,
disable_console=True, finalize_folder=True)
# StarCraft II
if compile_all or (project_selection == 'sc2'):
sc2_library_name = 'sc2_overlay'
assert not os.path.isdir(sc2_library_name)
os.mkdir(sc2_library_name)
compile_clean(name_overlay='sc2_overlay', game_folder='sc2', out_lib_name=sc2_library_name,
disable_console=True, finalize_folder=True)