Coverage for src/photo_cleanup_utils.py: 100%
16 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-16 04:41 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-16 04:41 +0000
1"""Photo file cleanup utilities module.
3This module contains utilities for cleaning up obsolete photo files
4that are no longer on the server.
5"""
7___author___ = "Mandar Patil <mandarons@pm.me>"
9from pathlib import Path
11from src import get_logger
13LOGGER = get_logger()
16def remove_obsolete_files(destination_path: str | None, tracked_files: set[str] | None) -> set[str]:
17 """Remove local obsolete files that are no longer on server.
19 Args:
20 destination_path: Path to search for obsolete files
21 tracked_files: Set of files that should be kept (files on server)
23 Returns:
24 Set of paths that were removed
25 """
26 removed_paths = set()
28 if not (destination_path and tracked_files is not None):
29 return removed_paths
31 for path in Path(destination_path).rglob("*"):
32 local_file = str(path.absolute())
33 if local_file not in tracked_files:
34 if path.is_file():
35 LOGGER.info(f"Removing {local_file} ...")
36 path.unlink(missing_ok=True)
37 removed_paths.add(local_file)
39 return removed_paths