This commit is contained in:
@@ -1628,6 +1628,10 @@ def export(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if finder_tag_keywords or finder_tag_template:
|
if finder_tag_keywords or finder_tag_template:
|
||||||
|
if dry_run:
|
||||||
|
for filepath in photo_files:
|
||||||
|
verbose(f"Writing Finder tags to [filepath]{filepath}[/]")
|
||||||
|
else:
|
||||||
tags_written, tags_skipped = write_finder_tags(
|
tags_written, tags_skipped = write_finder_tags(
|
||||||
p,
|
p,
|
||||||
photo_files,
|
photo_files,
|
||||||
@@ -1647,6 +1651,12 @@ def export(
|
|||||||
results.xattr_skipped.extend(tags_skipped)
|
results.xattr_skipped.extend(tags_skipped)
|
||||||
|
|
||||||
if xattr_template:
|
if xattr_template:
|
||||||
|
if dry_run:
|
||||||
|
for filepath in photo_files:
|
||||||
|
verbose(
|
||||||
|
f"Writing extended attributes to [filepath]{filepath}[/]"
|
||||||
|
)
|
||||||
|
else:
|
||||||
xattr_written, xattr_skipped = write_extended_attributes(
|
xattr_written, xattr_skipped = write_extended_attributes(
|
||||||
p,
|
p,
|
||||||
photo_files,
|
photo_files,
|
||||||
@@ -2690,11 +2700,11 @@ def write_finder_tags(
|
|||||||
for f in files:
|
for f in files:
|
||||||
md = OSXMetaData(f)
|
md = OSXMetaData(f)
|
||||||
if sorted(md.tags) != sorted(tags):
|
if sorted(md.tags) != sorted(tags):
|
||||||
verbose(f"Writing Finder tags to {f}")
|
verbose(f"Writing Finder tags to [filepath]{f}[/]")
|
||||||
md.tags = tags
|
md.tags = tags
|
||||||
written.append(f)
|
written.append(f)
|
||||||
else:
|
else:
|
||||||
verbose(f"Skipping Finder tags for {f}: nothing to do")
|
verbose(f"Skipping Finder tags for [filepath]{f}[/]: nothing to do")
|
||||||
skipped.append(f)
|
skipped.append(f)
|
||||||
|
|
||||||
return (written, skipped)
|
return (written, skipped)
|
||||||
@@ -2766,10 +2776,14 @@ def write_extended_attributes(
|
|||||||
if (not file_value and not value) or file_value == value:
|
if (not file_value and not value) or file_value == value:
|
||||||
# if both not set or both equal, nothing to do
|
# if both not set or both equal, nothing to do
|
||||||
# get returns None if not set and value will be [] if not set so can't directly compare
|
# get returns None if not set and value will be [] if not set so can't directly compare
|
||||||
verbose(f"Skipping extended attribute {attr} for {f}: nothing to do")
|
verbose(
|
||||||
|
f"Skipping extended attribute [bold]{attr}[/] for [filepath]{f}[/]: nothing to do"
|
||||||
|
)
|
||||||
skipped.add(f)
|
skipped.add(f)
|
||||||
else:
|
else:
|
||||||
verbose(f"Writing extended attribute {attr} to {f}")
|
verbose(
|
||||||
|
f"Writing extended attribute [bold]{attr}[/] to [filepath]{f}[/]"
|
||||||
|
)
|
||||||
md.set(attr, value)
|
md.set(attr, value)
|
||||||
written.add(f)
|
written.add(f)
|
||||||
|
|
||||||
|
|||||||
@@ -6774,6 +6774,29 @@ def test_export_ramdb():
|
|||||||
assert "exported: 0" in result.output
|
assert "exported: 0" in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_finder_tag_keywords_dry_run():
|
||||||
|
"""test --finder-tag-keywords with --dry-run, #958"""
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
cwd = os.getcwd()
|
||||||
|
# pylint: disable=not-context-manager
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
for uuid in CLI_FINDER_TAGS:
|
||||||
|
result = runner.invoke(
|
||||||
|
export,
|
||||||
|
[
|
||||||
|
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||||
|
".",
|
||||||
|
"-V",
|
||||||
|
"--finder-tag-keywords",
|
||||||
|
"--uuid",
|
||||||
|
f"{uuid}",
|
||||||
|
"--dry-run",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
def test_export_finder_tag_keywords():
|
def test_export_finder_tag_keywords():
|
||||||
"""test --finder-tag-keywords"""
|
"""test --finder-tag-keywords"""
|
||||||
|
|
||||||
@@ -7019,6 +7042,41 @@ def test_export_finder_tag_template_multi_field():
|
|||||||
assert sorted(md.tags) == sorted(expected)
|
assert sorted(md.tags) == sorted(expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_xattr_template_dry_run():
|
||||||
|
"""test --xattr template with --dry-run, #958"""
|
||||||
|
|
||||||
|
# Note: this test does not actually test that the metadata attributes get correctly
|
||||||
|
# written by osxmetadata as osxmetadata doesn't work reliably when run by pytest
|
||||||
|
# (but does appear to work correctly in practice)
|
||||||
|
# Reference: https://github.com/RhetTbull/osxmetadata/issues/68
|
||||||
|
|
||||||
|
runner = CliRunner()
|
||||||
|
cwd = os.getcwd()
|
||||||
|
# pylint: disable=not-context-manager
|
||||||
|
with runner.isolated_filesystem():
|
||||||
|
test_dir = os.getcwd()
|
||||||
|
for uuid in CLI_FINDER_TAGS:
|
||||||
|
result = runner.invoke(
|
||||||
|
export,
|
||||||
|
[
|
||||||
|
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||||
|
".",
|
||||||
|
"-V",
|
||||||
|
"--xattr-template",
|
||||||
|
"copyright",
|
||||||
|
"osxphotos 2022",
|
||||||
|
"--xattr-template",
|
||||||
|
"comment",
|
||||||
|
"{title};{descr}",
|
||||||
|
"--uuid",
|
||||||
|
f"{uuid}",
|
||||||
|
"--dry-run",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "Writing extended attribute" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_export_xattr_template():
|
def test_export_xattr_template():
|
||||||
"""test --xattr template"""
|
"""test --xattr template"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user