Skip to content

Commit e3eea94

Browse files
committed
add release generating script
1 parent 63d5641 commit e3eea94

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ __pycache__
22
.env
33
.mypy_cache
44
.vscode
5+
6+
PythonSDK.zip

prepare_release.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
from typing import List
3+
from zipfile import ZIP_DEFLATED, ZipFile
4+
5+
6+
def create_release(release_path: str, mods_folder: str, sdk_files: List[str]) -> None:
7+
"""
8+
Creates a release zip.
9+
10+
Args:
11+
release_path: The path to the release zip.
12+
mods_folder: The path to the mods folder to include. Will be copied recursively.
13+
sdk_files: A list of paths to the SDK's files, which will be placed in Win32. Will not copy
14+
folder structure.
15+
"""
16+
zip_root = os.path.join("Binaries", "Win32")
17+
18+
with ZipFile(release_path, "w", ZIP_DEFLATED, compresslevel=9) as zip_file:
19+
# Must always be placed in a folder called exactly 'Mods', regardless of where we're copying
20+
# it from
21+
zipped_mods_root = os.path.join(zip_root, "Mods")
22+
23+
for root, _, files in os.walk(mods_folder):
24+
for file_name in files:
25+
file_path = os.path.join(root, file_name)
26+
rel_path = os.path.relpath(file_path, mods_folder)
27+
zip_file.write(file_path, os.path.join(zipped_mods_root, rel_path))
28+
29+
for file_path in sdk_files:
30+
file_name = os.path.basename(file_path)
31+
zip_file.write(file_path, os.path.join(zip_root, file_name))
32+
33+
34+
if __name__ == "__main__":
35+
import traceback
36+
from argparse import ArgumentParser
37+
38+
RELEASE_NAME = "PythonSDK.zip"
39+
MODS_FOLDER = "Mods"
40+
41+
parser = ArgumentParser(description="Prepares a release zip. Copies the current Mods folder.")
42+
parser.add_argument(
43+
"sdk_files",
44+
nargs="+",
45+
help="The SDK's files, to be placed in Win32. Will not copy folder structure."
46+
)
47+
args = parser.parse_args()
48+
49+
try:
50+
create_release(RELEASE_NAME, MODS_FOLDER, args.sdk_files)
51+
except Exception:
52+
traceback.print_exc()
53+
input("Press enter to exit")

0 commit comments

Comments
 (0)