112 lines
3.7 KiB
PowerShell
112 lines
3.7 KiB
PowerShell
# ============================================================
|
|
# configure_embed.ps1 — Configure le runtime Python embedded
|
|
# ------------------------------------------------------------
|
|
#
|
|
# Quand le composant 'pythonembed' est installe, on a :
|
|
# <AppDir>\python-embed\ <-- runtime Python 3.12 embedded
|
|
#
|
|
# Ce script :
|
|
# 1. Active l'import des packages (patch de python312._pth)
|
|
# 2. Installe pip dans le runtime embedded
|
|
# 3. Installe les dependances requirements_agent.txt
|
|
# 4. Reecrit Lea.bat pour pointer sur python-embed\pythonw.exe
|
|
#
|
|
# Doit etre execute avec le CWD = <AppDir>
|
|
# ============================================================
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$AppDir = Get-Location
|
|
$EmbedDir = Join-Path $AppDir "python-embed"
|
|
$PythonExe = Join-Path $EmbedDir "python.exe"
|
|
|
|
if (-not (Test-Path $PythonExe)) {
|
|
Write-Host "Python embedded introuvable, abandon."
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Configuration de Python embedded..."
|
|
|
|
# ---------------------------------------------------------------
|
|
# 1. Decommenter la ligne 'import site' dans python312._pth
|
|
# (necessaire pour que pip puisse fonctionner)
|
|
# ---------------------------------------------------------------
|
|
$PthFile = Get-ChildItem -Path $EmbedDir -Filter "python*._pth" | Select-Object -First 1
|
|
if ($PthFile) {
|
|
$Content = Get-Content $PthFile.FullName
|
|
$NewContent = $Content -replace '^#import site', 'import site'
|
|
Set-Content -Path $PthFile.FullName -Value $NewContent
|
|
Write-Host " python._pth patche (import site active)"
|
|
}
|
|
|
|
# ---------------------------------------------------------------
|
|
# 2-3. Verification des dependances embarquees (runtime 100% autonome)
|
|
# L'embed DOIT contenir toutes les dependances runtime.
|
|
# AUCUN pip, AUCUN reseau : si une dependance manque -> echec explicite.
|
|
# ---------------------------------------------------------------
|
|
$RequiredModules = @('socketio','tkinter','mss','pynput','pystray','plyer','requests','httpx','PIL','win32api')
|
|
$Missing = @()
|
|
foreach ($m in $RequiredModules) {
|
|
& $PythonExe -c "import $m" 2>$null
|
|
if ($LASTEXITCODE -ne 0) { $Missing += $m }
|
|
}
|
|
|
|
if ($Missing.Count -gt 0) {
|
|
Write-Host " ERREUR : runtime Lea incomplet. Modules manquants : $($Missing -join ', ')"
|
|
Write-Host " L'embed doit etre livre complet (aucune installation reseau en POC)."
|
|
exit 1
|
|
}
|
|
Write-Host " Dependances embarquees verifiees ($($RequiredModules.Count) modules) - offline OK."
|
|
|
|
# ---------------------------------------------------------------
|
|
# 4. Reecrire Lea.bat pour utiliser python-embed
|
|
# ---------------------------------------------------------------
|
|
$LeaBat = Join-Path $AppDir "Lea.bat"
|
|
$NewLeaBat = @"
|
|
@echo off
|
|
chcp 65001 >nul 2>&1
|
|
title Lea - Assistante IA
|
|
cd /d "%~dp0"
|
|
|
|
if exist "lea_agent.lock" (
|
|
for /f "usebackq tokens=* delims=" %%i in ("lea_agent.lock") do (
|
|
taskkill /F /PID %%i >nul 2>&1
|
|
)
|
|
del /f /q "lea_agent.lock" >nul 2>&1
|
|
timeout /t 2 >nul
|
|
)
|
|
|
|
if exist "config.txt" (
|
|
for /f "usebackq eol=# tokens=1,* delims==" %%a in ("config.txt") do (
|
|
if not "%%a"=="" if not "%%b"=="" set "%%a=%%b"
|
|
)
|
|
)
|
|
|
|
echo.
|
|
echo Demarrage de Lea (runtime embedded)...
|
|
echo.
|
|
|
|
start "" /b "%~dp0python-embed\pythonw.exe" run_agent_v1.py
|
|
|
|
timeout /t 3 >nul
|
|
set "LEA_ALIVE=0"
|
|
if exist "lea_agent.lock" (
|
|
for /f "usebackq tokens=* delims=" %%i in ("lea_agent.lock") do (
|
|
tasklist /FI "PID eq %%i" /NH 2>nul | findstr /I "pythonw" >nul && set "LEA_ALIVE=1"
|
|
)
|
|
)
|
|
if "%LEA_ALIVE%"=="0" (
|
|
echo.
|
|
echo Lea n'a pas demarre correctement. Affichage des erreurs :
|
|
echo.
|
|
"%~dp0python-embed\python.exe" run_agent_v1.py
|
|
pause
|
|
)
|
|
"@
|
|
|
|
Set-Content -Path $LeaBat -Value $NewLeaBat -Encoding ASCII
|
|
Write-Host " Lea.bat reecrit pour runtime embedded"
|
|
|
|
Write-Host "Configuration terminee."
|
|
exit 0
|