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()