129 for k, v
in user_settings.items():
130 if k
not in (
'use_default_settings',
'engines'):
131 if k
in default_settings
and isinstance(v, Mapping):
134 default_settings[k] = v
136 categories_as_tabs = user_settings.get(
'categories_as_tabs')
137 if categories_as_tabs:
138 default_settings[
'categories_as_tabs'] = categories_as_tabs
141 remove_engines =
None
142 keep_only_engines =
None
143 use_default_settings = user_settings.get(
'use_default_settings')
144 if isinstance(use_default_settings, dict):
145 remove_engines = use_default_settings.get(
'engines', {}).get(
'remove')
146 keep_only_engines = use_default_settings.get(
'engines', {}).get(
'keep_only')
148 if 'engines' in user_settings
or remove_engines
is not None or keep_only_engines
is not None:
149 engines = default_settings[
'engines']
152 if remove_engines
is not None:
153 engines = list(filterfalse(
lambda engine: (engine.get(
'name'))
in remove_engines, engines))
156 if keep_only_engines
is not None:
157 engines = list(filter(
lambda engine: (engine.get(
'name'))
in keep_only_engines, engines))
160 user_engines = user_settings.get(
'engines')
162 engines_dict = dict((definition[
'name'], definition)
for definition
in engines)
163 for user_engine
in user_engines:
164 default_engine = engines_dict.get(user_engine[
'name'])
168 engines.append(user_engine)
171 default_settings[
'engines'] = engines
173 return default_settings
189 """Function for loading the settings of the SearXNG application
190 (:ref:`settings.yml <searxng settings.yml>`)."""
192 msg = f
"load the default settings from {DEFAULT_SETTINGS_FILE}"
196 if not load_user_settings
or not cfg_folder:
199 settings_yml = os.environ.get(
"SEARXNG_SETTINGS_PATH")
200 if settings_yml
and Path(settings_yml).is_file():
202 settings_yml = Path(settings_yml).name
205 settings_yml = SETTINGS_YAML
207 cfg_file = cfg_folder / settings_yml
208 if not cfg_file.exists():
211 msg = f
"load the user settings from {cfg_file}"
216 msg = f
"merge the default settings ( {DEFAULT_SETTINGS_FILE} ) and the user settings ( {cfg_file} )"