diff --git a/Excel/prod/Ratio_Cuisine.xlsm b/Excel/prod/Ratio_Cuisine.xlsm index 9607ac1..10eb254 100644 Binary files a/Excel/prod/Ratio_Cuisine.xlsm and b/Excel/prod/Ratio_Cuisine.xlsm differ diff --git a/Excel/prod/Ratio_Cuisine_VERSION.txt b/Excel/prod/Ratio_Cuisine_VERSION.txt new file mode 100644 index 0000000..681f15d --- /dev/null +++ b/Excel/prod/Ratio_Cuisine_VERSION.txt @@ -0,0 +1,2 @@ +4.1.2 +2025-11-17 diff --git a/Excel/prod/Ratio_Restauration.xlsm b/Excel/prod/Ratio_Restauration.xlsm index 2b38088..69ce435 100644 Binary files a/Excel/prod/Ratio_Restauration.xlsm and b/Excel/prod/Ratio_Restauration.xlsm differ diff --git a/Excel/prod/Ratio_Restauration_VERSION.txt b/Excel/prod/Ratio_Restauration_VERSION.txt new file mode 100644 index 0000000..6739ba8 --- /dev/null +++ b/Excel/prod/Ratio_Restauration_VERSION.txt @@ -0,0 +1,2 @@ +1.0.2 +2025-11-17 diff --git a/Scripts/Maj_prod_Cuisine.bat b/Scripts/Maj_prod_Cuisine.bat index 96dec5b..4865a8e 100644 --- a/Scripts/Maj_prod_Cuisine.bat +++ b/Scripts/Maj_prod_Cuisine.bat @@ -1,111 +1,32 @@ @echo off -chcp 1252 >nul -setlocal EnableExtensions +setlocal -REM ===================== PARAMS GENERAUX ===================== -set "ROOT=C:\Users\miche\PycharmProjects\Ratio_Inventaires" -set "PROD_DIR=%ROOT%\Excel\prod" -set "SHEET_NAME=Tableau de bord" -set "CELL_ADDR=U1" +REM Dossier où se trouve ce .bat (normalement ...\Ratio_Inventaires\Scripts\) +set SCRIPT_DIR=%~dp0 -REM ===================== CHOIX APPLI ========================= -REM Usage : maj_prod_ratio.bat CUISINE ou maj_prod_ratio.bat RESTAURATION +REM Racine du projet = dossier parent de Scripts +cd /d "%SCRIPT_DIR%\.." -set "APP=%~1" -if /I "%APP%"=="CUISINE" ( - set "BASE_NAME=Ratio_Cuisine" -) else if /I "%APP%"=="RESTAURATION" ( - set "BASE_NAME=Ratio_Restauration" -) else ( - echo. - echo Usage: %~n0 CUISINE^|RESTAURATION - echo Exemple: %~n0 CUISINE - endlocal & exit /b 1 +echo Répertoire courant : +echo %CD% +echo. + +echo --- Mise en prod Ratio_Cuisine --- + +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" -set "PROD_XLSM=%PROD_DIR%\%BASE_NAME%.xlsm" -set "VERSION_TXT=%ROOT%\Excel\dev\%BASE_NAME%_VERSION.txt" +REM 3) Copie du fichier Excel vers le dossier prod +copy /Y "Excel\dev\Ratio_Cuisine_dev.xlsm" "Excel\prod\Ratio_Cuisine.xlsm" -echo. -echo === Application : %APP% (%BASE_NAME%) ===================== - -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 +echo --- Mise en prod terminee --- +endlocal +exit /b 0 \ No newline at end of file diff --git a/Scripts/Maj_prod_Restauration.bat b/Scripts/Maj_prod_Restauration.bat index 96dec5b..a3b4941 100644 --- a/Scripts/Maj_prod_Restauration.bat +++ b/Scripts/Maj_prod_Restauration.bat @@ -1,111 +1,32 @@ @echo off -chcp 1252 >nul -setlocal EnableExtensions +setlocal -REM ===================== PARAMS GENERAUX ===================== -set "ROOT=C:\Users\miche\PycharmProjects\Ratio_Inventaires" -set "PROD_DIR=%ROOT%\Excel\prod" -set "SHEET_NAME=Tableau de bord" -set "CELL_ADDR=U1" +REM Dossier où se trouve ce .bat (normalement ...\Ratio_Inventaires\Scripts\) +set SCRIPT_DIR=%~dp0 -REM ===================== CHOIX APPLI ========================= -REM Usage : maj_prod_ratio.bat CUISINE ou maj_prod_ratio.bat RESTAURATION +REM Racine du projet = dossier parent de Scripts +cd /d "%SCRIPT_DIR%\.." -set "APP=%~1" -if /I "%APP%"=="CUISINE" ( - set "BASE_NAME=Ratio_Cuisine" -) else if /I "%APP%"=="RESTAURATION" ( - set "BASE_NAME=Ratio_Restauration" -) else ( - echo. - echo Usage: %~n0 CUISINE^|RESTAURATION - echo Exemple: %~n0 CUISINE - endlocal & exit /b 1 +echo Répertoire courant : +echo %CD% +echo. + +echo --- Mise en prod Ratio_Restauration --- + +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" -set "PROD_XLSM=%PROD_DIR%\%BASE_NAME%.xlsm" -set "VERSION_TXT=%ROOT%\Excel\dev\%BASE_NAME%_VERSION.txt" +REM 3) Copie du fichier Excel vers le dossier prod +copy /Y "Excel\dev\Ratio_Restauration_dev.xlsm" "Excel\prod\Ratio_Restauration.xlsm" -echo. -echo === Application : %APP% (%BASE_NAME%) ===================== - -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 +echo --- Mise en prod terminee --- +endlocal +exit /b 0 diff --git a/Scripts/Scripts/maj_version.py b/Scripts/Scripts/maj_version.py deleted file mode 100644 index e69de29..0000000 diff --git a/Scripts/maj_version.py b/Scripts/maj_version.py new file mode 100644 index 0000000..8533e0e --- /dev/null +++ b/Scripts/maj_version.py @@ -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() +