Ajout d'un script de nettoyage
This commit is contained in:
parent
617b12c02e
commit
da6c15d6b0
59
scripts/clean_csv_exports.py
Normal file
59
scripts/clean_csv_exports.py
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Supprime les fichiers CSV générés automatiquement dans l'arborescence des docs."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def iter_csv_files(base: Path) -> list[Path]:
|
||||
if not base.exists():
|
||||
return []
|
||||
return [path for path in base.rglob("*.csv") if path.is_file()]
|
||||
|
||||
|
||||
def remove_files(files: list[Path], dry_run: bool) -> int:
|
||||
count = 0
|
||||
for path in files:
|
||||
if dry_run:
|
||||
print(f"[DRY-RUN] {path.relative_to(ROOT)}")
|
||||
continue
|
||||
path.unlink(missing_ok=True)
|
||||
print(f"Supprimé : {path.relative_to(ROOT)}")
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Supprime les fichiers CSV d'une arborescence.")
|
||||
parser.add_argument(
|
||||
"--root",
|
||||
type=Path,
|
||||
default=ROOT,
|
||||
help="Répertoire racine à nettoyer (par défaut : ./).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Affiche les fichiers qui seraient supprimés sans les effacer.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
root = args.root.resolve()
|
||||
csv_files = iter_csv_files(root)
|
||||
if not csv_files:
|
||||
print(f"Aucun fichier CSV trouvé sous {root}.")
|
||||
return
|
||||
|
||||
removed = remove_files(csv_files, dry_run=args.dry_run)
|
||||
if args.dry_run:
|
||||
print(f"{len(csv_files)} fichier(s) CSV seraient supprimés.")
|
||||
else:
|
||||
print(f"✔ {removed} fichier(s) CSV supprimés.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user