2021-06-01 14:03:19 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# lint: pylint
|
2021-09-07 11:34:35 +00:00
|
|
|
# pylint: disable=missing-module-docstring
|
2014-09-13 16:39:03 +00:00
|
|
|
|
2021-06-01 14:03:19 +00:00
|
|
|
from os.path import dirname, abspath
|
2015-01-09 03:01:31 +00:00
|
|
|
import logging
|
2021-06-01 14:03:19 +00:00
|
|
|
|
2021-06-08 09:34:36 +00:00
|
|
|
import searx.unixthreadname
|
2020-11-27 18:32:45 +00:00
|
|
|
import searx.settings_loader
|
2021-05-28 16:45:22 +00:00
|
|
|
from searx.settings_defaults import settings_set_defaults
|
2014-01-18 23:17:02 +00:00
|
|
|
|
2014-01-19 21:59:01 +00:00
|
|
|
searx_dir = abspath(dirname(__file__))
|
2021-04-27 08:42:00 +00:00
|
|
|
searx_parent_dir = abspath(dirname(dirname(__file__)))
|
2020-11-27 18:32:45 +00:00
|
|
|
settings, settings_load_message = searx.settings_loader.load_settings()
|
2014-09-14 09:09:44 +00:00
|
|
|
|
2021-05-28 16:45:22 +00:00
|
|
|
if settings is not None:
|
|
|
|
settings = settings_set_defaults(settings)
|
2016-10-22 17:07:37 +00:00
|
|
|
|
2021-05-28 16:45:22 +00:00
|
|
|
searx_debug = settings['general']['debug']
|
2016-10-22 17:07:37 +00:00
|
|
|
if searx_debug:
|
2015-01-09 03:01:31 +00:00
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
|
|
|
|
logger = logging.getLogger('searx')
|
2020-11-03 14:29:59 +00:00
|
|
|
logger.info(settings_load_message)
|
2017-12-29 08:13:29 +00:00
|
|
|
|
2021-05-28 16:45:22 +00:00
|
|
|
# log max_request_timeout
|
|
|
|
max_request_timeout = settings['outgoing']['max_request_timeout']
|
|
|
|
if max_request_timeout is None:
|
|
|
|
logger.info('max_request_timeout=%s', repr(max_request_timeout))
|
|
|
|
else:
|
|
|
|
logger.info('max_request_timeout=%i second(s)', max_request_timeout)
|
2020-12-27 13:39:48 +00:00
|
|
|
|
2021-07-17 17:03:54 +00:00
|
|
|
_unset = object()
|
|
|
|
|
|
|
|
def get_setting(name, default=_unset):
|
|
|
|
"""Returns the value to which ``name`` point. If there is no such name in the
|
|
|
|
settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
|
|
|
|
|
|
|
|
"""
|
|
|
|
value = settings
|
|
|
|
for a in name.split('.'):
|
|
|
|
if isinstance(value, dict):
|
|
|
|
value = value.get(a, _unset)
|
|
|
|
else:
|
|
|
|
value = _unset
|
|
|
|
|
|
|
|
if value is _unset:
|
|
|
|
if default is _unset:
|
|
|
|
raise KeyError(name)
|
|
|
|
value = default
|
|
|
|
break
|
|
|
|
|
|
|
|
return value
|