-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_release.py
82 lines (69 loc) · 2.49 KB
/
package_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
"""Entire release creation - including source code and EXE."""
import os
import pathlib
import shutil
import subprocess
FOLDER = pathlib.Path(__file__).parent
RELEASE_FOLDER = FOLDER / "release"
if RELEASE_FOLDER.is_dir():
shutil.rmtree(RELEASE_FOLDER)
RELEASE_FOLDER.mkdir()
CODE_PACKAGE_FOLDER = RELEASE_FOLDER / "code"
CODE_PACKAGE_ZIP = RELEASE_FOLDER / "code"
ICON = FOLDER / "src" / "gui" / "bin" / "icon.ico"
START_SCRIPT = FOLDER / "run_app.py"
PATHS = (
FOLDER / "src",
FOLDER / "src" / "gui"
)
BINARIES = {
FOLDER / "src" / "gui" / "cpp" / "conversion.so": "src/gui/cpp",
FOLDER / "src" / "gui" / "cpp" / "foreground.so": "src/gui/cpp",
}
ADDITIONAL_DATA = {
FOLDER / "src" / "gui" / "bin": "src/gui/bin/"
}
OUTPUT_EXE_NAME = RELEASE_FOLDER / "streetviewimagedownloader.exe"
def package_code() -> None:
"""Packages source, ready to run."""
CODE_PACKAGE_FOLDER.mkdir()
shutil.copy(START_SCRIPT, CODE_PACKAGE_FOLDER / START_SCRIPT.name)
# Copy source folder.
shutil.copytree(FOLDER / "src", CODE_PACKAGE_FOLDER / "src")
# Delete all pycaches.
for path in (CODE_PACKAGE_FOLDER / "src").rglob("__pycache__"):
shutil.rmtree(path)
# Make zip file.
shutil.make_archive(CODE_PACKAGE_ZIP, "zip", CODE_PACKAGE_FOLDER)
# Delete copied source folder.
shutil.rmtree(CODE_PACKAGE_FOLDER)
def package_exe() -> None:
"""Packages standalone EXE, ready to run."""
# Build command parts.
command_parts = [
"pyinstaller", str(START_SCRIPT), "--noconfirm", "--onefile",
"--windowed", "--icon", str(ICON)]
for binary_src, binary_dest in BINARIES.items():
command_parts.append("--add-binary")
command_parts.append(f"{binary_src};{binary_dest}")
for path in PATHS:
command_parts.append("--paths")
command_parts.append(str(path))
for add_data_src, add_data_dest in ADDITIONAL_DATA.items():
command_parts.append("--add-data")
command_parts.append(f"{add_data_src};{add_data_dest}")
# Run Pyinstaller.
os.chdir(RELEASE_FOLDER)
subprocess.run(command_parts)
# Renames output EXE.
output_exe = RELEASE_FOLDER / "dist" / f"{START_SCRIPT.stem}.exe"
output_exe.rename(OUTPUT_EXE_NAME)
# Deletes Pyinstaller files and folders.
(RELEASE_FOLDER / "dist").rmdir()
shutil.rmtree(RELEASE_FOLDER / "build")
(RELEASE_FOLDER / f"{START_SCRIPT.stem}.spec").unlink(True)
def main() -> None:
package_code()
package_exe()
if __name__ == "__main__":
main()