|
@@ -5,11 +5,13 @@ import hashlib
|
|
import hmac
|
|
import hmac
|
|
import re
|
|
import re
|
|
import inspect
|
|
import inspect
|
|
|
|
+import itertools
|
|
|
|
|
|
from io import StringIO
|
|
from io import StringIO
|
|
from codecs import getincrementalencoder
|
|
from codecs import getincrementalencoder
|
|
|
|
|
|
-from searx import logger
|
|
|
|
|
|
+from searx import logger, settings
|
|
|
|
+from searx.engines import OTHER_CATEGORY
|
|
|
|
|
|
|
|
|
|
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$')
|
|
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$')
|
|
@@ -134,3 +136,26 @@ def is_flask_run_cmdline():
|
|
if len(frames) < 2:
|
|
if len(frames) < 2:
|
|
return False
|
|
return False
|
|
return frames[-2].filename.endswith('flask/cli.py')
|
|
return frames[-2].filename.endswith('flask/cli.py')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+DEFAULT_GROUP_NAME = 'others'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def group_engines_in_tab(engines):
|
|
|
|
+ def engine_sort_key(engine):
|
|
|
|
+ return (engine.about.get('language', ''), engine.name)
|
|
|
|
+
|
|
|
|
+ def group_sort_key(group):
|
|
|
|
+ return (group[0] == DEFAULT_GROUP_NAME, group[0].lower())
|
|
|
|
+
|
|
|
|
+ def get_group(eng):
|
|
|
|
+ non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs'] + [OTHER_CATEGORY]]
|
|
|
|
+ return non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME
|
|
|
|
+
|
|
|
|
+ return [
|
|
|
|
+ (groupname, sorted(engines, key=engine_sort_key))
|
|
|
|
+ for groupname, engines in sorted(
|
|
|
|
+ ((name, list(engines)) for name, engines in itertools.groupby(sorted(engines, key=get_group), get_group)),
|
|
|
|
+ key=group_sort_key,
|
|
|
|
+ )
|
|
|
|
+ ]
|