-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.py
More file actions
67 lines (49 loc) · 1.81 KB
/
Copy pathrelease.py
File metadata and controls
67 lines (49 loc) · 1.81 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
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZipFile
ROOT = Path(__file__).resolve().parent
RELEASE_DIR = ROOT / "_release"
INCLUDE_DIR = ROOT / "include"
LIB_DIR = ROOT / "lib"
BUILD_DIR = ROOT / "build"
FILES = [
ROOT / "MIT-LICENSE.txt",
ROOT / "makefile",
]
def ask_version():
version = input("Version: ").strip()
if not version:
raise SystemExit("Version cannot be empty.")
if any(symbol in version for symbol in '\\/:*?"<>|'):
raise SystemExit('Version contains invalid filename characters: \\ / : * ? " < > |')
return version
def add_file(zip_file: ZipFile, path: Path):
zip_file.write(path, path.relative_to(ROOT).as_posix())
def add_directory(zip_file: ZipFile, directory: Path):
for path in sorted(directory.rglob("*")):
if path.is_file():
add_file(zip_file, path)
def add_build_dlls(zip_file: ZipFile, directory: Path):
dll_files = sorted(directory.rglob("*.dll"))
if not dll_files:
raise SystemExit(f"No DLL files found in: {directory}")
for path in dll_files:
add_file(zip_file, path)
def main():
for directory in (INCLUDE_DIR, LIB_DIR, BUILD_DIR):
if not directory.is_dir():
raise SystemExit(f"Missing directory: {directory}")
for path in FILES:
if not path.is_file():
raise SystemExit(f"Missing file: {path}")
version = ask_version()
RELEASE_DIR.mkdir(exist_ok=True)
archive_path = RELEASE_DIR / f"InSDL-{version}.zip"
with ZipFile(archive_path, "w", ZIP_DEFLATED) as zip_file:
add_directory(zip_file, INCLUDE_DIR)
add_directory(zip_file, LIB_DIR)
add_build_dlls(zip_file, BUILD_DIR)
for path in FILES:
add_file(zip_file, path)
print(f"Created: {archive_path}")
if __name__ == "__main__":
main()