Mise en production : mise à jour des classeurs Cuisine/Restauration, scripts de mise à jour, versioning

This commit is contained in:
2025-11-17 15:55:30 +01:00
parent 37465a9ece
commit c1f25eb61d
8 changed files with 105 additions and 208 deletions

Binary file not shown.

View File

@@ -0,0 +1,2 @@
4.1.2
2025-11-17

Binary file not shown.

View File

@@ -0,0 +1,2 @@
1.0.2
2025-11-17

View File

@@ -1,111 +1,32 @@
@echo off @echo off
chcp 1252 >nul setlocal
setlocal EnableExtensions
REM ===================== PARAMS GENERAUX ===================== REM Dossier où se trouve ce .bat (normalement ...\Ratio_Inventaires\Scripts\)
set "ROOT=C:\Users\miche\PycharmProjects\Ratio_Inventaires" set SCRIPT_DIR=%~dp0
set "PROD_DIR=%ROOT%\Excel\prod"
set "SHEET_NAME=Tableau de bord"
set "CELL_ADDR=U1"
REM ===================== CHOIX APPLI ========================= REM Racine du projet = dossier parent de Scripts
REM Usage : maj_prod_ratio.bat CUISINE ou maj_prod_ratio.bat RESTAURATION cd /d "%SCRIPT_DIR%\.."
set "APP=%~1" echo Répertoire courant :
if /I "%APP%"=="CUISINE" ( echo %CD%
set "BASE_NAME=Ratio_Cuisine"
) else if /I "%APP%"=="RESTAURATION" (
set "BASE_NAME=Ratio_Restauration"
) else (
echo. echo.
echo Usage: %~n0 CUISINE^|RESTAURATION
echo Exemple: %~n0 CUISINE echo --- Mise en prod Ratio_Cuisine ---
endlocal & exit /b 1
REM 1) Mise à jour automatique de la version
python "%SCRIPT_DIR%maj_version.py" "Excel\prod\Ratio_Cuisine_VERSION.txt"
REM 2) Vérifier que le fichier source existe (dev)
if not exist "Excel\dev\Ratio_Cuisine_dev.xlsm" (
echo ERREUR : fichier source introuvable : Excel\dev\Ratio_Cuisine_dev.xlsm
pause
endlocal
exit /b 1
) )
set "DEV_XLSM=%ROOT%\Excel\dev\%BASE_NAME%_dev.xlsm" REM 3) Copie du fichier Excel vers le dossier prod
set "PROD_XLSM=%PROD_DIR%\%BASE_NAME%.xlsm" copy /Y "Excel\dev\Ratio_Cuisine_dev.xlsm" "Excel\prod\Ratio_Cuisine.xlsm"
set "VERSION_TXT=%ROOT%\Excel\dev\%BASE_NAME%_VERSION.txt"
echo. echo --- Mise en prod terminee ---
echo === Application : %APP% (%BASE_NAME%) ===================== endlocal
exit /b 0
echo.
echo === [1/4] Prep ============================================
if not exist "%PROD_DIR%" md "%PROD_DIR%"
if not exist "%DEV_XLSM%" goto ERR_NO_DEV
if not exist "%VERSION_TXT%" (
>"%VERSION_TXT%" echo 1.0.0
echo [INFO] %BASE_NAME%_VERSION.txt created with 1.0.0
)
for /f %%i in ('powershell -NoProfile -Command "(Get-Date).ToString('yyyy_MM_dd')"') do set "DATESTAMP=%%i"
set "ARCHIVE_FILE=%PROD_DIR%\%BASE_NAME%_%DATESTAMP%.xlsm"
echo.
echo === [2/4] Lire VERSION.txt et maj cellule ==================
for /f "usebackq delims=" %%v in ("%VERSION_TXT%") do set "NEW_VER=%%v"
set "NEW_VER=%NEW_VER: =%"
if "%NEW_VER%"=="" goto ERR_EMPTY_VER
echo Version: %NEW_VER%
REM Mise a jour de la cellule dans DEV via VBS (macros & evenements OFF)
cscript //nologo "%ROOT%\Scripts\set_cell_silent.vbs" "%DEV_XLSM%" "%SHEET_NAME%" "%CELL_ADDR%" "%NEW_VER%"
if errorlevel 1 goto U1_FAIL
echo [OK] %CELL_ADDR% updated on DEV: %NEW_VER%
goto AFTER_U1
:U1_FAIL
echo [WARN] %CELL_ADDR% update failed on DEV (continuing).
:AFTER_U1
echo.
echo === [3/4] Backup PROD et purge archives ===================
if not exist "%PROD_XLSM%" goto NO_BACKUP
echo Backup -> "%ARCHIVE_FILE%"
copy /Y "%PROD_XLSM%" "%ARCHIVE_FILE%" >nul
goto AFTER_BACKUP
:NO_BACKUP
echo Pas de PROD a sauvegarder.
:AFTER_BACKUP
REM Garder uniquement les 5 dernières archives
powershell -NoProfile -Command "Get-ChildItem -LiteralPath '%PROD_DIR%' -Filter '%BASE_NAME%_20*_??_??.xlsm' | Sort-Object LastWriteTime -Descending | Select-Object -Skip 5 | Remove-Item -Force -ErrorAction SilentlyContinue"
echo.
echo === [4/4] Copier DEV -> PROD ==============================
copy /Y "%DEV_XLSM%" "%PROD_XLSM%"
if errorlevel 1 goto ERR_COPY
>"%PROD_DIR%\%BASE_NAME%_VERSION.txt" echo %NEW_VER%
echo.
echo [OK] Termine pour %APP% :
echo Version : %NEW_VER%
echo PROD : "%PROD_XLSM%"
echo VERSION : "%PROD_DIR%\%BASE_NAME%_VERSION.txt"
echo.
endlocal & exit /b 0
REM ===================== ERRORS ===============================
:ERR_NO_DEV
echo [ERROR] DEV file not found: "%DEV_XLSM%"
endlocal & exit /b 1
:ERR_EMPTY_VER
echo [ERROR] "%VERSION_TXT%" is empty. Put a version like 1.8.3 and rerun.
endlocal & exit /b 1
:ERR_COPY
echo [ERROR] Copy DEV -> PROD failed.
endlocal & exit /b 1

