mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-16 08:04:26 -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
|
@ -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
|
||||
|
||||
|
@ -31,14 +31,11 @@ class SonicConfig(BaseConfigSet):
|
|||
SONIC_MAX_CHUNK_LENGTH: int = Field(default=2000)
|
||||
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
|
||||
|
||||
|
@ -26,14 +26,12 @@ class SqliteftsConfig(BaseConfigSet):
|
|||
SQLITEFTS_TABLE: str = Field(default='snapshot_fts')
|
||||
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]:
|
||||
# Make get_connection callable, because `django.db.connection.cursor()`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue