mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 14:44:29 -04:00
add get_SCOPE_CONFIG
Some checks are pending
Build Debian package / build (push) Waiting to run
Build Docker image / buildx (push) Waiting to run
Build Homebrew package / build (push) Waiting to run
Run linters / lint (push) Waiting to run
Build Pip package / build (push) Waiting to run
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Waiting to run
Run tests / docker_tests (push) Waiting to run
Some checks are pending
Build Debian package / build (push) Waiting to run
Build Docker image / buildx (push) Waiting to run
Build Homebrew package / build (push) Waiting to run
Run linters / lint (push) Waiting to run
Build Pip package / build (push) Waiting to run
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Waiting to run
Run tests / docker_tests (push) Waiting to run
This commit is contained in:
parent
eb721bd514
commit
5efeb9d347
4 changed files with 89 additions and 9 deletions
|
@ -199,15 +199,13 @@ def version(quiet: bool=False,
|
||||||
console = Console()
|
console = Console()
|
||||||
prnt = console.print
|
prnt = console.print
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from abx_plugin_default_binproviders import apt, brew, env
|
from abx_plugin_default_binproviders import apt, brew, env
|
||||||
|
|
||||||
from archivebox.config.version import get_COMMIT_HASH, get_BUILD_TIME
|
from archivebox.config.version import get_COMMIT_HASH, get_BUILD_TIME
|
||||||
from archivebox.config.permissions import ARCHIVEBOX_USER, ARCHIVEBOX_GROUP, RUNNING_AS_UID, RUNNING_AS_GID
|
from archivebox.config.permissions import ARCHIVEBOX_USER, ARCHIVEBOX_GROUP, RUNNING_AS_UID, RUNNING_AS_GID
|
||||||
from archivebox.config.paths import get_data_locations, get_code_locations
|
from archivebox.config.paths import get_data_locations, get_code_locations
|
||||||
|
|
||||||
LDAP_ENABLED = archivebox.pm.hook.get_FLAT_CONFIG().LDAP_ENABLED
|
LDAP_ENABLED = archivebox.pm.hook.get_SCOPE_CONFIG().LDAP_ENABLED
|
||||||
|
|
||||||
|
|
||||||
# 0.7.1
|
# 0.7.1
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
__package__ = 'abx_plugin_pocket'
|
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from abx_spec_config.base_configset import BaseConfigSet
|
from abx_spec_config import BaseConfigSet
|
||||||
|
|
||||||
|
|
||||||
class PocketConfig(BaseConfigSet):
|
class PocketConfig(BaseConfigSet):
|
||||||
POCKET_CONSUMER_KEY: str | None = Field(default=None)
|
POCKET_CONSUMER_KEY: str | None = Field(default=None)
|
||||||
POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=lambda: {}) # {<username>: <access_token>, ...}
|
POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=dict) # {<username>: <access_token>, ...}
|
||||||
|
|
||||||
|
|
||||||
POCKET_CONFIG = PocketConfig()
|
POCKET_CONFIG = PocketConfig()
|
||||||
|
|
|
@ -52,6 +52,91 @@ class ConfigPluginSpec:
|
||||||
for key, value in benedict(configset).items()
|
for key, value in benedict(configset).items()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_SCOPE_CONFIG(self, extra=None, archiveresult=None, snapshot=None, crawl=None, user=None, collection=..., environment=..., machine=..., default=...) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
"""Get the config as it applies to you right now, based on the current context"""
|
||||||
|
return benedict({
|
||||||
|
**pm.hook.get_default_config(default=default),
|
||||||
|
# **pm.hook.get_machine_config(machine),
|
||||||
|
**pm.hook.get_environment_config(environment=environment),
|
||||||
|
**pm.hook.get_collection_config(collection=collection),
|
||||||
|
**pm.hook.get_user_config(user=user),
|
||||||
|
**pm.hook.get_crawl_config(crawl=crawl),
|
||||||
|
**pm.hook.get_snapshot_config(snapshot=snapshot),
|
||||||
|
**pm.hook.get_archiveresult_config(archiveresult=archiveresult),
|
||||||
|
# **pm.hook.get_request_config(request=request),
|
||||||
|
**(extra or {}),
|
||||||
|
})
|
||||||
|
|
||||||
|
# @abx.hookspec(firstresult=True)
|
||||||
|
# @abx.hookimpl
|
||||||
|
# def get_request_config(self, request) -> dict:
|
||||||
|
# session = getattr(request, 'session', None)
|
||||||
|
# return getattr(session, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_archiveresult_config(self, archiveresult) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
return getattr(archiveresult, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_snapshot_config(self, snapshot) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
return getattr(snapshot, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_crawl_config(self, crawl) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
return getattr(crawl, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_user_config(self, user=None) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
return getattr(user, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_collection_config(self, collection=...) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
# ... = ellipsis, means automatically get the collection config from the active data/ArchiveBox.conf file
|
||||||
|
# {} = empty dict, override to ignore the collection config
|
||||||
|
return benedict({
|
||||||
|
key: value
|
||||||
|
for configset in pm.hook.get_CONFIGS().values()
|
||||||
|
for key, value in configset.from_collection().items()
|
||||||
|
}) if collection == ... else collection
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_environment_config(self, environment=...) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
# ... = ellipsis, means automatically get the environment config from the active environment variables
|
||||||
|
# {} = empty dict, override to ignore the environment config
|
||||||
|
return benedict({
|
||||||
|
key: value
|
||||||
|
for configset in pm.hook.get_CONFIGS().values()
|
||||||
|
for key, value in configset.from_environment().items()
|
||||||
|
}) if environment == ... else environment
|
||||||
|
|
||||||
|
# @abx.hookspec(firstresult=True)
|
||||||
|
# @abx.hookimpl
|
||||||
|
# def get_machine_config(self, machine=...) -> dict:
|
||||||
|
# # ... = ellipsis, means automatically get the machine config from the currently executing machine
|
||||||
|
# # {} = empty dict, override to ignore the machine config
|
||||||
|
# if machine == ...:
|
||||||
|
# machine = Machine.objects.get_current()
|
||||||
|
# return getattr(machine, 'config', None) or {}
|
||||||
|
|
||||||
|
@abx.hookspec(firstresult=True)
|
||||||
|
@abx.hookimpl
|
||||||
|
def get_default_config(self, default=...) -> Dict[ConfigKeyStr, Any]:
|
||||||
|
# ... = ellipsis, means automatically get the machine config from the currently executing machine
|
||||||
|
# {} = empty dict, override to ignore the machine config
|
||||||
|
return benedict({
|
||||||
|
key: value
|
||||||
|
for configset in pm.hook.get_CONFIGS().values()
|
||||||
|
for key, value in configset.from_defaults().items()
|
||||||
|
}) if default == ... else default
|
||||||
|
|
||||||
|
|
||||||
# TODO: add read_config_file(), write_config_file() hooks
|
# TODO: add read_config_file(), write_config_file() hooks
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue