Update build script

This commit is contained in:
Ahrimdon 2024-03-03 05:39:05 -05:00
parent 55815f424f
commit a10d742a43

View File

@ -1,23 +1,49 @@
import os import os
import shutil
import tempfile
import PyInstaller.__main__ import PyInstaller.__main__
from distutils.sysconfig import get_python_lib
site_packages_path = get_python_lib() NAME = "IW4MAdminDBParser"
NAME = "IW4MAdmin_DB_Parser"
SCRIPT = "parse_db.py" SCRIPT = "parse_db.py"
ICON = "assets/icon.png" ICON = "assets/icon.png"
BUILD_DIR = "build"
DIST_DIR = "dist"
SPEC_FILE = NAME + ".spec"
# Run PyInstaller to create the executable
PyInstaller.__main__.run([ PyInstaller.__main__.run([
"{}".format(SCRIPT), SCRIPT,
'--name', f"{NAME}", '--name', NAME,
"--noconfirm", "--noconfirm",
"--onefile", "--onefile",
"--windowed", "--windowed",
"--icon", f"{ICON}" "--icon", ICON,
'--distpath', BUILD_DIR, # Specify custom build output folder
'--clean' # Clean PyInstaller cache and remove temporary files before building
]) ])
# create symbolic hardlink to main directory # Remove SPEC file
if os.path.exists("combine_db.exe"): if os.path.exists(SPEC_FILE):
os.remove("combine_db.exe") os.remove(SPEC_FILE)
os.link('dist/IW4MAdmin_DB_Parser.exe', 'IW4MAdmin_DB_Parser.exe')
# Temporarily move the executable to a safe location
temp_dir = tempfile.mkdtemp()
exe_path = os.path.join(BUILD_DIR, NAME + '.exe')
temp_exe_path = os.path.join(temp_dir, NAME + '.exe')
if os.path.exists(exe_path):
shutil.move(exe_path, temp_exe_path)
# Remove the 'build' directory, which includes the subfolder and its contents
if os.path.isdir(BUILD_DIR):
shutil.rmtree(BUILD_DIR)
# Recreate the 'build' directory and move the executable back
os.makedirs(BUILD_DIR, exist_ok=True)
shutil.move(temp_exe_path, os.path.join(BUILD_DIR, NAME + '.exe'))
# Clean up the temporary directory
shutil.rmtree(temp_dir)
# Remove the 'dist' directory if it exists
if os.path.isdir(DIST_DIR):
shutil.rmtree(DIST_DIR)