Skip to content

Commit

Permalink
Initial refactor of --check-not
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Apr 7, 2024
1 parent b9953fc commit e8161ee
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions osxphotos/cli/import_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,13 +2182,11 @@ def import_cli(
)

if check:
# ZZZ need to be updated to skip AAE, live, raw
check_imported_files(files_to_import, last_library, verbose)
sys.exit(0)

if check_not:
# ZZZ need to be updated to skip AAE, live, raw
check_not_imported_files(files, last_library, verbose)
check_not_imported_files(files_to_import, last_library, verbose)
sys.exit(0)

if exiftool and not exiftool_path:
Expand Down Expand Up @@ -2268,7 +2266,6 @@ def import_cli(
verbose(f"Wrote import report to [filepath]{report_file}[/]")

skipped_str = f", [num]{skipped_count}[/] skipped" if resume or skip_dups else ""
# ZZZ add group count to imported
echo(
f"Done: imported [num]{imported_count}[/] {pluralize(imported_count, 'file group', 'file groups')}, "
f"[num]{error_count}[/] {pluralize(error_count, 'error', 'errors')}"
Expand All @@ -2277,6 +2274,32 @@ def import_cli(
)


def collect_filepaths_for_import_check(
filegroup: tuple[pathlib.Path, ...]
) -> list[pathlib.Path]:
"""Collect filepaths for import check"""
filepaths = []
# exclude .AAE files
filegroup = [f for f in filegroup if not f.name.lower().endswith(".aae")]
if len(filegroup) == 1:
filepaths.append(filegroup[0])
elif burst_uuid_from_path(filegroup[0]):
# include all burst images
filepaths.extend(filegroup)
elif len(filegroup) == 2:
if is_live_pair(*filegroup):
# only include the image file for live photos
filepaths.append(filegroup[0])
elif is_raw_pair(*filegroup):
# Photos always makes the non-RAW image the original upon import
# only include the non-RAW image
filepaths.append(non_raw_file(filegroup))
else:
# include everything else
filepaths.extend(filegroup)
return filepaths


def check_imported_files(
files: list[tuple[pathlib.Path, ...]], library: str, verbose: Callable[..., None]
):
Expand All @@ -2294,21 +2317,7 @@ def check_imported_files(
)
fq = FingerprintQuery(library)
for filegroup in files:
filepaths = []
# strip .AAE files
filegroup = [f for f in filegroup if not f.name.lower().endswith(".aae")]
if len(filegroup) == 1:
filepaths.append(filegroup[0])
elif burst_uuid_from_path(filegroup[0]):
filepaths.extend(filegroup)
elif len(filegroup) == 2:
if is_live_pair(*filegroup):
filepaths.append(filegroup[0])
elif is_raw_pair(*filegroup):
# Photos always makes the non-RAW image the original upon import
filepaths.append(non_raw_file(filegroup))
else:
filepaths.extend(filegroup)
filepaths = collect_filepaths_for_import_check(filegroup)
for filepath in filepaths:
if duplicates := fq.possible_duplicates(filepath):
echo(
Expand All @@ -2320,21 +2329,28 @@ def check_imported_files(


def check_not_imported_files(
files: list[str], library: str, verbose: Callable[..., None]
files: list[tuple[pathlib.Path, ...]], library: str, verbose: Callable[..., None]
):
"""Check if files have not been previously imported and print results"""

if not files:
rich_echo_error("No files to check")
return

file_word = pluralize(len(files), "file", "files")
verbose(f"Checking {len(files)} {file_word} to see if not previously imported")
filecount = len(list(itertools.chain.from_iterable(files)))
file_word = pluralize(filecount, "file", "files")
group_word = pluralize(files, "group", "groups")
verbose(
f"Checking {filecount} {file_word} in {len(files)} {group_word} to see if not previously imported"
)
fq = FingerprintQuery(library)
for filepath in files:
if fq.possible_duplicates(filepath):
continue
echo(f"{filepath}")
for filegroup in files:
filepaths = collect_filepaths_for_import_check(filegroup)
for filepath in filepaths:
if fq.possible_duplicates(filepath):
continue
# ZZZ need to show the group
echo(f"{filepath}")


def content_tree(filepath: str | os.PathLike) -> list[str]:
Expand Down

0 comments on commit e8161ee

Please sign in to comment.