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

main
xenofem 2024-03-16 02:44:21 -04:00
parent 435af20e59
commit 2fbf3ec0eb
1 changed files with 26 additions and 0 deletions

View File

@ -118,6 +118,8 @@ def open_rarfile_with_encoding(path):
def extract(args):
absolute_archive_paths = set(path.resolve(strict=True) for path in args.archives)
any_skipped = False
for archive_path in args.archives:
if archive_path.suffix.lower() == '.zip':
work_id = archive_path.stem
@ -142,6 +144,7 @@ def extract(args):
volumes = [Path(vol).resolve(strict=True) for vol in r.volumelist()]
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')
any_skipped = True
continue
work_extract_path.mkdir(parents=True)
r.extractall(path=work_extract_path)
@ -154,6 +157,11 @@ def extract(args):
pass
else:
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):
@ -255,6 +263,9 @@ def url_file_ext(url):
def fetch(args):
asyncio.run(fetch_async(args))
if args.auto:
parser_collate.parse_args(args=[], namespace=args)
collate(args)
def self_and_parents(path):
@ -317,6 +328,8 @@ def collate(args):
con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor()
any_warnings = False
for work_path in extraction_dir.iterdir():
work_id = work_path.name
@ -329,6 +342,7 @@ def collate(args):
continue
if len(list(work_collation_dir.iterdir())) > 0:
print(f'Collation directory for work {work_id} already exists!')
any_warnings = True
break
else:
work_collation_dir.rmdir()
@ -337,6 +351,7 @@ def collate(args):
if virtual == (1,):
if work_id in specified_works:
print(f'Work {work_id} is virtual!')
any_warnings = True
break
continue
@ -363,9 +378,15 @@ def collate(args):
elif collator.index == 0:
print(f'No files found for {work_id}, skipping')
any_warnings = True
collation_staging_area.rmdir()
con.close()
if args.auto and not any_warnings:
parser_generate.parse_args(args=[], namespace=args)
generate(args)
class Collator:
def __init__(self, dest, exclude, args):
self.dest = dest
@ -1172,6 +1193,11 @@ argparser.add_argument(
'May still fall back to Japanese if other languages are unavailable. '
'(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)
parser_extract = subparsers.add_parser('extract', aliases=['x'], help='extract archive files')