-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlaunch_win.bat
More file actions
89 lines (77 loc) · 2.42 KB
/
launch_win.bat
File metadata and controls
89 lines (77 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
@REM Launch BallonsTranslator for Windows portable bundle layout.
@echo off
setlocal
cd /d "%~dp0"
:: Set the path for PaddleOCR and PyTorch libraries (when bundled runtime is present)
set "PADDLE_PATH=%~dp0ballontrans_pylibs_win\Lib\site-packages\torch\lib"
if exist "%PADDLE_PATH%" set "PATH=%PADDLE_PATH%;%PATH%"
:: Prefer existing project venv, then bundled portable python, then system Python launcher/python.
set "PYTHON="
set "PY_MODE_FILE=.bt_python_mode"
set "PY_MODE="
if exist "%PY_MODE_FILE%" (
set /p PY_MODE=<"%PY_MODE_FILE%"
)
if /I "%PY_MODE%"=="venv" (
if exist "venv\Scripts\python.exe" set "PYTHON=venv\Scripts\python.exe"
)
if /I "%PY_MODE%"=="system" (
py -3 -c "" >NUL 2>NUL
if %ERRORLEVEL% == 0 set "PYTHON=py -3"
if not defined PYTHON (
python -c "" >NUL 2>NUL
if %ERRORLEVEL% == 0 set "PYTHON=python"
)
)
if not defined PYTHON if exist "venv\Scripts\python.exe" set "PYTHON=venv\Scripts\python.exe"
if not defined PYTHON if exist "ballontrans_pylibs_win\python.exe" set "PYTHON=ballontrans_pylibs_win\python.exe"
if not defined PYTHON (
py -3 -c "" >NUL 2>NUL
if %ERRORLEVEL% == 0 set "PYTHON=py -3"
)
if not defined PYTHON (
python -c "" >NUL 2>NUL
if %ERRORLEVEL% == 0 set "PYTHON=python"
)
set ERROR_REPORTING=FALSE
mkdir tmp 2>NUL
if not defined PYTHON (
>tmp\stdout.txt echo.
>tmp\stderr.txt echo Python was not found. Install Python 3.10+ or run setup.bat to create/use a venv.
echo Couldn't launch python
goto :show_stdout_stderr
)
%PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :check_pip
echo Couldn't launch python
goto :show_stdout_stderr
:check_pip
%PYTHON% -m pip --help >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :launch
if "%PIP_INSTALLER_LOCATION%" == "" goto :show_stdout_stderr
%PYTHON% "%PIP_INSTALLER_LOCATION%" >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :launch
echo Couldn't install pip
goto :show_stdout_stderr
:launch
start "BallonsTranslator" cmd /k "cd /d ""%~dp0"" && %PYTHON% launch.py %*"
exit /b
:show_stdout_stderr
echo.
echo exit code: %errorlevel%
for /f %%i in ("tmp\stdout.txt") do set size=%%~zi
if %size% equ 0 goto :show_stderr
echo.
echo stdout:
type tmp\stdout.txt
:show_stderr
for /f %%i in ("tmp\stderr.txt") do set size=%%~zi
if %size% equ 0 goto :endofscript
echo.
echo stderr:
type tmp\stderr.txt
:endofscript
echo.
echo Launch unsuccessful. Exiting.
pause
exit /b