View File

@@ -1,111 +1,32 @@
@echo off @echo off
chcp 1252 >nul setlocal
setlocal EnableExtensions
REM ===================== PARAMS GENERAUX ===================== REM Dossier où se trouve ce .bat (normalement ...\Ratio_Inventaires\Scripts\)
set "ROOT=C:\Users\miche\PycharmProjects\Ratio_Inventaires" set SCRIPT_DIR=%~dp0
set "PROD_DIR=%ROOT%\Excel\prod"
set "SHEET_NAME=Tableau de bord"
set "CELL_ADDR=U1"
REM ===================== CHOIX APPLI ========================= REM Racine du projet = dossier parent de Scripts
REM Usage : maj_prod_ratio.bat CUISINE ou maj_prod_ratio.bat RESTAURATION cd /d "%SCRIPT_DIR%\.."
set "APP=%~1" echo Répertoire courant :
if /I "%APP%"=="CUISINE" ( echo %CD%
set "BASE_NAME=Ratio_Cuisine"
) else if /I "%APP%"=="RESTAURATION" (
set "BASE_NAME=Ratio_Restauration"
) else (
echo. echo.
echo Usage: %~n0 CUISINE^|RESTAURATION
echo Exemple: %~n0 CUISINE echo --- Mise en prod Ratio_Restauration ---
endlocal & exit /b 1
REM 1) Mise à jour automatique de la version
python "%SCRIPT_DIR%maj_version.py" "Excel\prod\Ratio_Restauration_VERSION.txt"
REM 2) Vérifier que le fichier source existe (dev)
if not exist "Excel\dev\Ratio_Restauration_dev.xlsm" (
echo ERREUR : fichier source introuvable : Excel\dev\Ratio_Restauration_dev.xlsm
pause
endlocal
exit /b 1
) )
set "DEV_XLSM=%ROOT%\Excel\dev\%BASE_NAME%_dev.xlsm" REM 3) Copie du fichier Excel vers le dossier prod
set "PROD_XLSM=%PROD_DIR%\%BASE_NAME%.xlsm" copy /Y "Excel\dev\Ratio_Restauration_dev.xlsm" "Excel\prod\Ratio_Restauration.xlsm"
set "VERSION_TXT=%ROOT%\Excel\dev\%BASE_NAME%_VERSION.txt"
echo. echo --- Mise en prod terminee ---
echo === Application : %APP% (%BASE_NAME%) ===================== endlocal
exit /b 0
echo.
echo === [1/4] Prep ============================================
if not exist "%PROD_DIR%" md "%PROD_DIR%"
if not exist "%DEV_XLSM%" goto ERR_NO_DEV
if not exist "%VERSION_TXT%" (
>"%VERSION_TXT%" echo 1.0.0
echo [INFO] %BASE_NAME%_VERSION.txt created with 1.0.0
)
for /f %%i in ('powershell -NoProfile -Command "(Get-Date).ToString('yyyy_MM_dd')"') do set "DATESTAMP=%%i"
set "ARCHIVE_FILE=%PROD_DIR%\%BASE_NAME%_%DATESTAMP%.xlsm"
echo.
echo === [2/4] Lire VERSION.txt et maj cellule ==================
for /f "usebackq delims=" %%v in ("%VERSION_TXT%") do set "NEW_VER=%%v"
set "NEW_VER=%NEW_VER: =%"
if "%NEW_VER%"=="" goto ERR_EMPTY_VER
echo Version: %NEW_VER%
REM Mise a jour de la cellule dans DEV via VBS (macros & evenements OFF)
cscript //nologo "%ROOT%\Scripts\set_cell_silent.vbs" "%DEV_XLSM%" "%SHEET_NAME%" "%CELL_ADDR%" "%NEW_VER%"
if errorlevel 1 goto U1_FAIL
echo [OK] %CELL_ADDR% updated on DEV: %NEW_VER%
goto AFTER_U1
:U1_FAIL
echo [WARN] %CELL_ADDR% update failed on DEV (continuing).
:AFTER_U1
echo.
echo === [3/4] Backup PROD et purge archives ===================
if not exist "%PROD_XLSM%" goto NO_BACKUP
echo Backup -> "%ARCHIVE_FILE%"
copy /Y "%PROD_XLSM%" "%ARCHIVE_FILE%" >nul
goto AFTER_BACKUP
:NO_BACKUP
echo Pas de PROD a sauvegarder.
:AFTER_BACKUP
REM Garder uniquement les 5 dernières archives
powershell -NoProfile -Command "Get-ChildItem -LiteralPath '%PROD_DIR%' -Filter '%BASE_NAME%_20*_??_??.xlsm' | Sort-Object LastWriteTime -Descending | Select-Object -Skip 5 | Remove-Item -Force -ErrorAction SilentlyContinue"
echo.
echo === [4/4] Copier DEV -> PROD ==============================
copy /Y "%DEV_XLSM%" "%PROD_XLSM%"
if errorlevel 1 goto ERR_COPY
>"%PROD_DIR%\%BASE_NAME%_VERSION.txt" echo %NEW_VER%
echo.
echo [OK] Termine pour %APP% :
echo Version : %NEW_VER%
echo PROD : "%PROD_XLSM%"
echo VERSION : "%PROD_DIR%\%BASE_NAME%_VERSION.txt"
echo.
endlocal & exit /b 0
REM ===================== ERRORS ===============================
:ERR_NO_DEV
echo [ERROR] DEV file not found: "%DEV_XLSM%"
endlocal & exit /b 1
:ERR_EMPTY_VER
echo [ERROR] "%VERSION_TXT%" is empty. Put a version like 1.8.3 and rerun.
endlocal & exit /b 1
:ERR_COPY
echo [ERROR] Copy DEV -> PROD failed.
endlocal & exit /b 1

51
Scripts/maj_version.py Normal file
View File

@@ -0,0 +1,51 @@
import sys
from pathlib import Path
from datetime import date
def lire_version(path: Path):
if not path.exists():
return [1, 0, 0]
contenu = path.read_text(encoding="utf-8").strip().splitlines()
if not contenu:
return [1, 0, 0]
version_str = contenu[0].strip()
try:
parts = [int(x) for x in version_str.split(".")]
while len(parts) < 3:
parts.append(0)
return parts[:3]
except ValueError:
return [1, 0, 0]
def ecrire_version(path: Path, version):
version_str = ".".join(str(x) for x in version)
today = date.today().isoformat()
texte = f"{version_str}\n{today}\n"
path.write_text(texte, encoding="utf-8")
return version_str
def increment_patch(version):
version[2] += 1
return version
def main():
if len(sys.argv) < 2:
print("Usage : python maj_version.py chemin_du_VERSION.txt")
sys.exit(1)
version_file = Path(sys.argv[1])
version = lire_version(version_file)
version = increment_patch(version)
new_version_str = ecrire_version(version_file, version)
print(f"Nouvelle version : {new_version_str}")
if __name__ == "__main__":
main()