-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
89 lines (73 loc) · 2.3 KB
/
setup.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
import os
import platform
import shutil
import struct
from datetime import datetime
import PyInstaller.__main__ as pyinstaller
from pyinstaller_versionfile import create_versionfile
import sc4mpserver
TITLE = "SC4MP Server"
NAME = "sc4mpserver.exe"
VERSION = sc4mpserver.SC4MP_VERSION
PUBLISHER = "SimCity 4 Multiplayer Project"
DESCRIPTION = "Multiplayer gameserver for SimCity 4"
LICENSE = "MIT-0"
DIST = "dist" + str(8 * struct.calcsize("P"))
def main():
# Make distribution directory if it does not yet exist
print(f"Preparing distribution directory at \"{DIST}\"")
if not os.path.exists(DIST):
os.makedirs(DIST)
# Purge the distribution directory
for item in os.listdir(DIST):
item = os.path.join(DIST, item)
if (os.path.isfile(item)):
os.remove(item)
else:
shutil.rmtree(item)
# Create version file
print(f"Creating version file...")
create_versionfile(
output_file="version.rc",
version=VERSION,
company_name=PUBLISHER,
file_description=TITLE,
internal_name=TITLE,
legal_copyright=LICENSE,
original_filename=NAME,
product_name=TITLE,
)
# Run setup
print("Running setup...")
pyinstaller.run([
f"sc4mpserver.py",
f"--specpath",
f"{os.path.join('temp', 'spec')}",
f"--distpath",
f"dist",
f"--workpath",
f"{os.path.join('temp', 'build')}",
f"--onedir",
f"--contents-directory",
f"resources",
f"--noconfirm",
f"--noupx",
f"--console",
f"-i",
f"{os.path.abspath(os.path.join('resources', 'icon.ico'))}",
f"--version-file",
f"{os.path.abspath('version.rc')}"
])
# Copy binary files to distribution directory
shutil.copytree(os.path.join("dist", "sc4mpserver"), DIST, dirs_exist_ok=True)
# Copy extra files to distribution directory
print(f'Copying extra files to "{DIST}"...')
shutil.copytree("resources", os.path.join(DIST, "resources"), dirs_exist_ok=True)
shutil.copy("License.txt", DIST)
shutil.copy("Readme.html", DIST)
# Create a zip archive of the distribution
destination = os.path.join(os.path.join("builds", "sc4mp-server-" + platform.system().lower() + "-" + str(8 * struct.calcsize("P")) + "-v" + VERSION + "." + datetime.now().strftime("%Y%m%d%H%M%S")))
print('Creating zip archive of "' + DIST + '" at "' + destination + '"')
shutil.make_archive(destination, "zip", DIST)
if __name__ == "__main__":
main()