make sure to create site/images if it doesn't exist

This commit is contained in:
xenofem 2024-02-11 14:38:50 -05:00
parent 437cbcd73f
commit 6bc8332f47

View file

@ -373,11 +373,14 @@ def collate(args):
collation_staging_area = args.destdir / 'site' / 'images-staging' collation_staging_area = args.destdir / 'site' / 'images-staging'
collation_staging_area.mkdir(parents=True) 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(): for work_path in extraction_dir.iterdir():
work_id = work_path.name work_id = work_path.name
collation_dir = args.destdir / 'site' / 'images' / work_id work_collation_dir = collation_area / work_id
if collation_dir.exists(): if work_collation_dir.exists():
continue continue
virtual = cur.execute("SELECT virtual FROM works WHERE id = ?", (work_id,)).fetchone() 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, []) pages_collated = collate_from_paths([hint_map.get(work_id, work_path)], work_staging_dir, 0, [])
if pages_collated: if pages_collated:
print(f'Collated {pages_collated} pages for {work_id}') print(f'Collated {pages_collated} pages for {work_id}')
work_staging_dir.rename(collation_dir) work_staging_dir.rename(work_collation_dir)
else: else:
if work_staging_dir.is_dir(): if work_staging_dir.is_dir():
for f in work_staging_dir.iterdir(): for f in work_staging_dir.iterdir():
@ -603,13 +606,16 @@ def manual_collate(args):
else: else:
groups = [[extraction_dir / work_id]] groups = [[extraction_dir / work_id]]
collation_dir = args.destdir / 'site' / 'images' / work_id collation_area = args.destdir / 'site' / 'images'
if collation_dir.exists(): collation_area.mkdir(parents=True, exist_ok=True)
if len(list(collation_dir.iterdir())) > 0:
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!') print(f'Collation directory already exists!')
return return
else: else:
collation_dir.rmdir() work_collation_dir.rmdir()
nonexistent = [path for group in (groups + [exclusions]) for path in group if not path.exists()] nonexistent = [path for group in (groups + [exclusions]) for path in group if not path.exists()]
if len(nonexistent) > 0: if len(nonexistent) > 0:
@ -637,7 +643,7 @@ def manual_collate(args):
if pages_collated: if pages_collated:
print(f'Collated {pages_collated} pages for {work_id}') print(f'Collated {pages_collated} pages for {work_id}')
work_staging_dir.rename(collation_dir) work_staging_dir.rename(work_collation_dir)
else: else:
for f in work_staging_dir.iterdir(): for f in work_staging_dir.iterdir():
f.unlink() f.unlink()