__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """Implementations for providing the favicons in SearXNG.
  3. There is a command line for developer purposes and for deeper analysis. Here is
  4. an example in which the command line is called in the development environment::
  5. $ ./manage pyenv.cmd bash --norc --noprofile
  6. (py3) python -m searx.favicons --help
  7. """
  8. from __future__ import annotations
  9. __all__ = ["init", "favicon_url", "favicon_proxy"]
  10. import pathlib
  11. from searx import logger
  12. from searx import get_setting
  13. from .proxy import favicon_url, favicon_proxy
  14. logger = logger.getChild('favicons')
  15. def is_active():
  16. return bool(get_setting("search.favicon_resolver", False))
  17. def init():
  18. # pylint: disable=import-outside-toplevel
  19. from . import config, cache, proxy
  20. from .. import settings_loader
  21. cfg_file = (settings_loader.get_user_cfg_folder() or pathlib.Path("/etc/searxng")) / "favicons.toml"
  22. if not cfg_file.exists():
  23. if is_active():
  24. logger.error(f"missing favicon config: {cfg_file}")
  25. cfg_file = config.DEFAULT_CFG_TOML_PATH
  26. logger.debug(f"load favicon config: {cfg_file}")
  27. cfg = config.FaviconConfig.from_toml_file(cfg_file, use_cache=True)
  28. cache.init(cfg.cache)
  29. proxy.init(cfg.proxy)
  30. del cache, config, proxy, cfg, settings_loader