mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-26 22:20:21 +00:00
split migrations and data dir check
This commit is contained in:
parent
e96141cee9
commit
0e39a2098d
2 changed files with 15 additions and 13 deletions
|
@ -8,7 +8,7 @@ import argparse
|
||||||
from typing import Optional, Dict, List, IO, Union
|
from typing import Optional, Dict, List, IO, Union
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ..config import OUTPUT_DIR
|
from ..config import OUTPUT_DIR, check_data_folder, check_migrations
|
||||||
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
|
@ -67,8 +67,14 @@ def run_subcommand(subcommand: str,
|
||||||
cmd_requires_db = subcommand in archive_cmds
|
cmd_requires_db = subcommand in archive_cmds
|
||||||
init_pending = '--init' in subcommand_args or '--quick-init' in subcommand_args
|
init_pending = '--init' in subcommand_args or '--quick-init' in subcommand_args
|
||||||
|
|
||||||
|
if cmd_requires_db:
|
||||||
|
check_data_folder(pwd)
|
||||||
|
|
||||||
setup_django(in_memory_db=subcommand in fake_db, check_db=cmd_requires_db and not init_pending)
|
setup_django(in_memory_db=subcommand in fake_db, check_db=cmd_requires_db and not init_pending)
|
||||||
|
|
||||||
|
if cmd_requires_db:
|
||||||
|
check_migrations()
|
||||||
|
|
||||||
module = import_module('.archivebox_{}'.format(subcommand), __package__)
|
module = import_module('.archivebox_{}'.format(subcommand), __package__)
|
||||||
module.main(args=subcommand_args, stdin=stdin, pwd=pwd) # type: ignore
|
module.main(args=subcommand_args, stdin=stdin, pwd=pwd) # type: ignore
|
||||||
|
|
||||||
|
|
|
@ -1020,8 +1020,8 @@ def check_data_folder(out_dir: Union[str, Path, None]=None, config: ConfigDict=C
|
||||||
output_dir = out_dir or config['OUTPUT_DIR']
|
output_dir = out_dir or config['OUTPUT_DIR']
|
||||||
assert isinstance(output_dir, (str, Path))
|
assert isinstance(output_dir, (str, Path))
|
||||||
|
|
||||||
sql_index_exists = (Path(output_dir) / SQL_INDEX_FILENAME).exists()
|
archive_dir_exists = (Path(output_dir) / ARCHIVE_DIR_NAME).exists()
|
||||||
if not sql_index_exists:
|
if not archive_dir_exists:
|
||||||
stderr('[X] No archivebox index found in the current directory.', color='red')
|
stderr('[X] No archivebox index found in the current directory.', color='red')
|
||||||
stderr(f' {output_dir}', color='lightyellow')
|
stderr(f' {output_dir}', color='lightyellow')
|
||||||
stderr()
|
stderr()
|
||||||
|
@ -1033,26 +1033,22 @@ def check_data_folder(out_dir: Union[str, Path, None]=None, config: ConfigDict=C
|
||||||
stderr(' archivebox init')
|
stderr(' archivebox init')
|
||||||
raise SystemExit(2)
|
raise SystemExit(2)
|
||||||
|
|
||||||
|
def check_migrations(out_dir: Union[str, Path, None]=None, config: ConfigDict=CONFIG):
|
||||||
|
output_dir = out_dir or config['OUTPUT_DIR']
|
||||||
from .index.sql import list_migrations
|
from .index.sql import list_migrations
|
||||||
|
|
||||||
pending_migrations = [name for status, name in list_migrations() if not status]
|
pending_migrations = [name for status, name in list_migrations() if not status]
|
||||||
|
|
||||||
if (not sql_index_exists) or pending_migrations:
|
if pending_migrations:
|
||||||
if sql_index_exists:
|
|
||||||
pending_operation = f'apply the {len(pending_migrations)} pending migrations'
|
|
||||||
else:
|
|
||||||
pending_operation = 'generate the new SQL main index'
|
|
||||||
|
|
||||||
stderr('[X] This collection was created with an older version of ArchiveBox and must be upgraded first.', color='lightyellow')
|
stderr('[X] This collection was created with an older version of ArchiveBox and must be upgraded first.', color='lightyellow')
|
||||||
stderr(f' {output_dir}')
|
stderr(f' {output_dir}')
|
||||||
stderr()
|
stderr()
|
||||||
stderr(f' To upgrade it to the latest version and {pending_operation} run:')
|
stderr(f' To upgrade it to the latest version and apply the {len(pending_migrations)} pending migrations, run:')
|
||||||
stderr(' archivebox init')
|
stderr(' archivebox init')
|
||||||
raise SystemExit(3)
|
raise SystemExit(3)
|
||||||
|
|
||||||
sources_dir = Path(output_dir) / SOURCES_DIR_NAME
|
(Path(output_dir) / SOURCES_DIR_NAME).mkdir(exist_ok=True)
|
||||||
if not sources_dir.exists():
|
(Path(output_dir) / LOGS_DIR_NAME).mkdir(exist_ok=True)
|
||||||
sources_dir.mkdir()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue