49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import os
|
|
import shutil
|
|
import tempfile
|
|
import PyInstaller.__main__
|
|
|
|
NAME = "IW4MAdminDBParser"
|
|
SCRIPT = "parse_db.py"
|
|
ICON = "assets/icon.png"
|
|
BUILD_DIR = "build"
|
|
DIST_DIR = "dist"
|
|
SPEC_FILE = NAME + ".spec"
|
|
|
|
# Run PyInstaller to create the executable
|
|
PyInstaller.__main__.run([
|
|
SCRIPT,
|
|
'--name', NAME,
|
|
"--noconfirm",
|
|
"--onefile",
|
|
"--windowed",
|
|
"--icon", ICON,
|
|
'--distpath', BUILD_DIR, # Specify custom build output folder
|
|
'--clean' # Clean PyInstaller cache and remove temporary files before building
|
|
])
|
|
|
|
# Remove SPEC file
|
|
if os.path.exists(SPEC_FILE):
|
|
os.remove(SPEC_FILE)
|
|
|
|
# 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) |