ArchiveBox/archivebox/__init__.py

151 lines
11 KiB
Python
Raw Normal View History

2024-10-02 21:17:28 +00:00
#!/usr/bin/env python3
2024-10-04 10:24:15 +00:00
2024-10-02 21:17:28 +00:00
# Welcome to the ArchiveBox source code! Thanks for checking it out!
#
# "We are swimming upstream against a great torrent of disorganization.
# In this, our main obligation is to establish arbitrary enclaves of order and system.
# It is the greatest possible victory to be, to continue to be, and to have been.
# No defeat can deprive us of the success of having existed for some moment of time
# in a universe that seems indifferent to us."
# --Norber Weiner
2019-04-17 03:18:42 +00:00
__package__ = 'archivebox'
2024-05-06 14:13:25 +00:00
import os
import sys
from pathlib import Path
2024-10-28 11:07:35 +00:00
from typing import cast
2024-10-04 10:24:15 +00:00
ASCII_LOGO = """
"""
# make sure PACKAGE_DIR is in sys.path so we can import all subfolders
# without necessarily waiting for django to load them thorugh INSTALLED_APPS
PACKAGE_DIR = Path(__file__).resolve().parent
if str(PACKAGE_DIR) not in sys.path:
sys.path.append(str(PACKAGE_DIR))
os.environ['DJANGO_SETTINGS_MODULE'] = 'core.settings'
os.environ['TZ'] = 'UTC'
2024-10-08 07:15:53 +00:00
# detect ArchiveBox user's UID/GID based on data dir ownership
from .config.permissions import drop_privileges # noqa
drop_privileges()
from .misc.checks import check_not_root, check_io_encoding # noqa
check_not_root()
check_io_encoding()
2024-09-30 22:59:05 +00:00
# print('INSTALLING MONKEY PATCHES')
2024-10-08 07:12:09 +00:00
from .monkey_patches import * # noqa
2024-09-30 22:59:05 +00:00
# print('DONE INSTALLING MONKEY PATCHES')
2024-10-02 21:17:28 +00:00
# print('LOADING VENDORED LIBRARIES')
2024-10-08 07:12:09 +00:00
from .vendor import load_vendored_libs # noqa
2024-09-30 22:59:05 +00:00
load_vendored_libs()
2024-10-02 21:17:28 +00:00
# print('DONE LOADING VENDORED LIBRARIES')
2024-10-28 11:07:35 +00:00
import abx # noqa
import abx_spec_archivebox # noqa
import abx_spec_config # noqa
import abx_spec_pydantic_pkgr # noqa
import abx_spec_django # noqa
import abx_spec_searchbackend # noqa
abx.pm.add_hookspecs(abx_spec_config.PLUGIN_SPEC)
abx.pm.register(abx_spec_config.PLUGIN_SPEC())
abx.pm.add_hookspecs(abx_spec_pydantic_pkgr.PLUGIN_SPEC)
abx.pm.register(abx_spec_pydantic_pkgr.PLUGIN_SPEC())
abx.pm.add_hookspecs(abx_spec_django.PLUGIN_SPEC)
abx.pm.register(abx_spec_django.PLUGIN_SPEC())
abx.pm.add_hookspecs(abx_spec_searchbackend.PLUGIN_SPEC)
abx.pm.register(abx_spec_searchbackend.PLUGIN_SPEC())
abx.pm = cast(abx.ABXPluginManager[abx_spec_archivebox.ArchiveBoxPluginSpec], abx.pm)
pm = abx.pm
# Load all installed ABX-compatible plugins
ABX_ECOSYSTEM_PLUGINS = abx.get_pip_installed_plugins(group='abx')
# Load all ArchiveBox-specific plugins
ARCHIVEBOX_BUILTIN_PLUGINS = {
'config': PACKAGE_DIR / 'config',
'core': PACKAGE_DIR / 'core',
# 'search': PACKAGE_DIR / 'search',
# 'core': PACKAGE_DIR / 'core',
}
# Load all user-defined ArchiveBox plugins
USER_PLUGINS = abx.find_plugins_in_dir(Path(os.getcwd()) / 'user_plugins')
# Merge all plugins together
ALL_PLUGINS = {**ABX_ECOSYSTEM_PLUGINS, **ARCHIVEBOX_BUILTIN_PLUGINS, **USER_PLUGINS}
# Load ArchiveBox plugins
LOADED_PLUGINS = abx.load_plugins(ALL_PLUGINS)
2024-10-08 07:12:09 +00:00
from .config.constants import CONSTANTS # noqa
from .config.paths import PACKAGE_DIR, DATA_DIR, ARCHIVE_DIR # noqa
from .config.version import VERSION # noqa
__version__ = VERSION
2024-10-15 08:00:21 +00:00
__author__ = 'ArchiveBox'
2024-09-30 22:59:05 +00:00
__license__ = 'MIT'
2024-10-02 21:17:28 +00:00
2024-10-03 02:46:31 +00:00
ASCII_ICON = """
"""