VOC_Monitor/app/update_build_setup.py

87 lines
2.5 KiB
Python

"""
updater.exe 단독 빌드 스크립트
목표:
- app/updater/updater_gui.py를 단일 실행파일(onefile) updater.exe로 빌드
- 빌드 산출물과 updater 설정 파일(config.json)을 메인 패키징 입력 경로에 정리
사용 예시:
python app/update_build_setup.py
"""
from __future__ import annotations
import shutil
import subprocess
import sys
from pathlib import Path
def run_command(command: list[str], workdir: Path) -> None:
result = subprocess.run(command, cwd=str(workdir), check=False)
if result.returncode != 0:
raise RuntimeError(f"명령 실행 실패: {' '.join(command)} (rc={result.returncode})")
def main() -> int:
base_dir = Path(__file__).resolve().parent
updater_script = base_dir / "updater" / "updater_gui.py"
updater_icon = base_dir / "assets" / "app_icon.ico"
build_root = base_dir / "updater_build"
dist_root = build_root / "dist"
pyinstaller_build_root = build_root / "build"
spec_root = build_root / "spec"
config_src = base_dir / "updater" / "config.json"
config_dst = build_root / "config.json"
if not updater_script.exists():
raise FileNotFoundError(f"업데이터 스크립트가 없습니다: {updater_script}")
if not config_src.exists():
raise FileNotFoundError(f"업데이터 설정 파일이 없습니다: {config_src}")
dist_root.mkdir(parents=True, exist_ok=True)
pyinstaller_build_root.mkdir(parents=True, exist_ok=True)
spec_root.mkdir(parents=True, exist_ok=True)
command = [
sys.executable,
"-m",
"PyInstaller",
"--noconfirm",
"--clean",
"--onefile",
"--windowed",
"--name",
"updater",
"--distpath",
str(dist_root),
"--workpath",
str(pyinstaller_build_root),
"--specpath",
str(spec_root),
]
if updater_icon.exists():
command += ["--icon", str(updater_icon)]
command.append(str(updater_script))
print("[UpdaterBuild] updater.exe 단독 빌드 시작")
run_command(command, base_dir)
updater_exe = dist_root / "updater.exe"
if not updater_exe.exists():
raise FileNotFoundError(f"빌드 결과가 없습니다: {updater_exe}")
shutil.copy2(config_src, config_dst)
print(f"[UpdaterBuild] 완료: {updater_exe}")
print(f"[UpdaterBuild] 설정 복사: {config_dst}")
print("[UpdaterBuild] 메인 패키징 전에 updater_build 폴더를 유지하세요.")
return 0
if __name__ == "__main__":
raise SystemExit(main())