Run a given ArchiveBox subcommand with the given list of args
(subcommand: str,
subcommand_args: List[str]=None,
stdin: Optional[IO]=None,
pwd: Union[Path, str, None]=None)
| 55 | |
| 56 | |
| 57 | def run_subcommand(subcommand: str, |
| 58 | subcommand_args: List[str]=None, |
| 59 | stdin: Optional[IO]=None, |
| 60 | pwd: Union[Path, str, None]=None) -> None: |
| 61 | """Run a given ArchiveBox subcommand with the given list of args""" |
| 62 | |
| 63 | subcommand_args = subcommand_args or [] |
| 64 | |
| 65 | if subcommand not in meta_cmds: |
| 66 | from ..config import setup_django |
| 67 | |
| 68 | cmd_requires_db = subcommand in archive_cmds |
| 69 | init_pending = '--init' in subcommand_args or '--quick-init' in subcommand_args |
| 70 | |
| 71 | if cmd_requires_db: |
| 72 | check_data_folder(pwd) |
| 73 | |
| 74 | setup_django(in_memory_db=subcommand in fake_db, check_db=cmd_requires_db and not init_pending) |
| 75 | |
| 76 | if cmd_requires_db: |
| 77 | check_migrations() |
| 78 | |
| 79 | module = import_module('.archivebox_{}'.format(subcommand), __package__) |
| 80 | module.main(args=subcommand_args, stdin=stdin, pwd=pwd) # type: ignore |
| 81 | |
| 82 | |
| 83 | SUBCOMMANDS = list_subcommands() |