1
0
Fork 0
mirror of synced 2024-06-26 10:00:19 +12:00

fix database file location and init process

This commit is contained in:
Nick Sweeting 2019-04-17 05:42:09 -04:00
parent 88a37bc552
commit 289a6ea30f
4 changed files with 41 additions and 28 deletions

View file

@ -5,6 +5,11 @@ import os
SECRET_KEY = '---------------- not a valid secret key ! ----------------'
DEBUG = True
OUTPUT_DIR = os.path.abspath(os.curdir)
DATABASE_DIR_NAME = 'database'
DATABASE_FILE_NAME = 'database.sqlite3'
DATABASE_FILE = os.path.join(OUTPUT_DIR, DATABASE_DIR_NAME, DATABASE_FILE_NAME)
INSTALLED_APPS = [
'django.contrib.admin',
@ -15,7 +20,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'core',
'django_extensions',
]
@ -51,7 +56,7 @@ WSGI_APPLICATION = 'core.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(os.path.abspath(os.curdir), 'database', 'database.sqlite3'),
'NAME': DATABASE_FILE,
}
}
@ -67,7 +72,7 @@ LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
USE_TZ = False
STATIC_URL = '/static/'

View file

@ -98,7 +98,7 @@ DATABASE_FILE_NAME = 'database.sqlite3'
ARCHIVE_DIR = os.path.join(OUTPUT_DIR, ARCHIVE_DIR_NAME)
SOURCES_DIR = os.path.join(OUTPUT_DIR, SOURCES_DIR_NAME)
DATABASE_DIR = os.path.join(OUTPUT_DIR, DATABASE_DIR_NAME)
DATABASE_FILE = os.path.join(DATABASE_DIR, DATABASE_FILE_NAME)
DATABASE_FILE = os.path.join(OUTPUT_DIR, DATABASE_DIR_NAME, DATABASE_FILE_NAME)
PYTHON_DIR = os.path.join(REPO_DIR, 'archivebox')
LEGACY_DIR = os.path.join(PYTHON_DIR, 'legacy')
@ -346,7 +346,7 @@ try:
'DATABASE_DIR': {
'path': os.path.abspath(DATABASE_DIR),
'enabled': True,
'is_valid': os.path.exists(os.path.join(DATABASE_DIR, DATABASE_FILE)),
'is_valid': os.path.exists(DATABASE_FILE),
},
'CHROME_USER_DATA_DIR': {
'path': CHROME_USER_DATA_DIR and os.path.abspath(CHROME_USER_DATA_DIR),

View file

@ -71,7 +71,7 @@ def log_indexing_started(out_dir: str, out_file: str):
def log_indexing_finished(out_dir: str, out_file: str):
end_ts = datetime.now()
_LAST_RUN_STATS.index_end_ts = end_ts
print('\r{}/{}'.format(pretty_path(out_dir), out_file))
print('\r{}/{}'.format(out_dir, out_file))
### Archiving Stage

View file

@ -20,6 +20,7 @@ from .config import (
SOURCES_DIR,
ARCHIVE_DIR,
DATABASE_DIR,
DATABASE_FILE,
check_dependencies,
check_data_folder,
setup_django,
@ -39,21 +40,19 @@ from .logs import (
def init():
os.makedirs(OUTPUT_DIR, exist_ok=True)
harmless_files = {'.DS_Store', '.venv', 'venv', 'virtualenv', '.virtualenv'}
harmless_files = {'.DS_Store', '.venv', 'venv', 'virtualenv', '.virtualenv', 'sources', 'archive', 'database', 'logs', 'static'}
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 is_empty:
stderr('{green}[+] Initializing new archive directory: {}{reset}'.format(OUTPUT_DIR, **ANSI))
write_main_index([], out_dir=OUTPUT_DIR, finished=True)
else:
if existing_index:
stderr('{green}[√] You already have an archive index in: {}{reset}'.format(OUTPUT_DIR, **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)
stderr('{green}[√] You already have an ArchiveBox collection in the current folder.{reset}'.format(**ANSI))
stderr(f' {OUTPUT_DIR}')
stderr(f' > index.html')
stderr(f' > index.json')
else:
stderr(
("{red}[X] This folder already has files in it. You must run init inside a completely empty directory.{reset}"
@ -65,23 +64,32 @@ def init():
)
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_main_index([], out_dir=OUTPUT_DIR, finished=True)
os.makedirs(SOURCES_DIR, exist_ok=True)
stderr(f' > sources/')
os.makedirs(ARCHIVE_DIR, exist_ok=True)
stderr(f' > archive/')
os.makedirs(DATABASE_DIR, exist_ok=True)
setup_django()
from django.core.management import call_command
from django.contrib.auth.models import User
stderr(f' > database/')
stderr('\n{green}[+] Running Django migrations...{reset}'.format(**ANSI))
call_command("makemigrations", interactive=False)
call_command("migrate", interactive=False)
if not User.objects.filter(is_superuser=True).exists():
stderr('{green}[+] Creating admin user account...{reset}'.format(**ANSI))
call_command("createsuperuser", interactive=True)
stderr('{green}[√] Done.{reset}'.format(**ANSI))
stderr('\n{green}------------------------------------------------------------{reset}'.format(**ANSI))
stderr('{green}[√] Done. ArchiveBox collection is set up in current 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')