add --auto flag to automatically run following stages if successful

This commit is contained in:
xenofem 2024-03-16 02:44:21 -04:00
parent 435af20e59
commit 2fbf3ec0eb

View file

@ -118,6 +118,8 @@ def open_rarfile_with_encoding(path):
def extract(args): def extract(args):
absolute_archive_paths = set(path.resolve(strict=True) for path in args.archives) absolute_archive_paths = set(path.resolve(strict=True) for path in args.archives)
any_skipped = False
for archive_path in args.archives: for archive_path in args.archives:
if archive_path.suffix.lower() == '.zip': if archive_path.suffix.lower() == '.zip':
work_id = archive_path.stem work_id = archive_path.stem
@ -142,6 +144,7 @@ def extract(args):
volumes = [Path(vol).resolve(strict=True) for vol in r.volumelist()] volumes = [Path(vol).resolve(strict=True) for vol in r.volumelist()]
if any(vol not in absolute_archive_paths for vol in volumes): if any(vol not in absolute_archive_paths for vol in volumes):
print(f'Multipart RAR archive starting with {archive_path} contains volume files not listed on command-line, skipping') print(f'Multipart RAR archive starting with {archive_path} contains volume files not listed on command-line, skipping')
any_skipped = True
continue continue
work_extract_path.mkdir(parents=True) work_extract_path.mkdir(parents=True)
r.extractall(path=work_extract_path) r.extractall(path=work_extract_path)
@ -154,6 +157,11 @@ def extract(args):
pass pass
else: else:
print(f'Unknown archive file type {archive_path}, skipping') print(f'Unknown archive file type {archive_path}, skipping')
any_skipped = True
if args.auto and not any_skipped:
parser_fetch.parse_args(args=[], namespace=args)
fetch(args)
def manual_input_metadata(work_id): def manual_input_metadata(work_id):
@ -255,6 +263,9 @@ def url_file_ext(url):
def fetch(args): def fetch(args):
asyncio.run(fetch_async(args)) asyncio.run(fetch_async(args))
if args.auto:
parser_collate.parse_args(args=[], namespace=args)
collate(args)
def self_and_parents(path): def self_and_parents(path):
@ -317,6 +328,8 @@ def collate(args):
con = sqlite3.connect(args.destdir / 'meta.db') con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor() cur = con.cursor()
any_warnings = False
for work_path in extraction_dir.iterdir(): for work_path in extraction_dir.iterdir():
work_id = work_path.name work_id = work_path.name
@ -329,6 +342,7 @@ def collate(args):
continue continue
if len(list(work_collation_dir.iterdir())) > 0: if len(list(work_collation_dir.iterdir())) > 0:
print(f'Collation directory for work {work_id} already exists!') print(f'Collation directory for work {work_id} already exists!')
any_warnings = True
break break
else: else:
work_collation_dir.rmdir() work_collation_dir.rmdir()
@ -337,6 +351,7 @@ def collate(args):
if virtual == (1,): if virtual == (1,):
if work_id in specified_works: if work_id in specified_works:
print(f'Work {work_id} is virtual!') print(f'Work {work_id} is virtual!')
any_warnings = True
break break
continue continue
@ -363,9 +378,15 @@ def collate(args):
elif collator.index == 0: elif collator.index == 0:
print(f'No files found for {work_id}, skipping') print(f'No files found for {work_id}, skipping')
any_warnings = True
collation_staging_area.rmdir() collation_staging_area.rmdir()
con.close() con.close()
if args.auto and not any_warnings:
parser_generate.parse_args(args=[], namespace=args)
generate(args)
class Collator: class Collator:
def __init__(self, dest, exclude, args): def __init__(self, dest, exclude, args):
self.dest = dest self.dest = dest
@ -1172,6 +1193,11 @@ argparser.add_argument(
'May still fall back to Japanese if other languages are unavailable. ' 'May still fall back to Japanese if other languages are unavailable. '
'(default: $DLIBRARY_LOCALE or en_US)'), '(default: $DLIBRARY_LOCALE or en_US)'),
) )
argparser.add_argument(
'-a', '--auto',
action='store_true',
help='automatically continue the extract->fetch->collate->generate pipeline starting from whatever subcommand is being run',
)
subparsers = argparser.add_subparsers(title="subcommands", required=True) subparsers = argparser.add_subparsers(title="subcommands", required=True)
parser_extract = subparsers.add_parser('extract', aliases=['x'], help='extract archive files') parser_extract = subparsers.add_parser('extract', aliases=['x'], help='extract archive files')