Repository Public MIT Research preview
1"""Le même flux de travail, sur de VRAIS fichiers, mais dans un dossier temporaire.23Aucune commande du système n'est lancée : tout passe par pathlib. Le dossier temporaire est créé4par tempfile.TemporaryDirectory et supprimé, avec tout son contenu, à la sortie du bloc « with ».5Rien d'autre sur le disque n'est lu ni modifié.6"""7from __future__ import annotations89import tempfile10from pathlib import Path1112from atlas_s11.monde import NOTES131415def flux_reel() -> dict:16 """Crée les notes, cherche les retards, écrit le rapport, vérifie, puis laisse tout disparaître."""17 with tempfile.TemporaryDirectory(prefix="atlas-s11-") as nom:18 bac = Path(nom) / "atelier" # équivalent de : mkdir atelier19 (bac / "notes").mkdir(parents=True)20 for fichier, contenu in NOTES.items():21 (bac / "notes" / fichier).write_text(contenu, encoding="utf-8")22 textes = sorted(p.relative_to(bac).as_posix() for p in bac.rglob("*.txt")) # find . -name "*.txt"23 retards = []24 for fichier in sorted((bac / "notes").glob("*.txt")): # grep retard notes/*.txt25 retards += [ligne for ligne in fichier.read_text(encoding="utf-8").splitlines() if "retard" in ligne]26 (bac / "rapports").mkdir(exist_ok=True) # mkdir -p rapports27 rapport = bac / "rapports" / "retards.txt"28 rapport.write_text("".join(ligne + "\n" for ligne in retards), encoding="utf-8") # > retards.txt29 relu = rapport.read_text(encoding="utf-8") # cat rapports/retards.txt30 bilan = {31 "fichiers_texte": textes,32 "rapport": relu,33 "lignes_rapport": len(relu.splitlines()),34 "fichiers_crees": sum(1 for p in bac.rglob("*") if p.is_file()),35 "tout_dans_le_dossier_temporaire": all(Path(nom) in p.parents for p in bac.rglob("*")),36 "existait_pendant": bac.is_dir(),37 }38 bilan["existe_apres"] = Path(nom).exists()39 return bilan40