DMF_Crawler/bootstrap.cmd
Yun Chan 56a6e2da93 chore: 저장소 구조 정리 및 문서화, 첫 커밋
- src/dist 산출물 분리 원칙 정리(.gitignore, .gitattributes)
- 루트 및 주요 폴더(config/scripts/prompts/tests/src, 런타임 폴더 5종)에
  안내용 README.md 추가
- CHANGELOG.md, LICENSE, docs/ops/05-release-and-versioning.md 추가
- docs/README.md 문서 지도 갱신
2026-09-04 09:25:44 +09:00

226 lines
7.9 KiB
Batchfile

@echo off
setlocal EnableExtensions EnableDelayedExpansion
title DMF Crawler Install
cd /d "%~dp0"
set "ROOT=%~dp0"
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
set "VENV=%ROOT%\.venv"
set "VPY=%VENV%\Scripts\python.exe"
set "VPYW=%VENV%\Scripts\pythonw.exe"
set "LOGDIR=%ROOT%\logs"
if not exist "%LOGDIR%" mkdir "%LOGDIR%" >nul 2>&1
set "LOG=%LOGDIR%\bootstrap.log"
echo ================================================
echo DMF Crawler First-Time Setup
echo ================================================
echo.
echo This window closes itself when setup finishes.
echo It appears only once.
echo.
rem ===================================================================
rem [1/5] Find Python
rem Note: python.exe on PATH does not always mean Python is installed.
rem The Microsoft Store app-execution-alias stub is always on
rem PATH and returns an error code when run with arguments
rem (per Microsoft's own FAQ). So the py launcher is tried first;
rem the Store stub ships without py.
rem ===================================================================
echo [1/5] Looking for Python...
set "PYEXE="
rem -- if a venv already exists, reuse it (fast path on re-run)
if exist "%VPY%" (
"%VPY%" -c "import sys;raise SystemExit(0 if sys.version_info>=(3,11) else 1)" >nul 2>&1
if !errorlevel! equ 0 (
set "PYEXE=%VPY%"
echo Using existing environment.
goto :have_python
)
)
rem -- 1st choice: py launcher
where py.exe >nul 2>&1
if !errorlevel! equ 0 (
for %%V in (3.13 3.12 3.11) do (
if not defined PYEXE (
py -%%V -c "import sys" >nul 2>&1
if !errorlevel! equ 0 (
for /f "delims=" %%P in ('py -%%V -c "import sys;print(sys.executable)" 2^>nul') do set "PYEXE=%%P"
)
)
)
if not defined PYEXE (
py -3 -c "import sys;raise SystemExit(0 if sys.version_info>=(3,11) else 1)" >nul 2>&1
if !errorlevel! equ 0 (
for /f "delims=" %%P in ('py -3 -c "import sys;print(sys.executable)" 2^>nul') do set "PYEXE=%%P"
)
)
)
rem -- 2nd choice: python.exe on PATH (confirm it actually runs, not a stub)
if not defined PYEXE (
python -c "import sys;raise SystemExit(0 if sys.version_info>=(3,11) else 1)" >nul 2>&1
if !errorlevel! equ 0 (
for /f "delims=" %%P in ('python -c "import sys;print(sys.executable)" 2^>nul') do set "PYEXE=%%P"
)
)
rem -- 3rd choice: search well-known install paths directly
if not defined PYEXE (
for %%D in (
"%LOCALAPPDATA%\Programs\Python\Python313"
"%LOCALAPPDATA%\Programs\Python\Python312"
"%LOCALAPPDATA%\Programs\Python\Python311"
"C:\Python313" "C:\Python312" "C:\Python311"
) do (
if not defined PYEXE if exist "%%~D\python.exe" set "PYEXE=%%~D\python.exe"
)
)
if defined PYEXE goto :have_python
rem ===================================================================
rem No Python found -> ask whether to install it
rem ===================================================================
echo Not installed.
echo.
echo Install Python now? ^(about 2-5 minutes^)
echo Administrator rights are not required.
echo.
choice /c YN /n /m " [Y] Yes, install it [N] No, I will install it myself Choice: "
if errorlevel 2 goto :manual_python
echo.
echo Installing Python. Do not close this window...
where winget.exe >nul 2>&1
if !errorlevel! neq 0 goto :manual_python
winget install --id Python.Python.3.12 --scope user --silent ^
--accept-package-agreements --accept-source-agreements >>"%LOG%" 2>&1
rem -- this window's PATH is not refreshed right after install. Search directly.
for %%D in (
"%LOCALAPPDATA%\Programs\Python\Python313"
"%LOCALAPPDATA%\Programs\Python\Python312"
"%LOCALAPPDATA%\Programs\Python\Python311"
) do (
if not defined PYEXE if exist "%%~D\python.exe" set "PYEXE=%%~D\python.exe"
)
if not defined PYEXE (
where py.exe >nul 2>&1
if !errorlevel! equ 0 (
for /f "delims=" %%P in ('py -3 -c "import sys;print(sys.executable)" 2^>nul') do set "PYEXE=%%P"
)
)
if not defined PYEXE goto :manual_python
echo Installed.
:have_python
echo Found: %PYEXE%
echo.
rem ===================================================================
rem [2/5] Virtual environment + dependencies
rem ===================================================================
echo [2/5] Preparing the runtime environment... ^(30 sec - 2 min^)
if not exist "%VPY%" (
"%PYEXE%" -m venv "%VENV%" >>"%LOG%" 2>&1
if !errorlevel! neq 0 goto :fail_venv
)
"%VPY%" -m pip install --upgrade pip --disable-pip-version-check -q >>"%LOG%" 2>&1
"%VPY%" -m pip install -e "%ROOT%" --disable-pip-version-check -q >>"%LOG%" 2>&1
if !errorlevel! neq 0 goto :fail_deps
echo Done
echo.
rem ===================================================================
rem [3/5] Remove Mark-of-the-Web
rem Files extracted from a downloaded ZIP get a Zone.Identifier stream,
rem which can block .ps1 execution. This is the same action as the
rem [Unblock] checkbox in a file's Properties dialog.
rem ===================================================================
echo [3/5] Unblocking files...
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass ^
-Command "Get-ChildItem -LiteralPath '%ROOT%' -Recurse -File -ErrorAction SilentlyContinue | Unblock-File -ErrorAction SilentlyContinue" >>"%LOG%" 2>&1
echo Done
echo.
rem ===================================================================
rem [4/5] Shortcuts
rem ===================================================================
echo [4/5] Creating desktop shortcuts...
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass ^
-File "%ROOT%\scripts\make_shortcuts.ps1" -ProjectRoot "%ROOT%" >>"%LOG%" 2>&1
if !errorlevel! neq 0 (
echo Skipped ^(the program still works without shortcuts^)
) else (
echo Done
)
echo.
rem ===================================================================
rem [5/5] Launch the onboarding GUI
rem pythonw.exe does not create a console. Launch it with start "" and
rem close this window.
rem ===================================================================
echo [5/5] Opening the setup window...
echo.
echo Setup finished. The setup window will open in a moment.
start "" "%VPYW%" -m dmf_crawler onboard --mode setup
timeout /t 3 /nobreak >nul
exit /b 0
rem ===================================================================
rem Failure paths - always tell the user what to do next
rem ===================================================================
:manual_python
echo.
echo ------------------------------------------------
echo Please install Python yourself
echo ------------------------------------------------
echo.
echo 1. Open this address in your browser.
echo https://www.python.org/downloads/
echo 2. Click [Download Python 3.12.x] to get the installer.
echo 3. Near the bottom of the installer screen,
echo check the box [Add python.exe to PATH]
echo 4. When installation finishes, close this window and run
echo bootstrap.cmd again.
echo.
choice /c YN /n /m " Open the download page now? [Y/N]: "
if not errorlevel 2 start "" "https://www.python.org/downloads/"
echo.
pause
exit /b 1
:fail_venv
echo.
echo [Error] Could not create the runtime environment.
echo.
echo Please check the following.
echo - Whether this folder allows creating files
echo ^(if it is under C:\Program Files, move it to Documents^)
echo - Whether antivirus software is blocking it
echo.
echo Details: %LOG%
echo.
pause
exit /b 1
:fail_deps
echo.
echo [Error] Could not download the required components.
echo.
echo Please check the following.
echo - Whether this computer is connected to the internet
echo - Whether a company firewall blocks pypi.org
echo ^(ask IT to allow pypi.org and files.pythonhosted.org^)
echo.
echo Details: %LOG%
echo.
pause
exit /b 1