17root = logging.getLogger()
18handler = logging.StreamHandler(sys.stdout)
19for h
in root.handlers:
21root.addHandler(handler)
24if sys.stdout.isatty()
and os.environ.get(
'TERM')
not in [
'dumb',
'unknown']:
26 COLOR_SEQ =
"\033[1;%dm"
28 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = map(
lambda i: COLOR_SEQ % (30 + i), range(8))
33 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE =
"",
"",
"",
"",
"",
"",
"",
""
36stdout = io.TextIOWrapper(
38 open(sys.stdout.fileno(),
'wb', 0),
41stderr = io.TextIOWrapper(
43 open(sys.stderr.fileno(),
'wb', 0),
50 if len(engine_name_list) > 0:
51 for name
in engine_name_list:
52 name = engine_shortcuts.get(name, name)
53 processor = PROCESSORS.get(name)
54 if processor
is not None:
57 stdout.write(f
'{BOLD_SEQ}Engine {name:30}{RESET_SEQ}{RED}Engine does not exist{RESET_SEQ}\n')
59 for name, processor
in searx.search.PROCESSORS.items():
64def run(engine_name_list, verbose):
66 name_checker_list = []
68 stdout.write(f
'{BOLD_SEQ}Engine {name:30}{RESET_SEQ}Checking\n')
69 if not sys.stdout.isatty():
70 stderr.write(f
'{BOLD_SEQ}Engine {name:30}{RESET_SEQ}Checking\n')
73 name_checker_list.append((name, checker))
75 stdout.write(f
'\n== {BOLD_SEQ}Results{RESET_SEQ} ' +
'=' * 70 +
'\n')
76 for name, checker
in name_checker_list:
77 if checker.test_results.successful:
78 stdout.write(f
'{BOLD_SEQ}Engine {name:30}{RESET_SEQ}{GREEN}OK{RESET_SEQ}\n')
80 stdout.write(f
' {"found languages":15}: {" ".join(sorted(list(checker.test_results.languages)))}\n')
82 stdout.write(f
'{BOLD_SEQ}Engine {name:30}{RESET_SEQ}{RESET_SEQ}{RED}Error{RESET_SEQ}')
84 errors = [test_name +
': ' + error
for test_name, error
in checker.test_results]
85 stdout.write(f
'{RED}Error {str(errors)}{RESET_SEQ}\n')
88 stdout.write(f
' {"found languages":15}: {" ".join(sorted(list(checker.test_results.languages)))}\n')
89 for test_name, logs
in checker.test_results.logs.items():
91 log = map(
lambda l: l
if isinstance(l, str)
else repr(l), log)
92 stdout.write(f
' {test_name:15}: {RED}{" ".join(log)}{RESET_SEQ}\n')
97 parser = argparse.ArgumentParser(description=
'Check searx engines.')
100 metavar=
'engine name',
103 help=
'engines name or shortcut list. Empty for all engines.',
110 help=
'Display details about the test results',
113 args = parser.parse_args()
114 run(args.engine_name_list, args.verbose)
117if __name__ ==
'__main__':
run(engine_name_list, verbose)
iter_processor(engine_name_list)
initialize(settings_engines=None, enable_checker=False, check_network=False, enable_metrics=True)