From 6bc8332f471739aeb40075bd384e373b533fa9d1 Mon Sep 17 00:00:00 2001 From: xenofem Date: Sun, 11 Feb 2024 14:38:50 -0500 Subject: [PATCH] make sure to create site/images if it doesn't exist --- dlibrary/dlibrary.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index f6d4e7a..07a584b 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -373,11 +373,14 @@ def collate(args): collation_staging_area = args.destdir / 'site' / 'images-staging' collation_staging_area.mkdir(parents=True) + collation_area = args.destdir / 'site' / 'images' + collation_area.mkdir(parents=True, exist_ok=True) + for work_path in extraction_dir.iterdir(): work_id = work_path.name - collation_dir = args.destdir / 'site' / 'images' / work_id - if collation_dir.exists(): + work_collation_dir = collation_area / work_id + if work_collation_dir.exists(): continue virtual = cur.execute("SELECT virtual FROM works WHERE id = ?", (work_id,)).fetchone() @@ -389,7 +392,7 @@ def collate(args): pages_collated = collate_from_paths([hint_map.get(work_id, work_path)], work_staging_dir, 0, []) if pages_collated: print(f'Collated {pages_collated} pages for {work_id}') - work_staging_dir.rename(collation_dir) + work_staging_dir.rename(work_collation_dir) else: if work_staging_dir.is_dir(): for f in work_staging_dir.iterdir(): @@ -603,13 +606,16 @@ def manual_collate(args): else: groups = [[extraction_dir / work_id]] - collation_dir = args.destdir / 'site' / 'images' / work_id - if collation_dir.exists(): - if len(list(collation_dir.iterdir())) > 0: + collation_area = args.destdir / 'site' / 'images' + collation_area.mkdir(parents=True, exist_ok=True) + + work_collation_dir = collation_area / work_id + if work_collation_dir.exists(): + if len(list(work_collation_dir.iterdir())) > 0: print(f'Collation directory already exists!') return else: - collation_dir.rmdir() + work_collation_dir.rmdir() nonexistent = [path for group in (groups + [exclusions]) for path in group if not path.exists()] if len(nonexistent) > 0: @@ -637,7 +643,7 @@ def manual_collate(args): if pages_collated: print(f'Collated {pages_collated} pages for {work_id}') - work_staging_dir.rename(collation_dir) + work_staging_dir.rename(work_collation_dir) else: for f in work_staging_dir.iterdir(): f.unlink()