diff --git a/archivebox/abid_utils/models.py b/archivebox/abid_utils/models.py index 6c7cfd0e..f36bfcd9 100644 --- a/archivebox/abid_utils/models.py +++ b/archivebox/abid_utils/models.py @@ -174,7 +174,7 @@ class ABIDModel(models.Model): 'uri': self.abid_uri_src, 'subtype': self.abid_subtype_src, 'rand': self.abid_rand_src, - 'salt': 'self.abid_salt', # defined as static class vars at build time + 'salt': 'self.abid_salt', # defined as static class vars at build time } @property diff --git a/archivebox/main.py b/archivebox/main.py index ce6347b2..9ce0b9bd 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -199,15 +199,13 @@ def version(quiet: bool=False, console = Console() prnt = console.print - from django.conf import settings - from abx_plugin_default_binproviders import apt, brew, env 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.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 diff --git a/archivebox/pkgs/abx-plugin-pocket/abx_plugin_pocket/config.py b/archivebox/pkgs/abx-plugin-pocket/abx_plugin_pocket/config.py index 2db072a1..31f691b2 100644 --- a/archivebox/pkgs/abx-plugin-pocket/abx_plugin_pocket/config.py +++ b/archivebox/pkgs/abx-plugin-pocket/abx_plugin_pocket/config.py @@ -1,15 +1,12 @@ -__package__ = 'abx_plugin_pocket' - from typing import Dict - from pydantic import Field -from abx_spec_config.base_configset import BaseConfigSet +from abx_spec_config import BaseConfigSet class PocketConfig(BaseConfigSet): POCKET_CONSUMER_KEY: str | None = Field(default=None) - POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=lambda: {}) # {: , ...} + POCKET_ACCESS_TOKENS: Dict[str, str] = Field(default=dict) # {: , ...} POCKET_CONFIG = PocketConfig() diff --git a/archivebox/pkgs/abx-spec-config/abx_spec_config/__init__.py b/archivebox/pkgs/abx-spec-config/abx_spec_config/__init__.py index 3feaab82..6aeedb71 100644 --- a/archivebox/pkgs/abx-spec-config/abx_spec_config/__init__.py +++ b/archivebox/pkgs/abx-spec-config/abx_spec_config/__init__.py @@ -51,6 +51,91 @@ class ConfigPluginSpec: for configset in pm.hook.get_CONFIGS().values() 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