Demande utilisateur : pouvoir identifier la build au premier coup d'oeil
sans confondre ancien/nouveau exe lors des tests.
Implémentation :
- build_info.py (gitignored, fallback "dev" pour mode développement)
régénéré automatiquement par scripts/rebuild_anon.ps1 avec :
BUILD_DATE = "2026-04-15 18:15"
BUILD_COMMIT = "234137e"
BUILD_BRANCH = "main"
- Pseudonymisation_Gui_V5.py : fonction _version_long() qui construit
"v5.4 · 2026-04-15 18:15 · #234137e" depuis build_info (avec fallback
silencieux si module absent en dev). Affichée dans :
- Titre fenêtre : "Pseudonymisation de vos documents — v5.4 · ..."
- Status bar en bas à droite
- anonymisation_onefile.spec : build_info.py ajouté aux datas bundlées.
- scripts/rebuild_anon.ps1 : STEP 4a génère build_info.py avant le
PyInstaller avec git rev-parse short + branch + date courante.
- .gitignore : build_info.py exclu (volatile, regénéré).
En mode dev (pas frozen) : affichage "v5.4" seul (fallback).
En mode frozen : affichage complet avec date/commit.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
129 lines
5.2 KiB
PowerShell
129 lines
5.2 KiB
PowerShell
# Rebuild script - anonymisation Windows
|
|
$ErrorActionPreference = "Continue"
|
|
$project = "C:\Users\dom\ai\anonymisation"
|
|
$gitea = "http://192.168.1.40:3100/Dom/anonymisation.git"
|
|
|
|
Write-Host "=== STEP 0 : Désactiver le .git parasite dans C:\Users\dom\ ==="
|
|
if (Test-Path "C:\Users\dom\.git") {
|
|
if (-not (Test-Path "C:\Users\dom\.git_parasite_disabled")) {
|
|
Rename-Item "C:\Users\dom\.git" "C:\Users\dom\.git_parasite_disabled" -ErrorAction SilentlyContinue
|
|
Write-Host " .git parasite renommé en .git_parasite_disabled"
|
|
} else {
|
|
Write-Host " .git_parasite_disabled existe déjà"
|
|
}
|
|
}
|
|
|
|
Write-Host "=== STEP 1 : Init/sync repo dans $project ==="
|
|
Set-Location $project
|
|
if (-not (Test-Path "$project\.git")) {
|
|
Write-Host " git init"
|
|
git init 2>&1 | Out-Host
|
|
Write-Host " git remote add gitea $gitea"
|
|
git remote add gitea $gitea 2>&1 | Out-Host
|
|
} else {
|
|
Write-Host " .git existe déjà"
|
|
$existing = git remote 2>&1 | Out-String
|
|
if ($existing -notmatch "gitea") {
|
|
git remote add gitea $gitea 2>&1 | Out-Host
|
|
}
|
|
}
|
|
|
|
Write-Host "=== STEP 2 : Fetch + reset main ==="
|
|
git fetch gitea 2>&1 | Out-Host
|
|
git checkout -B main 2>&1 | Out-Host
|
|
git reset --hard gitea/main 2>&1 | Out-Host
|
|
|
|
Write-Host "=== STEP 3 : Vérification du dernier commit ==="
|
|
git log --oneline -3 2>&1 | Out-Host
|
|
|
|
# Choix du venv
|
|
$venvPython = if (Test-Path "$project\venv\Scripts\python.exe") {
|
|
"$project\venv\Scripts\python.exe"
|
|
} elseif (Test-Path "$project\.venv\Scripts\python.exe") {
|
|
"$project\.venv\Scripts\python.exe"
|
|
} else {
|
|
Write-Host "ERREUR : aucun venv trouvé (ni venv\, ni .venv\)"
|
|
exit 1
|
|
}
|
|
Write-Host " Venv détecté : $venvPython"
|
|
|
|
Write-Host "=== STEP 4 : Régénérer finess_numbers.txt (entjur fix) ==="
|
|
& $venvPython "$project\scripts\build_finess_gazetteers.py" 2>&1 | Out-Host
|
|
|
|
Write-Host "=== STEP 4a : Générer build_info.py (identifiant de build) ==="
|
|
$commit = (git rev-parse --short HEAD 2>&1).Trim()
|
|
$branch = (git rev-parse --abbrev-ref HEAD 2>&1).Trim()
|
|
$buildDate = Get-Date -Format "yyyy-MM-dd HH:mm"
|
|
$buildInfo = @"
|
|
"""Métadonnées de build - GENERE AUTOMATIQUEMENT par rebuild_anon.ps1.
|
|
Ne PAS editer a la main - ecrase a chaque rebuild."""
|
|
BUILD_DATE = "$buildDate"
|
|
BUILD_COMMIT = "$commit"
|
|
BUILD_BRANCH = "$branch"
|
|
"@
|
|
$buildInfo | Set-Content "$project\build_info.py" -Encoding UTF8
|
|
Write-Host " build_info.py: $buildDate / $commit / $branch"
|
|
|
|
Write-Host "=== STEP 4bis : Désactiver scan Defender sur dist/ (évite locks PyInstaller) ==="
|
|
try {
|
|
Add-MpPreference -ExclusionPath "$project\dist" -ErrorAction SilentlyContinue
|
|
Add-MpPreference -ExclusionPath "$project\build" -ErrorAction SilentlyContinue
|
|
Write-Host " Exclusions Defender ajoutées (dist, build)"
|
|
} catch {
|
|
Write-Host " Impossible d'ajouter exclusion Defender : $_"
|
|
}
|
|
|
|
Write-Host "=== STEP 5 : Cleanup build/ et dist/ (contournement lock) ==="
|
|
# Stratégie anti-lock : RENOMMER l'ancien EXE au lieu de le supprimer.
|
|
# PyInstaller essaie de `os.remove` l'EXE existant avant d'en créer un nouveau.
|
|
# Si Defender/antivirus tient un handle sur le fichier, le remove échoue avec
|
|
# PermissionError WinError 5. En renommant AVANT (Move-Item bypass le lock de
|
|
# la plupart des scanners), PyInstaller voit dist\Anonymisation.exe absent et
|
|
# peut créer le nouveau fichier sans conflit.
|
|
$exePath = "$project\dist\Anonymisation.exe"
|
|
$timestampAvant = if (Test-Path $exePath) { (Get-Item $exePath).LastWriteTime } else { [DateTime]::MinValue }
|
|
|
|
# Renommer l'ancien EXE avec un suffixe timestamp (évite conflit si multiples retries)
|
|
if (Test-Path $exePath) {
|
|
$backupName = "Anonymisation.old-$(Get-Date -Format 'HHmmss').exe"
|
|
try {
|
|
Move-Item $exePath "$project\dist\$backupName" -Force -ErrorAction Stop
|
|
Write-Host " Ancien EXE renomme -> $backupName"
|
|
} catch {
|
|
Write-Host " AVERTISSEMENT : impossible de renommer l'ancien EXE : $_"
|
|
# Fallback : essayer de le supprimer quand meme (peut marcher si le lock se libere)
|
|
Remove-Item $exePath -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
# Nettoyer le dossier build/ (peut toujours etre verrouille mais moins critique)
|
|
if (Test-Path "$project\build") {
|
|
Remove-Item -Recurse -Force "$project\build" -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Host "=== STEP 6 : PyInstaller (5-15 min) ==="
|
|
$pyinstaller = if (Test-Path "$project\venv\Scripts\pyinstaller.exe") {
|
|
"$project\venv\Scripts\pyinstaller.exe"
|
|
} else {
|
|
"$project\.venv\Scripts\pyinstaller.exe"
|
|
}
|
|
& $pyinstaller --clean anonymisation_onefile.spec 2>&1 | Out-Host
|
|
|
|
Write-Host "=== STEP 7 : Vérification (timestamp AVANT/APRÈS) ==="
|
|
$exe = "$project\dist\Anonymisation.exe"
|
|
if (-not (Test-Path $exe)) {
|
|
Write-Host "ÉCHEC CRITIQUE : aucun exe produit"
|
|
exit 1
|
|
}
|
|
$timestampApres = (Get-Item $exe).LastWriteTime
|
|
if ($timestampApres -le $timestampAvant) {
|
|
$size = [math]::Round((Get-Item $exe).Length / 1MB, 1)
|
|
Write-Host "ÉCHEC CRITIQUE : l'exe n'a pas été mis à jour (timestamp inchangé)"
|
|
Write-Host " Avant : $timestampAvant"
|
|
Write-Host " Après : $timestampApres"
|
|
Write-Host " Taille : $size MB (mais c'est probablement l'ancien exe)"
|
|
exit 2
|
|
}
|
|
$size = [math]::Round((Get-Item $exe).Length / 1MB, 1)
|
|
Write-Host "OK : $exe ($size MB) - LastWriteTime : $timestampApres"
|