From b9839500b272a9794ab17a63fd49013c7137d13f Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Wed, 27 Mar 2019 15:15:51 -0400 Subject: [PATCH] make archivebox use current directory as OUTPUT_DIR by default --- archivebox/config.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/archivebox/config.py b/archivebox/config.py index 1a6b6d6d..e564942e 100644 --- a/archivebox/config.py +++ b/archivebox/config.py @@ -66,15 +66,30 @@ REPO_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__ if OUTPUT_DIR: OUTPUT_DIR = os.path.abspath(OUTPUT_DIR) else: - OUTPUT_DIR = os.path.join(REPO_DIR, 'output') + OUTPUT_DIR = os.path.abspath(os.curdir) + +if not os.path.exists(OUTPUT_DIR): + print('{green}[+] Created a new archive directory: {}{reset}'.format(OUTPUT_DIR, **ANSI)) + os.makedirs(OUTPUT_DIR) +else: + not_empty = len(set(os.listdir(OUTPUT_DIR)) - {'.DS_Store'}) + index_exists = os.path.exists(os.path.join(OUTPUT_DIR, 'index.json')) + if not_empty and not index_exists: + print( + ('{red}[X] Could not find index.json in the OUTPUT_DIR: {reset}{}\n' + ' You must run ArchiveBox in an existing archive directory, \n' + ' or an empty/new directory to start a new archive collection.' + ).format(OUTPUT_DIR, **ANSI) + ) + raise SystemExit(1) ARCHIVE_DIR_NAME = 'archive' SOURCES_DIR_NAME = 'sources' ARCHIVE_DIR = os.path.join(OUTPUT_DIR, ARCHIVE_DIR_NAME) SOURCES_DIR = os.path.join(OUTPUT_DIR, SOURCES_DIR_NAME) -PYTHON_PATH = os.path.join(REPO_DIR, 'archivebox') -TEMPLATES_DIR = os.path.join(PYTHON_PATH, 'templates') +PYTHON_DIR = os.path.join(REPO_DIR, 'archivebox') +TEMPLATES_DIR = os.path.join(PYTHON_DIR, 'templates') if COOKIES_FILE: COOKIES_FILE = os.path.abspath(COOKIES_FILE)