From c042163e85dec7ecf4ce29d3e71fd417c795152b Mon Sep 17 00:00:00 2001 From: xenofem Date: Sat, 2 Mar 2024 18:10:22 -0500 Subject: [PATCH] properly handle edge case when we point collate or manual-collate directly at an extraction directory --- dlibrary/dlibrary.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index fcaf440..132e7b2 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -208,12 +208,15 @@ def fetch(args): asyncio.run(fetch_async(args)) +def self_and_parents(path): + return [path] + list(path.parents) + def collate(args): con = sqlite3.connect(args.destdir / 'meta.db') cur = con.cursor() extraction_dir = args.destdir / 'extract' - hint_map = {Path(relpath(hint, extraction_dir)).parents[-2].name: hint for hint in args.hints} + hint_map = {self_and_parents(Path(relpath(hint, extraction_dir)))[-2].name: hint for hint in args.hints} collation_staging_area = args.destdir / 'site' / 'images-staging' collation_staging_area.mkdir(parents=True) @@ -697,7 +700,7 @@ def manual_collate(args): extraction_dir = args.destdir / 'extract' sample_path = next(path for group in (raw_groups + [raw_exclusions]) for path in group) - work_id = Path(relpath(sample_path, extraction_dir)).parents[-2].name + work_id = self_and_parents(Path(relpath(sample_path, extraction_dir)))[-2].name exclusions = [normalize_to(item, args.destdir) for item in raw_exclusions]