Add statistics and data-consistency menus, recently-added folder

This commit is contained in:
2026-07-02 06:10:14 +02:00
parent b5c2023212
commit f0f38d4257
17 changed files with 498 additions and 78 deletions
+43
View File
@@ -143,6 +143,32 @@ class TestHardlinkManager:
# The mirror (reserved folder) is left alone
assert mirror_link.exists()
def test_sync_removes_orphan_link_from_replaced_movie(
self, temp_source_dir, temp_output_dir, tag_manager
):
"""A stale link pointing at a no-longer-pooled inode is cleaned up."""
f = File(temp_source_dir / "file1.txt", tag_manager)
f.tags.clear()
f.add_tag(Tag("žánr", "Drama")) # a root-level category enables the sweep
f.add_tag(Tag("rok", "1968"))
roots = {"žánr": "", "rok": "- Dle roku"}
manager = HardlinkManager(temp_output_dir)
manager.sync_structure([f], category_roots=roots)
# Simulate a leftover from an OLD layout: a different file (different
# inode, not in the pool) hardlinked under an old unprefixed folder.
orphan_src = temp_source_dir / "orphan.txt"
orphan_src.write_text("old data")
old_dir = temp_output_dir / "Dle roku" / "1968"
old_dir.mkdir(parents=True)
os.link(orphan_src, old_dir / "file1.txt")
manager.sync_structure([f], category_roots=roots)
# new prefixed folder kept, stale unprefixed one (orphan) removed
assert (temp_output_dir / "- Dle roku" / "1968" / "file1.txt").exists()
assert not (temp_output_dir / "Dle roku").exists()
def test_sync_removes_root_genre_folder_when_last_movie_drops_tag(
self, temp_source_dir, temp_output_dir, tag_manager
):
@@ -255,6 +281,23 @@ class TestHardlinkManager:
tips = temp_output_dir / "Tipy dne"
assert len(list(tips.iterdir())) == 1 # not accumulated to 2
def test_generate_recently_added_orders_by_added(
self, files_with_tags, temp_output_dir
):
"""The newest-added movies (by added_timestamp) fill the folder."""
# explicit added timestamps: file2 newest, file1 middle, file3 oldest
files_with_tags[0].added = "2026-01-02T00:00:00"
files_with_tags[1].added = "2026-01-03T00:00:00"
files_with_tags[2].added = "2026-01-01T00:00:00"
manager = HardlinkManager(temp_output_dir)
created, fail = manager.generate_recently_added(
files_with_tags, count=2, subfolder="- Nově přidané")
recent = temp_output_dir / "- Nově přidané"
assert created == 2 and fail == 0
names = {p.name for p in recent.iterdir()}
assert names == {"file2.txt", "file1.txt"} # newest two, file3 excluded
def test_dry_run(self, files_with_tags, temp_output_dir):
"""Test dry run (bez skutečného vytváření)"""
manager = HardlinkManager(temp_output_dir)