fix: fix Aur detection packages

This commit is contained in:
2026-05-27 07:41:44 +02:00
parent 8d0d9835be
commit 084d1f5b42
4 changed files with 235 additions and 1 deletions

View File

@ -5,6 +5,10 @@ import os
from datetime import datetime
import state as state_mod
from aur_manager import (
check_aur_updates, detect_active_user, detect_aur_helper,
install_aur_packages,
)
from classifier import classify
from config import FIRST_RUN_DELAY_SECONDS, SOCKET_PATH, UPDATE_INTERVAL_SECONDS
from package_manager import (
@ -37,6 +41,8 @@ class Daemon:
logger.info("pacman est verrouillé (autre processus actif), cycle ignoré")
return
asyncio.create_task(self.aur_cycle())
try:
self._set_status("checking")
logger.info("Vérification des mises à jour disponibles…")
@ -125,6 +131,56 @@ class Daemon:
self._add_error(str(e))
self._set_status("error")
async def aur_cycle(self):
helper = await asyncio.to_thread(detect_aur_helper)
if not helper:
logger.debug("Aucun helper AUR trouvé (paru/yay), AUR ignoré")
return
user = await asyncio.to_thread(detect_active_user)
if not user:
logger.info("Aucune session graphique active, AUR ignoré ce cycle")
return
logger.info(f"Vérification des mises à jour AUR avec {helper} (user={user})…")
packages = await asyncio.to_thread(check_aur_updates, user, helper)
# Fusionner avec les paquets AUR en attente du cycle précédent
existing = {p["name"] for p in self._state.get("pending_aur", [])}
for pkg in packages:
if pkg.name not in existing:
self._state.setdefault("pending_aur", []).append({
"name": pkg.name,
"old_version": pkg.old_version,
"new_version": pkg.new_version,
"queued_at": datetime.now().isoformat(),
})
existing.add(pkg.name)
self._save()
all_aur = self._state.get("pending_aur", [])
if not all_aur:
logger.info("Aucune mise à jour AUR disponible")
return
names = [p["name"] for p in all_aur]
logger.info(f"{len(names)} mise(s) à jour AUR : {', '.join(names)}")
result = await asyncio.to_thread(install_aur_packages, user, helper, names)
if result.success:
logger.info("Mises à jour AUR installées avec succès")
now = datetime.now().isoformat()
for pkg in all_aur:
self._state["installed_history"].append({**pkg, "installed_at": now})
self._state["installed_history"] = self._state["installed_history"][-200:]
self._state["pending_aur"] = []
else:
logger.error(f"Échec installation AUR : {result.error}")
self._add_error(f"Échec AUR : {result.error}")
self._save()
async def install_pending_cycle(self):
if self._state["status"] not in ("idle", "error"):
logger.info("Une opération est déjà en cours, installation ignorée")
@ -190,6 +246,9 @@ class Daemon:
elif action == "install_pending":
asyncio.create_task(self.install_pending_cycle())
response = {"status": "ok", "message": "Installation lancée"}
elif action == "install_aur":
asyncio.create_task(self.aur_cycle())
response = {"status": "ok", "message": "Installation AUR lancée"}
elif action == "get_state":
response = {"status": "ok", "state": self._state}
else: