SwapStation_Dashboard/generate_exe.py

57 lines
2.0 KiB
Python

import subprocess
import sys
def generate_executable():
"""Prompts for a version and generates a single-file executable."""
# 1. Ask the user for the version number
version = ""
while not version:
version = input("Enter the version for the executable (e.g., 4.1): ")
if not version:
print("Version cannot be empty. Please try again.")
executable_name = f"SwapStationDashboard_v{version}"
print(f"Generating executable with name: {executable_name}")
# Check if pyinstaller is installed
try:
subprocess.run([sys.executable, "-m", "PyInstaller", "--version"], check=True, capture_output=True)
except (subprocess.CalledProcessError, FileNotFoundError):
print("PyInstaller is not found. Please install it using: pip install pyinstaller")
return
print("Starting executable generation...")
# 2. Use the version to create the command
command = [
sys.executable,
"-m", "PyInstaller",
f"--name={executable_name}",
"--onefile",
"--icon=assets/icon.ico",
"--add-data=logo;logo",
"--add-data=assets;assets",
"--add-data=proto;proto",
"--hidden-import=paho.mqtt",
"--hidden-import=google.protobuf",
"--hidden-import=PyQt6",
"--hidden-import=PyQt6.Qt6",
"--hidden-import=PyQt6.sip",
"--hidden-import=setuptools",
"main.py"
]
try:
# 3. Execute the command
subprocess.run(command, check=True)
print("\n✅ Executable generated successfully!")
print(f"Look for '{executable_name}.exe' in the 'dist' folder.")
except subprocess.CalledProcessError as e:
print("\n❌ An error occurred during executable generation.")
print(f"Command failed with return code: {e.returncode}")
except FileNotFoundError:
print("\n❌ Error: The 'main.py' file was not found. Please run this script from the project's root directory.")
if __name__ == "__main__":
generate_executable()