on master help sign in
[mod] change settings file structure according to #314
commit1fcf066a8188b28eb644ea304a131d40b1b341eb authorAdam Tauber <asciimoo@gmail.com> dateSun 2 Aug 2015, 19:38 (11 years ago) parentd0830d4
7 files changed+46−34
searx/autocomplete.py+1−1 searx/engines/__init__.py+1−1 searx/poolrequests.py+4−4 searx/settings.yml+15−11 searx/settings_robot.yml+12−5 searx/utils.py+2−1 searx/webapp.py+11−11
searx/autocomplete.py+1−1
@@ -29,7 +29,7 @@ from searx.poolrequests import get as http_get
2929
3030def get(*args, **kwargs):
3131 if 'timeout' not in kwargs:
32− kwargs['timeout'] = settings['server']['request_timeout']
32+ kwargs['timeout'] = settings['outgoing']['request_timeout']
3333
3434 return http_get(*args, **kwargs)
3535
searx/engines/__init__.py+1−1
@@ -75,7 +75,7 @@ def load_engine(engine_data):
7575 engine.safesearch = False
7676
7777 if not hasattr(engine, 'timeout'):
78− engine.timeout = settings['server']['request_timeout']
78+ engine.timeout = settings['outgoing']['request_timeout']
7979
8080 if not hasattr(engine, 'shortcut'):
8181 engine.shortcut = ''
searx/poolrequests.py+4−4
@@ -39,11 +39,11 @@ class HTTPAdapterWithConnParams(requests.adapters.HTTPAdapter):
3939 block=self._pool_block, **self._conn_params)
4040
4141
42−if settings.get('source_ips'):
42+if settings['outgoing'].get('source_ips'):
4343 http_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=100, source_address=(source_ip, 0))
44− for source_ip in settings['source_ips'])
44+ for source_ip in settings['outgoing']['source_ips'])
4545 https_adapters = cycle(HTTPAdapterWithConnParams(pool_connections=100, source_address=(source_ip, 0))
46− for source_ip in settings['source_ips'])
46+ for source_ip in settings['outgoing']['source_ips'])
4747else:
4848 http_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=100), ))
4949 https_adapters = cycle((HTTPAdapterWithConnParams(pool_connections=100), ))
@@ -69,7 +69,7 @@ def request(method, url, **kwargs):
6969 """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies"""
7070 global settings
7171 session = SessionSinglePool()
72− kwargs['proxies'] = settings.get('outgoing_proxies', None)
72+ kwargs['proxies'] = settings['outgoing'].get('proxies', None)
7373 response = session.request(method=method, url=url, **kwargs)
7474 session.close()
7575 return response
searx/settings.yml+15−11
@@ -1,28 +1,32 @@
1+general:
2+ debug : False # Debug mode, only for development
3+
14server:
25 port : 8888
36 bind_address : "127.0.0.1" # address to listen on
47 secret_key : "ultrasecretkey" # change this!
5− debug : False # Debug mode, only for development
6− request_timeout : 2.0 # seconds
78 base_url : False # Set custom base_url. Possible values: False or "https://your.custom.host/location/"
9+ image_proxy : False # Proxying image results through searx
10+
11+ui:
812 themes_path : "" # Custom ui themes path - leave it blank if you didn't change
913 default_theme : oscar # ui theme
10− useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
11− image_proxy : False # Proxying image results through searx
1214 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
1315
16+outgoing: # communication with search engines
17+ request_timeout : 2.0 # seconds
18+ useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
1419# uncomment below section if you want to use a proxy
1520# see http://docs.python-requests.org/en/latest/user/advanced/#proxies
1621# SOCKS proxies are not supported : see https://github.com/kennethreitz/requests/pull/478
17−#outgoing_proxies :
18−# http : http://127.0.0.1:8080
19−# https: http://127.0.0.1:8080
20−
22+# proxies :
23+# http : http://127.0.0.1:8080
24+# https: http://127.0.0.1:8080
2125# uncomment below section only if you have more than one network interface
2226# which can be the source of outgoing search requests
23−#source_ips:
24−# - 1.1.1.1
25−# - 1.1.1.2
27+# source_ips:
28+# - 1.1.1.1
29+# - 1.1.1.2
2630
2731engines:
2832 - name : wikipedia
searx/settings_robot.yml+12−5
@@ -1,14 +1,21 @@
1+general:
2+ debug : False
3+
14server:
25 port : 11111
36 bind_address : 127.0.0.1
47 secret_key : "ultrasecretkey" # change this!
5− debug : False
6− request_timeout : 3.0 # seconds
7− base_url: False
8+ base_url : False
9+ image_proxy : False
10+
11+ui:
812 themes_path : ""
913 default_theme : default
10− https_rewrite : True
11− image_proxy : False
14+ default_locale : ""
15+
16+outgoing:
17+ request_timeout : 1.0 # seconds
18+ useragent_suffix : ""
1219
1320engines:
1421 - name : general_dummy
searx/utils.py+2−1
@@ -26,6 +26,7 @@ ua_versions = ('33.0',
2626ua_os = ('Windows NT 6.3; WOW64',
2727 'X11; Linux x86_64',
2828 'X11; Linux x86')
29+
2930ua = "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}"
3031
3132blocked_tags = ('script',
@@ -40,7 +41,7 @@ def gen_useragent():
4041def searx_useragent():
4142 return 'searx/{searx_version} {suffix}'.format(
4243 searx_version=VERSION_STRING,
43− suffix=settings['server'].get('useragent_suffix', ''))
44+ suffix=settings['outgoing'].get('useragent_suffix', ''))
4445
4546
4647def highlight_content(content, query):
searx/webapp.py+11−11
@@ -77,11 +77,11 @@ except ImportError:
7777
7878
7979static_path, templates_path, themes =\
80− get_themes(settings['themes_path']
81− if settings.get('themes_path')
80+ get_themes(settings['ui']['themes_path']
81+ if settings['ui']['themes_path']
8282 else searx_dir)
8383
84−default_theme = settings['server'].get('default_theme', 'default')
84+default_theme = settings['ui']['default_theme']
8585
8686static_files = get_static_files(searx_dir)
8787
@@ -121,15 +121,15 @@ _category_names = (gettext('files'),
121121 gettext('news'),
122122 gettext('map'))
123123
124−outgoing_proxies = settings.get('outgoing_proxies', None)
124+outgoing_proxies = settings['outgoing'].get('proxies', None)
125125
126126
127127@babel.localeselector
128128def get_locale():
129129 locale = request.accept_languages.best_match(settings['locales'].keys())
130130
131− if settings['server'].get('default_locale'):
132− locale = settings['server']['default_locale']
131+ if settings['ui'].get('default_locale'):
132+ locale = settings['ui']['default_locale']
133133
134134 if request.cookies.get('locale', '') in settings['locales']:
135135 locale = request.cookies.get('locale', '')
@@ -640,12 +640,12 @@ def preferences():
640640 stats[e.name] = {'time': None,
641641 'warn_timeout': False,
642642 'warn_time': False}
643− if e.timeout > settings['server']['request_timeout']:
643+ if e.timeout > settings['outgoing']['request_timeout']:
644644 stats[e.name]['warn_timeout'] = True
645645
646646 for engine_stat in get_engines_stats()[0][1]:
647647 stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3)
648− if engine_stat.get('avg') > settings['server']['request_timeout']:
648+ if engine_stat.get('avg') > settings['outgoing']['request_timeout']:
649649 stats[engine_stat.get('name')]['warn_time'] = True
650650 # end of stats
651651
@@ -683,7 +683,7 @@ def image_proxy():
683683
684684 resp = requests.get(url,
685685 stream=True,
686− timeout=settings['server'].get('request_timeout', 2),
686+ timeout=settings['outgoing']['request_timeout'],
687687 headers=headers,
688688 proxies=outgoing_proxies)
689689
@@ -775,8 +775,8 @@ def clear_cookies():
775775
776776def run():
777777 app.run(
778− debug=settings['server']['debug'],
779− use_debugger=settings['server']['debug'],
778+ debug=settings['general']['debug'],
779+ use_debugger=settings['general']['debug'],
780780 port=settings['server']['port'],
781781 host=settings['server']['bind_address']
782782 )