60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.api.visual_watch import cleanup_visual_watch_captures
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
output_json = _get_bool(env, "VISUAL_CAPTURE_CLEANUP_OUTPUT_JSON", False)
|
|
payload = cleanup_visual_watch_captures(
|
|
retention_hours=_get_int(env, "VISUAL_CAPTURE_CLEANUP_RETENTION_HOURS", 168),
|
|
dry_run=_get_bool(env, "VISUAL_CAPTURE_CLEANUP_DRY_RUN", False),
|
|
output_dir=_get_optional_value(env, "VISUAL_CAPTURE_CLEANUP_OUTPUT_DIR"),
|
|
max_delete_files=_get_int(env, "VISUAL_CAPTURE_CLEANUP_MAX_DELETE_FILES", 500),
|
|
)
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
print(f"Visual capture cleanup status: {payload.get('status')}")
|
|
print(f"Root: {payload.get('root')}")
|
|
print(f"Retention hours: {payload.get('retention_hours')}")
|
|
print(f"Eligible files: {payload.get('eligible_file_count')}")
|
|
print(f"Deleted files: {payload.get('deleted_file_count')}")
|
|
if payload.get("reason"):
|
|
print(f"Reason: {payload.get('reason')}")
|
|
return 0 if payload.get("status") != "failed" else 2
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool = False) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
def _get_int(env, key: str, default: int) -> int:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return int(value)
|
|
|
|
|
|
def _get_optional_value(env, key: str):
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return None
|
|
return value
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|