File size: 1,300 Bytes
2e1a095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path

ROOT_DIR = Path(__file__).resolve().parent.parent
if str(ROOT_DIR) not in sys.path:
    sys.path.insert(0, str(ROOT_DIR))

from app import main


def main_cli() -> None:
    parser = argparse.ArgumentParser(description="Delete old generated audio files and abandoned temp folders.")
    parser.add_argument("--days", type=int, default=main.OUTPUT_RETENTION_DAYS, help="Delete files older than this many days.")
    parser.add_argument("--max-files", type=int, default=main.OUTPUT_MAX_FILES, help="Keep only the newest N audio files.")
    parser.add_argument("--output-dir", type=Path, default=main.OUTPUT_DIR, help="Directory containing generated audio files.")
    parser.add_argument("--json", action="store_true", help="Print JSON instead of a compact summary.")
    args = parser.parse_args()

    result = main.cleanup_output_storage(args.output_dir, args.days, args.max_files)
    if args.json:
        print(json.dumps(result, indent=2))
    else:
        mb = result["bytes"] / 1024 / 1024
        print(
            f"Deleted {result['files']} audio file(s), {result['directories']} temp folder(s), "
            f"freed {mb:.1f} MB."
        )


if __name__ == "__main__":
    main_cli()