mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-25 12:14:32 -04:00
better data folder checking on startup
This commit is contained in:
parent
22bea7a4f6
commit
21174da014
3 changed files with 10 additions and 57 deletions
archivebox/cli
|
@ -9,59 +9,7 @@ import sys
|
|||
import argparse
|
||||
|
||||
from ..legacy.util import reject_stdin
|
||||
from ..legacy.index import write_links_index
|
||||
from ..legacy.config import (
|
||||
OUTPUT_DIR,
|
||||
SOURCES_DIR,
|
||||
ARCHIVE_DIR,
|
||||
DATABASE_DIR,
|
||||
ANSI,
|
||||
stderr,
|
||||
)
|
||||
|
||||
|
||||
def init(output_dir: str=OUTPUT_DIR):
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
harmless_files = {'.DS_Store', '.venv', 'venv', 'virtualenv', '.virtualenv'}
|
||||
is_empty = not len(set(os.listdir(output_dir)) - harmless_files)
|
||||
existing_index = os.path.exists(os.path.join(output_dir, 'index.json'))
|
||||
|
||||
if not is_empty:
|
||||
if existing_index:
|
||||
stderr('{green}[√] You already have an archive index in this folder.{reset}'.format(**ANSI))
|
||||
stderr(' To add new links, you can run:')
|
||||
stderr(" archivebox add 'https://example.com'")
|
||||
stderr()
|
||||
stderr(' For more usage and examples, run:')
|
||||
stderr(' archivebox help')
|
||||
# TODO: import old archivebox version's archive data folder
|
||||
|
||||
raise SystemExit(1)
|
||||
else:
|
||||
stderr(
|
||||
("{red}[X] This folder already has files in it. You must run init inside a completely empty directory.{reset}"
|
||||
"\n\n"
|
||||
" {lightred}Hint:{reset} To import a data folder created by an older version of ArchiveBox, \n"
|
||||
" just cd into the folder and run the archivebox command to pick up where you left off.\n\n"
|
||||
" (Always make sure your data folder is backed up first before updating ArchiveBox)"
|
||||
).format(output_dir, **ANSI)
|
||||
)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
stderr('{green}[+] Initializing new archive directory: {}{reset}'.format(output_dir, **ANSI))
|
||||
os.makedirs(SOURCES_DIR)
|
||||
stderr(f' > {SOURCES_DIR}')
|
||||
os.makedirs(ARCHIVE_DIR)
|
||||
stderr(f' > {ARCHIVE_DIR}')
|
||||
os.makedirs(DATABASE_DIR)
|
||||
stderr(f' > {DATABASE_DIR}')
|
||||
|
||||
write_links_index([], out_dir=OUTPUT_DIR, finished=True)
|
||||
|
||||
stderr('{green}[√] Done.{reset}'.format(**ANSI))
|
||||
from ..legacy.main import init
|
||||
|
||||
|
||||
def main(args=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue