mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 07:04:27 -04:00
call validate functions at AppConfig.ready time manually
This commit is contained in:
parent
7a6f1f36d2
commit
267fde0138
12 changed files with 43 additions and 24 deletions
|
@ -28,6 +28,7 @@ def get_PLUGIN():
|
|||
@abx.hookimpl
|
||||
def get_CONFIG():
|
||||
from .config import LDAP_CONFIG
|
||||
|
||||
return {
|
||||
__id__: LDAP_CONFIG
|
||||
}
|
||||
|
@ -64,6 +65,10 @@ def ready():
|
|||
"""
|
||||
Called at AppConfig.ready() time (settings + models are all loaded)
|
||||
"""
|
||||
from .config import LDAP_CONFIG
|
||||
|
||||
LDAP_CONFIG.validate()
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if settings.CONFIGS.ldap.LDAP_ENABLED:
|
||||
|
|
|
@ -50,8 +50,7 @@ class LdapConfig(BaseConfigSet):
|
|||
LDAP_LASTNAME_ATTR: str = Field(default='last_name')
|
||||
LDAP_EMAIL_ATTR: str = Field(default='email')
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_ldap_config(self):
|
||||
def validate(self):
|
||||
if self.LDAP_ENABLED:
|
||||
LDAP_LIB, _LDAPSearch = get_ldap_lib()
|
||||
# Check that LDAP libraries are installed
|
||||
|
|
|
@ -37,6 +37,12 @@ def get_BINARIES():
|
|||
'chrome': CHROME_BINARY,
|
||||
}
|
||||
|
||||
@abx.hookimpl
|
||||
def ready():
|
||||
from .config import CHROME_CONFIG
|
||||
CHROME_CONFIG.validate()
|
||||
|
||||
|
||||
# @abx.hookimpl
|
||||
# def get_EXTRACTORS():
|
||||
# return {
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
__package__ = 'plugins_extractor.chrome'
|
||||
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic import Field
|
||||
from pydantic_pkgr import bin_abspath
|
||||
|
||||
from abx.archivebox.base_configset import BaseConfigSet
|
||||
from abx.archivebox.base_binary import env
|
||||
|
||||
from archivebox.config import CONSTANTS
|
||||
from archivebox.config.common import ARCHIVING_CONFIG, SHELL_CONFIG
|
||||
from archivebox.misc.logging import STDERR
|
||||
from archivebox.misc.util import dedupe
|
||||
from archivebox.logging_util import pretty_path
|
||||
|
||||
|
||||
CHROMIUM_BINARY_NAMES_LINUX = [
|
||||
|
|
|
@ -45,3 +45,8 @@ def get_EXTRACTORS():
|
|||
'wget': WGET_EXTRACTOR,
|
||||
'warc': WARC_EXTRACTOR,
|
||||
}
|
||||
|
||||
@abx.hookimpl
|
||||
def ready():
|
||||
from .config import WGET_CONFIG
|
||||
WGET_CONFIG.validate()
|
||||
|
|
|
@ -4,7 +4,7 @@ import subprocess
|
|||
from typing import List, Optional
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic import Field
|
||||
|
||||
from abx.archivebox.base_configset import BaseConfigSet
|
||||
|
||||
|
@ -40,8 +40,7 @@ class WgetConfig(BaseConfigSet):
|
|||
WGET_USER_AGENT: str = Field(default=lambda: ARCHIVING_CONFIG.USER_AGENT)
|
||||
WGET_COOKIES_FILE: Optional[Path] = Field(default=lambda: ARCHIVING_CONFIG.COOKIES_FILE)
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_use_ytdlp(self):
|
||||
def validate(self):
|
||||
if self.USE_WGET and self.WGET_TIMEOUT < 10:
|
||||
STDERR.print(f'[red][!] Warning: TIMEOUT is set too low! (currently set to TIMEOUT={self.WGET_TIMEOUT} seconds)[/red]')
|
||||
STDERR.print(' wget will fail to archive any sites if set to less than ~20 seconds.')
|
||||
|
|
|
@ -35,3 +35,8 @@ def get_BINARIES():
|
|||
'ytdlp': YTDLP_BINARY,
|
||||
'ffmpeg': FFMPEG_BINARY,
|
||||
}
|
||||
|
||||
@abx.hookimpl
|
||||
def ready():
|
||||
from .config import YTDLP_CONFIG
|
||||
YTDLP_CONFIG.validate()
|
||||
|
|
|
@ -2,7 +2,7 @@ __package__ = 'plugins_extractor.ytdlp'
|
|||
|
||||
from typing import List
|
||||
|
||||
from pydantic import Field, model_validator, AliasChoices
|
||||
from pydantic import Field, AliasChoices
|
||||
|
||||
from abx.archivebox.base_configset import BaseConfigSet
|
||||
|
||||
|
@ -19,8 +19,7 @@ class YtdlpConfig(BaseConfigSet):
|
|||
YTDLP_CHECK_SSL_VALIDITY: bool = Field(default=lambda: ARCHIVING_CONFIG.CHECK_SSL_VALIDITY)
|
||||
YTDLP_TIMEOUT: int = Field(default=lambda: ARCHIVING_CONFIG.MEDIA_TIMEOUT)
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_use_ytdlp(self):
|
||||
def validate(self):
|
||||
if self.USE_YTDLP and self.YTDLP_TIMEOUT < 20:
|
||||
STDERR.print(f'[red][!] Warning: MEDIA_TIMEOUT is set too low! (currently set to MEDIA_TIMEOUT={self.YTDLP_TIMEOUT} seconds)[/red]')
|
||||
STDERR.print(' youtube-dl/yt-dlp will fail to archive any media if set to less than ~20 seconds.')
|
||||
|
|
|
@ -112,7 +112,7 @@ SQLITE_BINARY = SqliteBinary()
|
|||
|
||||
LOADED_DJANGO_PATH = Path(django.__file__)
|
||||
LOADED_DJANGO_VERSION = SemVer(django.VERSION[:3])
|
||||
LOADED_DJANGO_FROM_VENV = str(LOADED_DJANGO_PATH.absolute().resolve()).startswith(str(VENV_PIP_BINPROVIDER.pip_venv.absolute().resolve()))
|
||||
LOADED_DJANGO_FROM_VENV = str(LOADED_DJANGO_PATH.absolute().resolve()).startswith(str(VENV_PIP_BINPROVIDER.pip_venv and VENV_PIP_BINPROVIDER.pip_venv.absolute().resolve()))
|
||||
|
||||
class DjangoBinary(BaseBinary):
|
||||
name: BinName = 'django'
|
||||
|
|
|
@ -46,3 +46,8 @@ def get_SEARCHBACKENDS():
|
|||
return {
|
||||
'sonic': SONIC_SEARCH_BACKEND,
|
||||
}
|
||||
|
||||
@abx.hookimpl
|
||||
def ready():
|
||||
from .config import SONIC_CONFIG
|
||||
SONIC_CONFIG.validate()
|
||||
|
|
|
@ -2,7 +2,7 @@ __package__ = 'plugins_search.sonic'
|
|||
|
||||
import sys
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic import Field
|
||||
|
||||
from abx.archivebox.base_configset import BaseConfigSet
|
||||
|
||||
|
@ -32,13 +32,10 @@ class SonicConfig(BaseConfigSet):
|
|||
SONIC_MAX_TEXT_LENGTH: int = Field(default=100000000)
|
||||
SONIC_MAX_RETRIES: int = Field(default=5)
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_sonic_port(self):
|
||||
def validate(self):
|
||||
if SEARCH_BACKEND_CONFIG.SEARCH_BACKEND_ENGINE == 'sonic' and SONIC_LIB is None:
|
||||
sys.stderr.write('[X] Error: Sonic search backend is enabled but sonic-client lib is not installed. You may need to run: pip install archivebox[sonic]\n')
|
||||
# dont hard exit here. in case the user is just running "archivebox version" or "archivebox help", we still want those to work despite broken ldap
|
||||
# sys.exit(1)
|
||||
SEARCH_BACKEND_CONFIG.update_in_place(SEARCH_BACKEND_ENGINE='ripgrep')
|
||||
return self
|
||||
|
||||
SONIC_CONFIG = SonicConfig()
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Callable
|
|||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from pydantic import Field
|
||||
|
||||
from abx.archivebox.base_configset import BaseConfigSet
|
||||
|
||||
|
@ -27,12 +27,10 @@ class SqliteftsConfig(BaseConfigSet):
|
|||
SQLITEFTS_ID_TABLE: str = Field(default='snapshot_id_fts')
|
||||
SQLITEFTS_COLUMN: str = Field(default='texts')
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_fts_separate_database(self):
|
||||
def validate(self):
|
||||
if SEARCH_BACKEND_CONFIG.SEARCH_BACKEND_ENGINE == 'sqlite' and self.SQLITEFTS_SEPARATE_DATABASE and not self.SQLITEFTS_DB:
|
||||
sys.stderr.write('[X] Error: SQLITEFTS_DB must be set if SQLITEFTS_SEPARATE_DATABASE is True\n')
|
||||
SEARCH_BACKEND_CONFIG.update_in_place(SEARCH_BACKEND_ENGINE='ripgrep')
|
||||
return self
|
||||
|
||||
@property
|
||||
def get_connection(self) -> Callable[[], sqlite3.Connection]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue