Files
apim-apps/apim_apps/report.py
T
2026-06-29 14:22:37 +02:00

53 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from ._colors import _c
from .models import NormResult
def print_report(results: dict[str, NormResult], dry_run: bool):
mode = _c("yellow", "[DRY-RUN] ") if dry_run else ""
print()
print(_c("bold", f"{'─'*65}"))
print(_c("bold", f" {mode}Rapport de normalisation"))
print(_c("bold", f"{'─'*65}"))
total_done = total_skip = total_err = 0
for env_name, result in results.items():
done = len(result.actions_done)
skip = len(result.actions_skipped)
err = len(result.errors)
total_done += done
total_skip += skip
total_err += err
status = _c("green", "✅") if err == 0 else _c("red", "❌")
print(f"\n {status} {_c('bold', env_name)}")
print(f" Actions {'simulées' if dry_run else 'effectuées'} : {_c('green', str(done))}")
print(f" Déjà présents (skip) : {_c('cyan', str(skip))}")
print(f" Erreurs / avertissements : {_c('red', str(err)) if err else _c('green', '0')}")
if result.actions_done:
print(f" {'─'*50}")
for a in result.actions_done:
icon = {"create_org": "🏢", "create_app": "📱", "grant_api": "🔗"}.get(a.kind, "•")
prefix = " ~ " if dry_run else " + "
print(f" {prefix}{icon} {a.description}")
if result.errors:
print(f" {'─'*50}")
for e in result.errors:
print(f" ⚠️ {_c('red', e)}")
print()
print(_c("bold", f"{'─'*65}"))
print(
f" Total — {'simulé' if dry_run else 'effectué'}: {_c('green', str(total_done))} | "
f"skip: {_c('cyan', str(total_skip))} | "
f"erreurs: {_c('red', str(total_err)) if total_err else _c('green', '0')}"
)
print(_c("bold", f"{'─'*65}"))
if dry_run:
print(_c("yellow", "\n ️ Mode DRY-RUN : aucun changement appliqué."))
print(_c("yellow", " Relancez sans --dry-run pour appliquer les modifications.\n"))
else:
print()