forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
147 lines (119 loc) · 4.52 KB
/
Copy pathsetup.py
File metadata and controls
147 lines (119 loc) · 4.52 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import os
import shutil
import sys
import sysconfig
from pathlib import Path
import cx_Freeze
is_64bits = sys.maxsize > 2 ** 32
folder = "exe.{platform}-{version}".format(platform=sysconfig.get_platform(),
version=sysconfig.get_python_version())
buildfolder = Path("build", folder)
sbuildfolder = str(buildfolder)
libfolder = Path(buildfolder, "lib")
library = Path(libfolder, "library.zip")
print("Outputting to: " + sbuildfolder)
icon = "icon.ico"
if os.path.exists("X:/pw.txt"):
print("Using signtool")
with open("X:/pw.txt") as f:
pw = f.read()
signtool = r'signtool sign /f X:/_SITS_Zertifikat_.pfx /p ' + pw + r' /fd sha256 /tr http://timestamp.digicert.com/ '
else:
signtool = None
from hashlib import sha3_512
import base64
def _threaded_hash(filepath):
hasher = sha3_512()
hasher.update(open(filepath, "rb").read())
return base64.b85encode(hasher.digest()).decode()
os.makedirs(buildfolder, exist_ok=True)
def manifest_creation():
hashes = {}
manifestpath = os.path.join(buildfolder, "manifest.json")
from concurrent.futures import ThreadPoolExecutor
pool = ThreadPoolExecutor()
for dirpath, dirnames, filenames in os.walk(buildfolder):
for filename in filenames:
path = os.path.join(dirpath, filename)
hashes[os.path.relpath(path, start=buildfolder)] = pool.submit(_threaded_hash, path)
import json
manifest = {"buildtime": buildtime.isoformat(sep=" ", timespec="seconds"),
"hashes": {path: hash.result() for path, hash in hashes.items()}}
json.dump(manifest, open(manifestpath, "wt"), indent=4)
print("Created Manifest")
scripts = {"MultiClient.py": "BerserkerMultiClient",
"MultiMystery.py": "BerserkerMultiMystery",
"MultiServer.py": "BerserkerMultiServer",
"gui.py": "BerserkerMultiCreator",
"Mystery.py": "BerserkerMystery",
"Adjuster.py": "BerserkerLttPAdjuster"}
exes = []
for script, scriptname in scripts.items():
exes.append(cx_Freeze.Executable(
script=script,
target_name=scriptname + ("" if sys.platform == "linux" else ".exe"),
icon=icon,
))
import datetime
buildtime = datetime.datetime.utcnow()
cx_Freeze.setup(
name="BerserkerMultiWorld",
version=f"{buildtime.year}.{buildtime.month}.{buildtime.day}.{buildtime.hour}",
description="BerserkerMultiWorld",
executables=exes,
options={
"build_exe": {
"includes": [],
"excludes": ["numpy", "Cython", "PySide2", "PIL",
"pandas"],
"zip_include_packages": ["*"],
"zip_exclude_packages": [],
"include_files": [],
"include_msvcr": True,
"replace_paths": [("*", "")],
"optimize": 2,
"build_exe": buildfolder
},
},
)
def installfile(path, keep_content=False):
lbuildfolder = buildfolder
print('copying', path, '->', lbuildfolder)
if path.is_dir():
lbuildfolder /= path.name
if lbuildfolder.is_dir() and not keep_content:
shutil.rmtree(lbuildfolder)
shutil.copytree(path, lbuildfolder, dirs_exist_ok=True)
elif path.is_file():
shutil.copy(path, lbuildfolder)
else:
print('Warning,', path, 'not found')
extra_data = ["LICENSE", "data", "EnemizerCLI", "host.yaml", "QUsb2Snes", "meta.yaml"]
for data in extra_data:
installfile(Path(data))
os.makedirs(buildfolder / "Players", exist_ok=True)
shutil.copyfile("playerSettings.yaml", buildfolder / "Players" / "weightedSettings.yaml")
try:
from maseya import z3pr
except ImportError:
print("Maseya Palette Shuffle not found, skipping data files.")
else:
# maseya Palette Shuffle exists and needs its data files
print("Maseya Palette Shuffle found, including data files...")
file = z3pr.__file__
installfile(Path(os.path.dirname(file)) / "data", keep_content=True)
qusb2sneslog = buildfolder / "QUsb2Snes" / "log.txt"
if os.path.exists(qusb2sneslog):
os.remove(qusb2sneslog)
qusb2snesconfig = buildfolder / "QUsb2Snes" / "config.ini"
if os.path.exists(qusb2snesconfig):
os.remove(qusb2snesconfig)
alttpr_sprites_folder = buildfolder / "data" / "sprites" / "alttpr"
for file in os.listdir(alttpr_sprites_folder):
if file != ".gitignore":
os.remove(alttpr_sprites_folder / file)
if signtool:
for exe in exes:
print(f"Signing {exe.target_name}")
os.system(signtool + os.path.join(buildfolder, exe.target_name))
manifest_creation()