Les && sur une ligne avec where/set/goto causent des erreurs de syntaxe en batch Windows. Remplacé par des if/else classiques. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
497 lines
15 KiB
Batchfile
497 lines
15 KiB
Batchfile
@echo off
|
|
chcp 65001 >nul 2>&1
|
|
setlocal EnableDelayedExpansion
|
|
title Copydev Imposing Tool — Installation
|
|
|
|
set "APP_NAME=Copydev Imposing Tool"
|
|
set "INSTALL_DIR=%LOCALAPPDATA%\CopydevImposingTool"
|
|
set "PYTHON_DIR=%INSTALL_DIR%\python"
|
|
set "APP_DIR=%INSTALL_DIR%\app"
|
|
set "EXE_PATH=%INSTALL_DIR%\CopydevImposingTool.exe"
|
|
set "SHORTCUT_NAME=Copydev Imposing Tool"
|
|
set "GITEA_REPO=https://git.copydev.fr/jules/copydev-imposing-tool.git"
|
|
set "PYTHON_VERSION=3.12.8"
|
|
set "PYTHON_URL=https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-embed-amd64.zip"
|
|
set "GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py"
|
|
set "GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.2/MinGit-2.47.1.2-64-bit.zip"
|
|
|
|
:: ============================================================
|
|
:MENU
|
|
cls
|
|
echo ============================================================
|
|
echo %APP_NAME%
|
|
echo ============================================================
|
|
echo.
|
|
echo 1. Installer
|
|
echo 2. Mettre a jour
|
|
echo 3. Reparer (reinstaller Python + dependances)
|
|
echo 4. Desinstaller
|
|
echo 5. Quitter
|
|
echo.
|
|
set "CHOIX="
|
|
set /p "CHOIX=Votre choix [1-5] : "
|
|
|
|
if "%CHOIX%"=="1" goto INSTALL
|
|
if "%CHOIX%"=="2" goto UPDATE
|
|
if "%CHOIX%"=="3" goto REPAIR
|
|
if "%CHOIX%"=="4" goto UNINSTALL
|
|
if "%CHOIX%"=="5" goto FIN
|
|
echo Choix invalide.
|
|
timeout /t 2 >nul
|
|
goto MENU
|
|
|
|
:: ============================================================
|
|
:: INSTALLATION COMPLETE
|
|
:: ============================================================
|
|
:INSTALL
|
|
cls
|
|
echo ============================================================
|
|
echo INSTALLATION de %APP_NAME%
|
|
echo ============================================================
|
|
echo.
|
|
|
|
if exist "%APP_DIR%\main.py" (
|
|
echo [!] Deja installe dans %INSTALL_DIR%
|
|
set /p "REINSTALL=Reinstaller ? [O/N] : "
|
|
if /i "!REINSTALL!" neq "O" goto MENU
|
|
rmdir /s /q "%APP_DIR%" 2>nul
|
|
del "%EXE_PATH%" 2>nul
|
|
)
|
|
|
|
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
|
|
if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp"
|
|
|
|
:: ---- GIT ----
|
|
echo.
|
|
echo [1/7] Git...
|
|
set "GIT_CMD="
|
|
where git >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "GIT_CMD=git"
|
|
echo [OK] Git systeme
|
|
goto INSTALL_STEP2
|
|
)
|
|
if exist "%INSTALL_DIR%\git\cmd\git.exe" (
|
|
set "GIT_CMD=%INSTALL_DIR%\git\cmd\git.exe"
|
|
echo [OK] Git portable
|
|
goto INSTALL_STEP2
|
|
)
|
|
|
|
echo Telechargement de Git portable...
|
|
if not exist "%INSTALL_DIR%\git" mkdir "%INSTALL_DIR%\git"
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GIT_URL%' -OutFile '%INSTALL_DIR%\temp\git.zip' -UseBasicParsing"
|
|
if not exist "%INSTALL_DIR%\temp\git.zip" (
|
|
echo [ERREUR] Echec telechargement Git
|
|
pause
|
|
goto MENU
|
|
)
|
|
powershell -Command "Expand-Archive -Force '%INSTALL_DIR%\temp\git.zip' '%INSTALL_DIR%\git'"
|
|
del "%INSTALL_DIR%\temp\git.zip" 2>nul
|
|
if not exist "%INSTALL_DIR%\git\cmd\git.exe" (
|
|
echo [ERREUR] git.exe introuvable apres extraction
|
|
pause
|
|
goto MENU
|
|
)
|
|
set "GIT_CMD=%INSTALL_DIR%\git\cmd\git.exe"
|
|
echo [OK] Git portable installe
|
|
|
|
:: ---- PYTHON ----
|
|
:INSTALL_STEP2
|
|
echo.
|
|
echo [2/7] Python...
|
|
set "PYTHON_CMD="
|
|
if exist "%PYTHON_DIR%\python.exe" (
|
|
set "PYTHON_CMD=%PYTHON_DIR%\python.exe"
|
|
echo [OK] Python embarque
|
|
goto INSTALL_STEP3
|
|
)
|
|
where python >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "PYTHON_CMD=python"
|
|
echo [OK] Python systeme
|
|
goto INSTALL_STEP3
|
|
)
|
|
where py >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "PYTHON_CMD=py"
|
|
echo [OK] py launcher
|
|
goto INSTALL_STEP3
|
|
)
|
|
|
|
echo Telechargement de Python %PYTHON_VERSION%...
|
|
if not exist "%PYTHON_DIR%" mkdir "%PYTHON_DIR%"
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%PYTHON_URL%' -OutFile '%INSTALL_DIR%\temp\python.zip' -UseBasicParsing"
|
|
if not exist "%INSTALL_DIR%\temp\python.zip" (
|
|
echo [ERREUR] Echec telechargement Python
|
|
pause
|
|
goto MENU
|
|
)
|
|
echo Extraction...
|
|
powershell -Command "Expand-Archive -Force '%INSTALL_DIR%\temp\python.zip' '%PYTHON_DIR%'"
|
|
del "%INSTALL_DIR%\temp\python.zip" 2>nul
|
|
if not exist "%PYTHON_DIR%\python.exe" (
|
|
echo [ERREUR] python.exe introuvable apres extraction
|
|
dir "%PYTHON_DIR%" 2>nul
|
|
pause
|
|
goto MENU
|
|
)
|
|
:: Activer pip
|
|
for %%f in ("%PYTHON_DIR%\python*._pth") do (
|
|
powershell -Command "(Get-Content '%%f') -replace '#import site','import site' | Set-Content '%%f'"
|
|
)
|
|
set "PYTHON_CMD=%PYTHON_DIR%\python.exe"
|
|
echo [OK] Python %PYTHON_VERSION% installe
|
|
|
|
:: ---- PIP ----
|
|
:INSTALL_STEP3
|
|
echo.
|
|
echo [3/7] Pip...
|
|
"%PYTHON_CMD%" -m pip --version >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
echo [OK] pip deja present
|
|
goto INSTALL_STEP4
|
|
)
|
|
echo Installation de pip...
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GET_PIP_URL%' -OutFile '%INSTALL_DIR%\temp\get-pip.py' -UseBasicParsing"
|
|
"%PYTHON_CMD%" "%INSTALL_DIR%\temp\get-pip.py" --no-warn-script-location
|
|
del "%INSTALL_DIR%\temp\get-pip.py" 2>nul
|
|
"%PYTHON_CMD%" -m pip --version >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
echo [OK] pip installe
|
|
) else (
|
|
echo [ERREUR] pip n'a pas pu etre installe
|
|
pause
|
|
goto MENU
|
|
)
|
|
|
|
:: ---- DEPENDANCES ----
|
|
:INSTALL_STEP4
|
|
echo.
|
|
echo [4/7] Dependances Python...
|
|
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2
|
|
echo.
|
|
echo Verification...
|
|
"%PYTHON_CMD%" -c "import PyQt6; print(' [OK] PyQt6')" 2>nul || echo [MANQUANT] PyQt6
|
|
"%PYTHON_CMD%" -c "import pypdf; print(' [OK] pypdf')" 2>nul || echo [MANQUANT] pypdf
|
|
"%PYTHON_CMD%" -c "import reportlab; print(' [OK] reportlab')" 2>nul || echo [MANQUANT] reportlab
|
|
"%PYTHON_CMD%" -c "import pypdfium2; print(' [OK] pypdfium2')" 2>nul || echo [MANQUANT] pypdfium2
|
|
|
|
:: ---- CODE SOURCE ----
|
|
echo.
|
|
echo [5/7] Code source...
|
|
if exist "%APP_DIR%\.git" (
|
|
pushd "%APP_DIR%"
|
|
"%GIT_CMD%" pull origin master
|
|
popd
|
|
) else (
|
|
if exist "%APP_DIR%" rmdir /s /q "%APP_DIR%"
|
|
"%GIT_CMD%" clone "%GITEA_REPO%" "%APP_DIR%"
|
|
)
|
|
if not exist "%APP_DIR%\main.py" (
|
|
echo [ERREUR] main.py introuvable
|
|
pause
|
|
goto MENU
|
|
)
|
|
echo [OK] Code telecharge
|
|
|
|
:: ---- LANCEURS ----
|
|
echo.
|
|
echo [6/7] Creation des lanceurs...
|
|
|
|
(
|
|
echo @echo off
|
|
echo cd /d "%APP_DIR%"
|
|
echo "%PYTHON_CMD%" main.py
|
|
echo if errorlevel 1 pause
|
|
) > "%INSTALL_DIR%\lancer.bat"
|
|
|
|
(
|
|
echo Set WshShell = CreateObject^("WScript.Shell"^)
|
|
echo WshShell.CurrentDirectory = "%APP_DIR%"
|
|
echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False
|
|
) > "%INSTALL_DIR%\lancer.vbs"
|
|
|
|
set "LAUNCH_TARGET=%INSTALL_DIR%\lancer.vbs"
|
|
|
|
:: Raccourci Bureau
|
|
powershell -Command "$s = (New-Object -COM WScript.Shell).CreateShortcut([Environment]::GetFolderPath('Desktop')+'\%SHORTCUT_NAME%.lnk'); $s.TargetPath='%LAUNCH_TARGET%'; $s.WorkingDirectory='%APP_DIR%'; $s.Description='%APP_NAME%'; $s.Save()"
|
|
echo [OK] Raccourci Bureau
|
|
|
|
:: Raccourci Menu Demarrer
|
|
powershell -Command "$s = (New-Object -COM WScript.Shell).CreateShortcut('%APPDATA%\Microsoft\Windows\Start Menu\Programs\%SHORTCUT_NAME%.lnk'); $s.TargetPath='%LAUNCH_TARGET%'; $s.WorkingDirectory='%APP_DIR%'; $s.Description='%APP_NAME%'; $s.Save()"
|
|
echo [OK] Raccourci Menu Demarrer
|
|
|
|
:: ---- TEST ----
|
|
echo.
|
|
echo [7/7] Test de l'application...
|
|
"%PYTHON_CMD%" -c "import sys; sys.path.insert(0, r'%APP_DIR%'); from app.engine.pdf_utils import PAGE_SIZES; print(' [OK] Moteur PDF charge avec', len(PAGE_SIZES), 'formats')"
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo [ERREUR] Le moteur PDF ne se charge pas
|
|
echo Lancez manuellement pour voir l'erreur :
|
|
echo "%PYTHON_CMD%" "%APP_DIR%\main.py"
|
|
)
|
|
|
|
:: Nettoyage
|
|
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
|
|
|
echo.
|
|
echo ============================================================
|
|
echo INSTALLATION TERMINEE
|
|
echo ============================================================
|
|
echo.
|
|
echo Dossier : %INSTALL_DIR%
|
|
echo Python : %PYTHON_CMD%
|
|
echo.
|
|
echo Lancer : raccourci Bureau "%SHORTCUT_NAME%"
|
|
echo Debug : "%PYTHON_CMD%" "%APP_DIR%\main.py"
|
|
echo.
|
|
echo Mot de passe requis au lancement.
|
|
echo.
|
|
pause
|
|
goto MENU
|
|
|
|
:: ============================================================
|
|
:: MISE A JOUR
|
|
:: ============================================================
|
|
:UPDATE
|
|
cls
|
|
echo ============================================================
|
|
echo MISE A JOUR de %APP_NAME%
|
|
echo ============================================================
|
|
echo.
|
|
|
|
if not exist "%APP_DIR%\main.py" (
|
|
echo [!] Application non installee. Utilisez l'option 1.
|
|
pause
|
|
goto MENU
|
|
)
|
|
|
|
:: Trouver Git
|
|
set "GIT_CMD="
|
|
where git >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "GIT_CMD=git"
|
|
echo [OK] Git systeme
|
|
) else if exist "%INSTALL_DIR%\git\cmd\git.exe" (
|
|
set "GIT_CMD=%INSTALL_DIR%\git\cmd\git.exe"
|
|
echo [OK] Git portable
|
|
) else (
|
|
echo [ERREUR] Git introuvable. Utilisez l'option 3 ^(Reparer^).
|
|
pause
|
|
goto MENU
|
|
)
|
|
|
|
:: Trouver Python
|
|
set "PYTHON_CMD="
|
|
if exist "%PYTHON_DIR%\python.exe" (
|
|
set "PYTHON_CMD=%PYTHON_DIR%\python.exe"
|
|
echo [OK] Python embarque
|
|
goto UPDATE_PULL
|
|
)
|
|
where python >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "PYTHON_CMD=python"
|
|
echo [OK] Python systeme
|
|
goto UPDATE_PULL
|
|
)
|
|
where py >nul 2>&1
|
|
if %ERRORLEVEL%==0 (
|
|
set "PYTHON_CMD=py"
|
|
echo [OK] py launcher
|
|
goto UPDATE_PULL
|
|
)
|
|
echo [ERREUR] Python introuvable. Utilisez l'option 3 ^(Reparer^).
|
|
pause
|
|
goto MENU
|
|
|
|
:UPDATE_PULL
|
|
|
|
:: Pull
|
|
echo.
|
|
echo [1/3] Mise a jour du code...
|
|
pushd "%APP_DIR%"
|
|
"%GIT_CMD%" fetch origin 2>&1
|
|
|
|
set "COMMITS=0"
|
|
for /f %%i in ('"%GIT_CMD%" rev-list HEAD..origin/master --count 2^>nul') do set "COMMITS=%%i"
|
|
if "!COMMITS!"=="0" (
|
|
echo Deja a jour !
|
|
popd
|
|
echo.
|
|
pause
|
|
goto MENU
|
|
)
|
|
echo !COMMITS! nouveau^(x^) commit^(s^):
|
|
"%GIT_CMD%" log --oneline HEAD..origin/master 2>nul
|
|
echo.
|
|
"%GIT_CMD%" pull origin master
|
|
popd
|
|
echo [OK] Code mis a jour
|
|
|
|
:: Deps
|
|
echo.
|
|
echo [2/3] Mise a jour dependances...
|
|
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2
|
|
|
|
:: Test
|
|
echo.
|
|
echo [3/3] Test...
|
|
"%PYTHON_CMD%" -c "import sys; sys.path.insert(0, r'%APP_DIR%'); from app.engine.pdf_utils import PAGE_SIZES; print(' [OK] Moteur PDF charge')"
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo [ERREUR] Probleme detecte.
|
|
echo "%PYTHON_CMD%" "%APP_DIR%\main.py"
|
|
)
|
|
|
|
echo.
|
|
echo ============================================================
|
|
echo MISE A JOUR TERMINEE
|
|
echo ============================================================
|
|
echo.
|
|
pause
|
|
goto MENU
|
|
|
|
:: ============================================================
|
|
:: REPARATION
|
|
:: ============================================================
|
|
:REPAIR
|
|
cls
|
|
echo ============================================================
|
|
echo REPARATION de %APP_NAME%
|
|
echo ============================================================
|
|
echo.
|
|
echo Reinstalle Python + pip + dependances
|
|
echo.
|
|
|
|
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
|
|
if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp"
|
|
|
|
:: Supprimer ancien Python
|
|
echo [1/4] Nettoyage ancien Python...
|
|
if exist "%PYTHON_DIR%" rmdir /s /q "%PYTHON_DIR%"
|
|
echo [OK]
|
|
|
|
:: Python
|
|
echo.
|
|
echo [2/4] Installation Python %PYTHON_VERSION%...
|
|
if not exist "%PYTHON_DIR%" mkdir "%PYTHON_DIR%"
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%PYTHON_URL%' -OutFile '%INSTALL_DIR%\temp\python.zip' -UseBasicParsing"
|
|
if not exist "%INSTALL_DIR%\temp\python.zip" (
|
|
echo [ERREUR] Echec telechargement
|
|
pause
|
|
goto MENU
|
|
)
|
|
powershell -Command "Expand-Archive -Force '%INSTALL_DIR%\temp\python.zip' '%PYTHON_DIR%'"
|
|
del "%INSTALL_DIR%\temp\python.zip" 2>nul
|
|
if not exist "%PYTHON_DIR%\python.exe" (
|
|
echo [ERREUR] python.exe introuvable
|
|
pause
|
|
goto MENU
|
|
)
|
|
for %%f in ("%PYTHON_DIR%\python*._pth") do (
|
|
powershell -Command "(Get-Content '%%f') -replace '#import site','import site' | Set-Content '%%f'"
|
|
)
|
|
set "PYTHON_CMD=%PYTHON_DIR%\python.exe"
|
|
echo [OK] Python installe
|
|
|
|
:: Pip
|
|
echo.
|
|
echo [3/4] Installation pip + dependances...
|
|
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GET_PIP_URL%' -OutFile '%INSTALL_DIR%\temp\get-pip.py' -UseBasicParsing"
|
|
"%PYTHON_CMD%" "%INSTALL_DIR%\temp\get-pip.py" --no-warn-script-location
|
|
del "%INSTALL_DIR%\temp\get-pip.py" 2>nul
|
|
"%PYTHON_CMD%" -m pip install --upgrade --no-warn-script-location PyQt6 pypdf reportlab pypdfium2
|
|
|
|
:: Test
|
|
echo.
|
|
echo [4/4] Verification...
|
|
"%PYTHON_CMD%" -c "import PyQt6; print(' [OK] PyQt6')" 2>nul || echo [MANQUANT] PyQt6
|
|
"%PYTHON_CMD%" -c "import pypdf; print(' [OK] pypdf')" 2>nul || echo [MANQUANT] pypdf
|
|
"%PYTHON_CMD%" -c "import reportlab; print(' [OK] reportlab')" 2>nul || echo [MANQUANT] reportlab
|
|
"%PYTHON_CMD%" -c "import pypdfium2; print(' [OK] pypdfium2')" 2>nul || echo [MANQUANT] pypdfium2
|
|
|
|
if exist "%APP_DIR%\main.py" (
|
|
echo.
|
|
"%PYTHON_CMD%" -c "import sys; sys.path.insert(0, r'%APP_DIR%'); from app.engine.pdf_utils import PAGE_SIZES; print(' [OK] Application prete')"
|
|
|
|
:: Mettre a jour les lanceurs
|
|
(
|
|
echo @echo off
|
|
echo cd /d "%APP_DIR%"
|
|
echo "%PYTHON_CMD%" main.py
|
|
echo if errorlevel 1 pause
|
|
) > "%INSTALL_DIR%\lancer.bat"
|
|
(
|
|
echo Set WshShell = CreateObject^("WScript.Shell"^)
|
|
echo WshShell.CurrentDirectory = "%APP_DIR%"
|
|
echo WshShell.Run """%PYTHON_CMD%"" ""%APP_DIR%\main.py""", 0, False
|
|
) > "%INSTALL_DIR%\lancer.vbs"
|
|
echo [OK] Lanceurs mis a jour
|
|
)
|
|
|
|
rmdir /s /q "%INSTALL_DIR%\temp" 2>nul
|
|
|
|
echo.
|
|
echo ============================================================
|
|
echo REPARATION TERMINEE
|
|
echo ============================================================
|
|
echo.
|
|
echo Python : %PYTHON_CMD%
|
|
echo Debug : "%PYTHON_CMD%" "%APP_DIR%\main.py"
|
|
echo.
|
|
pause
|
|
goto MENU
|
|
|
|
:: ============================================================
|
|
:: DESINSTALLATION
|
|
:: ============================================================
|
|
:UNINSTALL
|
|
cls
|
|
echo ============================================================
|
|
echo DESINSTALLATION de %APP_NAME%
|
|
echo ============================================================
|
|
echo.
|
|
|
|
if not exist "%INSTALL_DIR%" (
|
|
echo [!] Application non installee.
|
|
pause
|
|
goto MENU
|
|
)
|
|
|
|
echo Seront supprimes :
|
|
echo - %INSTALL_DIR%
|
|
echo - Raccourcis Bureau et Menu Demarrer
|
|
echo.
|
|
set /p "CONFIRM=Confirmer ? [O/N] : "
|
|
if /i "%CONFIRM%" neq "O" goto MENU
|
|
|
|
echo.
|
|
del "%USERPROFILE%\Desktop\%SHORTCUT_NAME%.lnk" 2>nul
|
|
del "%APPDATA%\Microsoft\Windows\Start Menu\Programs\%SHORTCUT_NAME%.lnk" 2>nul
|
|
echo [OK] Raccourcis supprimes
|
|
|
|
taskkill /f /im python.exe 2>nul
|
|
taskkill /f /im CopydevImposingTool.exe 2>nul
|
|
timeout /t 2 >nul
|
|
rmdir /s /q "%INSTALL_DIR%" 2>nul
|
|
|
|
if exist "%INSTALL_DIR%" (
|
|
echo [!] Suppression incomplete. Supprimez manuellement :
|
|
echo %INSTALL_DIR%
|
|
) else (
|
|
echo [OK] Tout supprime
|
|
)
|
|
|
|
echo.
|
|
echo ============================================================
|
|
echo DESINSTALLATION TERMINEE
|
|
echo ============================================================
|
|
echo.
|
|
pause
|
|
goto MENU
|
|
|
|
:: ============================================================
|
|
:FIN
|
|
echo Au revoir !
|
|
timeout /t 2 >nul
|
|
exit /b 0
|