def test_when_multi_processed_to_delete_with_xmp_then_correct_deletion( self, indexes_mock: Mock) -> None: indexes_mock.side_effect = ( [("00001", "/mydir/IMG_00001.cr3")], [("00001", "/mydir/IMG_00001.xmp")], [("00002", "/mydir/IMG_00002.cr3")], [("00002", "/mydir/IMG_00002.xmp")], [("00003", "/mydir/IMG_00003.cr3")], [("00003", "/mydir/IMG_00003.xmp")], [("00004", "/mydir/IMG_00004.xmp")], [("00004", "/mydir/IMG_00004.cr3")], [("00005", "/mydir/IMG_00005.cr3")], [("00005", "/mydir/IMG_00005.xmp")], [("00001", "/mydir/00Processed/IMG_00001-00003.jpg"), ("00002", "/mydir/00Processed/IMG_00001-00003.jpg"), ("00003", "/mydir/00Processed/IMG_00001-00003.jpg")], ) to_remove: List[str] = purge( RAW_EXTS, cast("Callable[[str], List[Tuple[str, str]]]", indexes_mock), [ "/mydir/IMG_00001.cr3", "/mydir/IMG_00001.xmp", "/mydir/IMG_00002.cr3", "/mydir/IMG_00002.xmp", "/mydir/IMG_00003.cr3", "/mydir/IMG_00003.xmp", "/mydir/IMG_00004.cr3", "/mydir/IMG_00004.xmp", "/mydir/IMG_00005.cr3", "/mydir/IMG_00005.xmp", "/mydir/00Processed/IMG_00001-00003.jpg" ]) assert to_remove == [ "/mydir/IMG_00004.cr3", "/mydir/IMG_00004.xmp", "/mydir/IMG_00005.cr3", "/mydir/IMG_00005.xmp" ]
def test_when_purge_folder_with_one_to_delete_then_deleted( self, indexes_mock: Mock) -> None: indexes_mock.side_effect = ([("00001", "/mydir/IMG_00001.cr3")], [ ("00002", "/mydir/IMG_00002.cr3") ], [("00001", "/mydir/00Processed/IMG_00001.jpg")]) to_remove: List[str] = purge( RAW_EXTS, cast("Callable[[str], List[Tuple[str, str]]]", indexes_mock), [ "/mydir/IMG_00001.cr3", "/mydir/IMG_00002.cr3", "/mydir/00Processed/IMG_00001.jpg" ]) assert to_remove == ["/mydir/IMG_00002.cr3"]
def main(input_path: str, do_delete: bool, raw_exts: Tuple[str], processed_exts: Tuple[str]) -> None: """Trawls the given directory for raw and processed images. Where it finds a raw image with a numeric index that can't be found in the processed images it is marked for removal. Any sequence of 3 to 6 (inc) numbers in the image filename is deemed as its index which is used to associate processed and raw images. Processed images may also have a filename format with a range of indexes, e.g. IMG_01234-1236.jpg This processed file would be associated with IMG_01234.cr3, IMG_01235.cr3 and IMG_01236.cr3 raw images thus ensuring they are not deleted. This is useful for HDR or panoramic processed images. """ pipe(input_path, directory_walker(list(raw_exts + processed_exts)), purge(list(raw_exts), indexer), deleter if do_delete else fake_deleter)
def test_when_purge_empty_folder_nothing_done( self, indexes_mock: Callable[[str], List[Tuple[str, str]]]) -> None: to_remove: List[str] = purge(RAW_EXTS, indexes_mock, []) assert to_remove == []