Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import stop on errors #1486

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions osxphotos/cli/import_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ def import_files(
split_folder: str,
post_function: tuple[Callable[..., None]],
skip_dups: bool,
stop_on_error: int,
dup_check: bool,
dry_run: bool,
report_data: dict[pathlib.Path, ReportRecord],
Expand Down Expand Up @@ -1133,6 +1134,13 @@ def import_files(
if error:
error_count += 1
report_record.error = True

# Stop after stop_on_error errors. "Unknown error" issue with Photos at import ~2000 assets.
if error_count >= stop_on_error:
verbose(
f"More than [stop_on_error]{stop_on_error}[/] import errors. Stopping! Last [filename]{filepath.name}[/] [error_count]{error_count}[/]"
)
break
continue
else:
photo = None
Expand Down Expand Up @@ -1919,6 +1927,13 @@ def get_help(self, ctx):
"You will only need to specify this if osxphotos cannot determine the path to the library "
"in which case osxphotos will tell you to use the --library option when you run the import command.",
)
@click.option(
"--stop-on-error",
metavar="ERRORCOUNT",
help="Stops importing after ERRORCOUNT errors. . "
"Useful when facing Photos 'Unknownd error' when importing more than ~2000 assets.",
type=click.IntRange(min=0)
)
@THEME_OPTION
@click.argument("files", nargs=-1)
@click.pass_obj
Expand Down Expand Up @@ -1955,6 +1970,7 @@ def import_main(
sidecar: bool,
sidecar_ignore_date: bool,
sidecar_filename_template: str | None,
stop_on_error: int | None,
skip_dups: bool,
split_folder: str | None,
theme: str | None,
Expand Down Expand Up @@ -2014,6 +2030,7 @@ def import_cli(
sidecar_filename_template: str | None = None,
skip_dups: bool = False,
split_folder: str | None = None,
stop_on_error: int | None = None,
theme: str | None = None,
timestamp: bool = False,
title: str | None = None,
Expand Down Expand Up @@ -2133,6 +2150,7 @@ def import_cli(
split_folder=split_folder,
post_function=post_function,
skip_dups=skip_dups,
stop_on_error=stop_on_error,
dup_check=dup_check,
dry_run=dry_run,
report_data=report_data,
Expand Down
Loading