Skip to content

Commit

Permalink
Fixing duplicate thumbnail warning
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpage authored and pagerk committed Sep 2, 2024
1 parent 218d827 commit deca12f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 4 additions & 8 deletions genweb/genweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,14 @@ def copy_person_thumbnails(
continue

dest_file = destination_file(join(dst_dir, person.id), f"{person.id}.jpg")
found = artifacts.paths(f"{person.id}.jpg")
source_file = join(person.id, f"{person.id}.jpg")

if not found:
if not artifacts.has_file(source_file):
link(join(dst_dir, default_thumbnail), dest_file)
continue

if len(found) != 1:
PRINT(f"WARNING: duplicate thumbnails for {person.id}")
PRINT("\t" + "\n\t".join(found))

link(join(artifacts.directory, found[0]), dest_file)
artifacts.add(found[0])
link(join(artifacts.directory, source_file), dest_file)
artifacts.add(source_file)


def copy_metadata_files(
Expand Down
15 changes: 9 additions & 6 deletions tests/test_genweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def test_copy_metadata_files() -> None:
with TemporaryDirectory() as src_dir, TemporaryDirectory() as dst_dir:
copytree(join(dirname(__file__), "data"), join(src_dir, "data"))
makedirs(join(dst_dir, "foo"))
makedirs(join(src_dir, "1"))
copy(
join(dirname(__file__), "data", "fake.jpg"),
join(src_dir, "1", "1.jpg"),
)
copy(
join(dirname(__file__), "data", "test.xml"),
join(dst_dir, "foo", "test.xml"),
Expand All @@ -109,17 +114,15 @@ def test_copy_metadata_files() -> None:
copy_metadata_files(artifacts, dst_dir, metadata, people, default_thumbnail)
assert isfile(join(dst_dir, "foo", "test.xml"))

with open(join(dst_dir, "1", "1.jpg"), "r", encoding="utf-8") as file_1:
with open(join(dst_dir, "fake", "fake.jpg"), "r", encoding="utf-8") as file_1:
fake2_contents = file_1.read()

assert fake2_contents.startswith("default")
assert fake2_contents.startswith("default"), fake2_contents

with open(
join(dst_dir, "fake", "fake.jpg"), "r", encoding="utf-8"
) as file_fake:
with open(join(dst_dir, "1", "1.jpg"), "r", encoding="utf-8") as file_fake:
fake_contents = file_fake.read()

assert fake_contents.startswith("not really an image")
assert fake_contents.startswith("not really an image"), fake_contents


if __name__ == "__main__":
Expand Down

0 comments on commit deca12f

Please sign in to comment.