parent
3ad4c7a4cc
commit
1d1b69601f
@ -38,7 +38,13 @@ from .param_types import Latitude, Longitude, TemplateString
|
|||||||
metavar="KEYWORD_TEMPLATE",
|
metavar="KEYWORD_TEMPLATE",
|
||||||
type=TemplateString(),
|
type=TemplateString(),
|
||||||
multiple=True,
|
multiple=True,
|
||||||
help="Set keywords of photo. May be specified multiple times.",
|
help="Add keywords to photo. May be specified multiple times.",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--replace-keywords",
|
||||||
|
is_flag=True,
|
||||||
|
help="When specified with --keyword, replace existing keywords. "
|
||||||
|
"Default is to add to existing keywords.",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--location",
|
"--location",
|
||||||
@ -59,6 +65,7 @@ def batch_edit(
|
|||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
keyword,
|
keyword,
|
||||||
|
replace_keywords,
|
||||||
location,
|
location,
|
||||||
dry_run,
|
dry_run,
|
||||||
undo,
|
undo,
|
||||||
@ -77,11 +84,11 @@ def batch_edit(
|
|||||||
--verbose \\
|
--verbose \\
|
||||||
--title "California vacation 2023 {created.year}-{created.dd}-{created.mm} {counter:03d}" \\
|
--title "California vacation 2023 {created.year}-{created.dd}-{created.mm} {counter:03d}" \\
|
||||||
--description "{place.name}" \\
|
--description "{place.name}" \\
|
||||||
--keyword "Family" --keyword "Travel" --keyword "{keyword}"
|
--keyword "Family" --keyword "Travel"
|
||||||
|
|
||||||
This will set the title to "California vacation 2023 2023-02-20 001", and so on,
|
This will set the title to "California vacation 2023 2023-02-20 001", and so on,
|
||||||
the description to the reverse geolocation place name,
|
the description to the reverse geolocation place name,
|
||||||
and the keywords to "Family", "Travel", and any existing keywords of the photo.
|
and add the keywords to "Family", "Travel".
|
||||||
|
|
||||||
--title, --description, and --keyword may be any valid template string.
|
--title, --description, and --keyword may be any valid template string.
|
||||||
See https://rhettbull.github.io/osxphotos/template_help.html
|
See https://rhettbull.github.io/osxphotos/template_help.html
|
||||||
@ -103,6 +110,13 @@ def batch_edit(
|
|||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if replace_keywords and not keyword:
|
||||||
|
echo_error(
|
||||||
|
"[error] Cannot specify --replace-keywords without --keyword. "
|
||||||
|
"Use --help for more information."
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not photos:
|
if not photos:
|
||||||
echo_error("[error] No photos selected")
|
echo_error("[error] No photos selected")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -124,7 +138,7 @@ def batch_edit(
|
|||||||
save_photo_undo_info(undo_store, photo)
|
save_photo_undo_info(undo_store, photo)
|
||||||
set_photo_title_from_template(photo, title, dry_run)
|
set_photo_title_from_template(photo, title, dry_run)
|
||||||
set_photo_description_from_template(photo, description, dry_run)
|
set_photo_description_from_template(photo, description, dry_run)
|
||||||
set_photo_keywords_from_template(photo, keyword, dry_run)
|
set_photo_keywords_from_template(photo, keyword, replace_keywords, dry_run)
|
||||||
set_photo_location(photo, location, dry_run)
|
set_photo_location(photo, location, dry_run)
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +259,10 @@ def set_photo_description_from_template(
|
|||||||
|
|
||||||
|
|
||||||
def set_photo_keywords_from_template(
|
def set_photo_keywords_from_template(
|
||||||
photo: osxphotos.PhotoInfo, keyword_template: list[str], dry_run: bool
|
photo: osxphotos.PhotoInfo,
|
||||||
|
keyword_template: list[str],
|
||||||
|
replace_keywords: bool,
|
||||||
|
dry_run: bool,
|
||||||
):
|
):
|
||||||
"""Set photo keywords from template"""
|
"""Set photo keywords from template"""
|
||||||
if not keyword_template:
|
if not keyword_template:
|
||||||
@ -267,6 +284,9 @@ def set_photo_keywords_from_template(
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not replace_keywords:
|
||||||
|
keywords.update(photo.keywords)
|
||||||
|
|
||||||
verbose(
|
verbose(
|
||||||
f"Setting [i]keywords[/] to {', '.join(f'[bold]{kw}[/]' for kw in keywords)}"
|
f"Setting [i]keywords[/] to {', '.join(f'[bold]{kw}[/]' for kw in keywords)}"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -131,6 +131,7 @@ def test_batch_edit_undo(photoslib):
|
|||||||
"Test",
|
"Test",
|
||||||
"--keyword",
|
"--keyword",
|
||||||
"test",
|
"test",
|
||||||
|
"--replace-keywords",
|
||||||
"--location",
|
"--location",
|
||||||
"34.052235",
|
"34.052235",
|
||||||
"-118.243683",
|
"-118.243683",
|
||||||
@ -164,3 +165,56 @@ def test_batch_edit_undo(photoslib):
|
|||||||
assert photo.description == "Pumpkin Farm"
|
assert photo.description == "Pumpkin Farm"
|
||||||
assert photo.keywords == ["kids"]
|
assert photo.keywords == ["kids"]
|
||||||
assert photo.location == (41.256566, -95.940257)
|
assert photo.location == (41.256566, -95.940257)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.test_batch_edit
|
||||||
|
def test_batch_edit_replace_keywords(photoslib):
|
||||||
|
"""Test batch-edit command with --replace-keywords"""
|
||||||
|
photo = photoslib.selection[0]
|
||||||
|
assert photo.uuid == TEST_DATA_BATCH_EDIT["uuid"]
|
||||||
|
photo.title = "Pumpkin Farm"
|
||||||
|
photo.description = "Pumpkin Farm"
|
||||||
|
photo.keywords = ["kids"]
|
||||||
|
|
||||||
|
with CliRunner().isolated_filesystem():
|
||||||
|
# First test that omitting --replace-keywords adds keywords
|
||||||
|
result = CliRunner().invoke(
|
||||||
|
batch_edit,
|
||||||
|
[
|
||||||
|
"--keyword",
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
photo = osxphotos.PhotosDB().get_photo(TEST_DATA_BATCH_EDIT["uuid"])
|
||||||
|
assert sorted(photo.keywords) == ["kids", "test"]
|
||||||
|
|
||||||
|
result = CliRunner().invoke(
|
||||||
|
batch_edit,
|
||||||
|
[
|
||||||
|
"--keyword",
|
||||||
|
"test2",
|
||||||
|
"--replace-keywords",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
photo = osxphotos.PhotosDB().get_photo(TEST_DATA_BATCH_EDIT["uuid"])
|
||||||
|
assert photo.keywords == ["test2"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.test_batch_edit
|
||||||
|
def test_batch_edit_replace_keywords_error(photoslib):
|
||||||
|
"""Test batch-edit command with --replace-keywords when no keywords specified"""
|
||||||
|
photo = photoslib.selection[0]
|
||||||
|
assert photo.uuid == TEST_DATA_BATCH_EDIT["uuid"]
|
||||||
|
|
||||||
|
with CliRunner().isolated_filesystem():
|
||||||
|
result = CliRunner().invoke(
|
||||||
|
batch_edit,
|
||||||
|
[
|
||||||
|
"--title",
|
||||||
|
"test",
|
||||||
|
"--replace-keywords",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code != 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user