go back to deducing work_id automatically in manual-collate

main
xenofem 2024-02-07 22:52:17 -05:00
parent ad71c6c280
commit bfee8affe1
1 changed files with 11 additions and 7 deletions

View File

@ -588,14 +588,19 @@ def normalize_to(path, ref):
def manual_collate(args):
(raw_groups, raw_exclusions) = parse_expressions(args.expression)
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
exclusions = [normalize_to(item, args.destdir) for item in raw_exclusions]
if raw_groups:
groups = [[normalize_to(item, args.destdir) for item in group] for group in raw_groups]
else:
groups = [[args.destdir / 'extract' / args.work_id]]
groups = [[extraction_dir / work_id]]
collation_dir = args.destdir / 'site' / 'images' / args.work_id
collation_dir = args.destdir / 'site' / 'images' / work_id
if collation_dir.exists():
if len(list(collation_dir.iterdir())) > 0:
print(f'Collation directory already exists!')
@ -609,7 +614,7 @@ def manual_collate(args):
return
collation_staging_area = args.destdir / 'site' / 'images-staging'
work_staging_dir = collation_staging_area / args.work_id
work_staging_dir = collation_staging_area / work_id
work_staging_dir.mkdir(parents=True)
pages_collated = 0
@ -621,14 +626,14 @@ def manual_collate(args):
exclusions,
)
if pages_added is None:
print(f'Unable to deduce file structure for {args.work_id} subgroup {[str(path) for path in group]}')
print(f'Unable to deduce file structure for {work_id} subgroup {[str(path) for path in group]}')
pages_collated = None
break
pages_collated += pages_added
if pages_collated:
print(f'Collated {pages_collated} pages for {args.work_id}')
print(f'Collated {pages_collated} pages for {work_id}')
work_staging_dir.rename(collation_dir)
else:
for f in work_staging_dir.iterdir():
@ -953,10 +958,9 @@ parser_manual_collate = subparsers.add_parser(
All provided paths must be under $DLIBRARY_DIR/extract/[work id]/
for the work being manually collated. `manual-collate` can
only handle one work at a time. Paths are used as follows:
only handle one work at a time.
"""),
)
parser_manual_collate.add_argument('work_id')
parser_manual_collate.add_argument(
'expression',
nargs='+',