2024-09-25 02:04:38 +00:00
|
|
|
__package__ = 'archivebox.misc'
|
|
|
|
|
|
|
|
from benedict import benedict
|
|
|
|
|
2024-09-30 22:59:05 +00:00
|
|
|
from archivebox.config import DATA_DIR, ARCHIVE_DIR, CONSTANTS, SHELL_CONFIG
|
2024-09-25 12:10:09 +00:00
|
|
|
|
2024-09-30 22:59:05 +00:00
|
|
|
from .logging import stderr
|
2024-09-25 02:04:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_data_folder(config: benedict) -> None:
|
|
|
|
|
2024-09-30 22:59:05 +00:00
|
|
|
archive_dir_exists = ARCHIVE_DIR.exists()
|
2024-09-25 02:04:38 +00:00
|
|
|
if not archive_dir_exists:
|
|
|
|
stderr('[X] No archivebox index found in the current directory.', color='red')
|
2024-09-30 22:59:05 +00:00
|
|
|
stderr(f' {DATA_DIR}', color='lightyellow')
|
2024-09-25 02:04:38 +00:00
|
|
|
stderr()
|
2024-09-30 22:59:05 +00:00
|
|
|
stderr(' {lightred}Hint{reset}: Are you running archivebox in the right folder?'.format(**SHELL_CONFIG.ANSI))
|
2024-09-25 02:04:38 +00:00
|
|
|
stderr(' cd path/to/your/archive/folder')
|
|
|
|
stderr(' archivebox [command]')
|
|
|
|
stderr()
|
2024-09-30 22:59:05 +00:00
|
|
|
stderr(' {lightred}Hint{reset}: To create a new archive collection or import existing data in this folder, run:'.format(**SHELL_CONFIG.ANSI))
|
2024-09-25 02:04:38 +00:00
|
|
|
stderr(' archivebox init')
|
|
|
|
raise SystemExit(2)
|
|
|
|
|
|
|
|
|
|
|
|
def check_migrations(config: benedict):
|
|
|
|
from ..index.sql import list_migrations
|
|
|
|
|
|
|
|
pending_migrations = [name for status, name in list_migrations() if not status]
|
|
|
|
|
|
|
|
if pending_migrations:
|
|
|
|
stderr('[X] This collection was created with an older version of ArchiveBox and must be upgraded first.', color='lightyellow')
|
2024-09-30 22:59:05 +00:00
|
|
|
stderr(f' {DATA_DIR}')
|
2024-09-25 02:04:38 +00:00
|
|
|
stderr()
|
|
|
|
stderr(f' To upgrade it to the latest version and apply the {len(pending_migrations)} pending migrations, run:')
|
|
|
|
stderr(' archivebox init')
|
|
|
|
raise SystemExit(3)
|
|
|
|
|
2024-09-30 22:59:05 +00:00
|
|
|
CONSTANTS.SOURCES_DIR.mkdir(exist_ok=True)
|
|
|
|
CONSTANTS.LOGS_DIR.mkdir(exist_ok=True)
|
|
|
|
CONSTANTS.CACHE_DIR.mkdir(exist_ok=True)
|
|
|
|
(CONSTANTS.LIB_DIR / 'bin').mkdir(exist_ok=True, parents=True)
|
|
|
|
(CONSTANTS.PERSONAS_DIR / 'Default').mkdir(exist_ok=True, parents=True)
|