- # -*- coding: utf-8 -*-
- """
- Build script for Excel Converter application
- This script uses PyInstaller to build an executable from the Python code
- """
-
- import os
- import sys
- import subprocess
- import shutil
-
- def main():
- # Package name and path
- package_name = "ExcelConverter"
- main_script = "main.py"
- icon_path = "icon.ico"
-
- # Make sure we're in the right directory
- script_dir = os.path.dirname(os.path.abspath(__file__))
- os.chdir(script_dir)
-
- # Create build command
- cmd = [
- "pyinstaller",
- "--name={}".format(package_name),
- "--onefile",
- "--windowed",
- "--clean",
- "--paths={}".format(script_dir),
- "--add-data={}{}config.py;.".format(script_dir, os.path.sep),
- "--add-data={}{}template.xlsx;.".format(script_dir, os.path.sep)
- ]
-
- # Add icon if it exists
- if os.path.exists(icon_path):
- cmd.append("--icon={}".format(icon_path))
-
- # Add main script
- cmd.append(main_script)
-
- # Print command
- print("Running command: {}".format(" ".join(cmd)))
-
- # Run PyInstaller
- try:
- subprocess.check_call(cmd)
- print("\nBuild completed successfully!")
-
- # Copy necessary files to dist folder
- dist_dir = os.path.join(script_dir, "dist", package_name)
- if not os.path.exists(dist_dir):
- dist_dir = os.path.join(script_dir, "dist")
-
- # Copy template file to dist folder
- if os.path.exists("template.xlsx"):
- shutil.copy("template.xlsx", dist_dir)
- print("Copied template.xlsx to {}".format(dist_dir))
-
- # Create empty config file if it doesn't exist
- config_path = os.path.join(dist_dir, "employee_info.json")
- if not os.path.exists(config_path):
- with open(config_path, 'w', encoding='utf-8') as f:
- f.write("[]")
- print("Created empty employee_info.json in {}".format(dist_dir))
-
- print("\nBuild is ready in: {}".format(dist_dir))
-
- except subprocess.CalledProcessError as e:
- print("Build failed with error:")
- print(e)
- return 1
- except Exception as e:
- print("An error occurred:")
- print(e)
- return 1
-
- return 0
-
- if __name__ == "__main__":
- sys.exit(main())
|