go back to deducing work_id automatically in manual-collate
This commit is contained in:
parent
ad71c6c280
commit
bfee8affe1
|
@ -588,14 +588,19 @@ def normalize_to(path, ref):
|
||||||
def manual_collate(args):
|
def manual_collate(args):
|
||||||
(raw_groups, raw_exclusions) = parse_expressions(args.expression)
|
(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]
|
exclusions = [normalize_to(item, args.destdir) for item in raw_exclusions]
|
||||||
|
|
||||||
if raw_groups:
|
if raw_groups:
|
||||||
groups = [[normalize_to(item, args.destdir) for item in group] for group in raw_groups]
|
groups = [[normalize_to(item, args.destdir) for item in group] for group in raw_groups]
|
||||||
else:
|
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 collation_dir.exists():
|
||||||
if len(list(collation_dir.iterdir())) > 0:
|
if len(list(collation_dir.iterdir())) > 0:
|
||||||
print(f'Collation directory already exists!')
|
print(f'Collation directory already exists!')
|
||||||
|
@ -609,7 +614,7 @@ def manual_collate(args):
|
||||||
return
|
return
|
||||||
|
|
||||||
collation_staging_area = args.destdir / 'site' / 'images-staging'
|
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)
|
work_staging_dir.mkdir(parents=True)
|
||||||
|
|
||||||
pages_collated = 0
|
pages_collated = 0
|
||||||
|
@ -621,14 +626,14 @@ def manual_collate(args):
|
||||||
exclusions,
|
exclusions,
|
||||||
)
|
)
|
||||||
if pages_added is None:
|
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
|
pages_collated = None
|
||||||
break
|
break
|
||||||
|
|
||||||
pages_collated += pages_added
|
pages_collated += pages_added
|
||||||
|
|
||||||
if pages_collated:
|
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)
|
work_staging_dir.rename(collation_dir)
|
||||||
else:
|
else:
|
||||||
for f in work_staging_dir.iterdir():
|
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]/
|
All provided paths must be under $DLIBRARY_DIR/extract/[work id]/
|
||||||
for the work being manually collated. `manual-collate` can
|
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(
|
parser_manual_collate.add_argument(
|
||||||
'expression',
|
'expression',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
|
|
Loading…
Reference in a new issue