mirror of https://github.com/searxng/searxng.git
[mod] settings.yml can be /etc/searx/settings.yml
The exact order is * first from SEARX_SETTINGS_PATH, * if not found then from searx code base, * if not found then from /etc/searx/settings.yml * if not found an exception stops searx loading
This commit is contained in:
parent
ee080feaed
commit
9c91ab33f8
|
@ -18,7 +18,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||||
import certifi
|
import certifi
|
||||||
import logging
|
import logging
|
||||||
from os import environ
|
from os import environ
|
||||||
from os.path import realpath, dirname, join, abspath
|
from os.path import realpath, dirname, join, abspath, isfile
|
||||||
from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
|
from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
|
||||||
try:
|
try:
|
||||||
from yaml import load
|
from yaml import load
|
||||||
|
@ -30,13 +30,24 @@ except:
|
||||||
searx_dir = abspath(dirname(__file__))
|
searx_dir = abspath(dirname(__file__))
|
||||||
engine_dir = dirname(realpath(__file__))
|
engine_dir = dirname(realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
def check_settings_yml(file_name):
|
||||||
|
if isfile(file_name):
|
||||||
|
return file_name
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# find location of settings.yml
|
||||||
|
if 'SEARX_SETTINGS_PATH' in environ:
|
||||||
# if possible set path to settings using the
|
# if possible set path to settings using the
|
||||||
# enviroment variable SEARX_SETTINGS_PATH
|
# enviroment variable SEARX_SETTINGS_PATH
|
||||||
if 'SEARX_SETTINGS_PATH' in environ:
|
settings_path = check_settings_yml(environ['SEARX_SETTINGS_PATH'])
|
||||||
settings_path = environ['SEARX_SETTINGS_PATH']
|
|
||||||
# otherwise using default path
|
|
||||||
else:
|
else:
|
||||||
settings_path = join(searx_dir, 'settings.yml')
|
# if not, get it from searx code base or last solution from /etc/searx
|
||||||
|
settings_path = check_settings_yml(join(searx_dir, 'settings.yml')) or check_settings_yml('/etc/searx/settings.yml')
|
||||||
|
|
||||||
|
if not settings_path:
|
||||||
|
raise Exception('settings.yml not found')
|
||||||
|
|
||||||
# load settings
|
# load settings
|
||||||
with open(settings_path) as settings_yaml:
|
with open(settings_path) as settings_yaml:
|
||||||
|
@ -67,7 +78,7 @@ else:
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
|
||||||
logger = logging.getLogger('searx')
|
logger = logging.getLogger('searx')
|
||||||
|
logger.debug('read configuration from %s', settings_path)
|
||||||
# Workaround for openssl versions <1.0.2
|
# Workaround for openssl versions <1.0.2
|
||||||
# https://github.com/certifi/python-certifi/issues/26
|
# https://github.com/certifi/python-certifi/issues/26
|
||||||
if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
|
if OPENSSL_VERSION_INFO[0:3] < (1, 0, 2):
|
||||||
|
|
|
@ -186,9 +186,9 @@ def get_resources_directory(searx_directory, subdirectory, resources_directory):
|
||||||
return resources_directory
|
return resources_directory
|
||||||
|
|
||||||
|
|
||||||
def get_themes(static_path):
|
def get_themes(templates_path):
|
||||||
"""Returns available themes list."""
|
"""Returns available themes list."""
|
||||||
themes = os.listdir(os.path.join(static_path, 'themes'))
|
themes = os.listdir(templates_path)
|
||||||
if '__common__' in themes:
|
if '__common__' in themes:
|
||||||
themes.remove('__common__')
|
themes.remove('__common__')
|
||||||
return themes
|
return themes
|
||||||
|
|
|
@ -100,7 +100,7 @@ static_files = get_static_files(static_path)
|
||||||
default_theme = settings['ui']['default_theme']
|
default_theme = settings['ui']['default_theme']
|
||||||
templates_path = get_resources_directory(searx_dir, 'templates', settings['ui']['templates_path'])
|
templates_path = get_resources_directory(searx_dir, 'templates', settings['ui']['templates_path'])
|
||||||
logger.debug('templates directory is %s', templates_path)
|
logger.debug('templates directory is %s', templates_path)
|
||||||
themes = get_themes(static_path)
|
themes = get_themes(templates_path)
|
||||||
result_templates = get_result_templates(templates_path)
|
result_templates = get_result_templates(templates_path)
|
||||||
global_favicons = []
|
global_favicons = []
|
||||||
for indice, theme in enumerate(themes):
|
for indice, theme in enumerate(themes):
|
||||||
|
|
Loading…
Reference in New Issue