run_checks: Colorize exit status

This commit is contained in:
Florian Bruhin 2014-08-14 20:58:39 +02:00
parent 0f1c819b89
commit 7512d766d4

View File

@ -276,6 +276,7 @@ def main():
"""Main entry point.""" """Main entry point."""
col.init() col.init()
exit_status = OrderedDict() exit_status = OrderedDict()
exit_status_bool = {}
parser = argparse.ArgumentParser(description='Run various checkers.') parser = argparse.ArgumentParser(description='Run various checkers.')
parser.add_argument('-s', '--setup', help="Run additional setup checks", parser.add_argument('-s', '--setup', help="Run additional setup checks",
action='store_true') action='store_true')
@ -298,20 +299,29 @@ def main():
col.Fore.RESET)) col.Fore.RESET))
if _checker_enabled(args, group, name): if _checker_enabled(args, group, name):
status = func() status = func()
exit_status['{}_{}'.format(group, name)] = status key = '{}_{}'.format(group, name)
exit_status[key] = status
if name == 'flake8':
# pyflakes uses True for errors and False for ok.
exit_status_bool[key] = not status
elif isinstance(status, bool):
exit_status_bool[key] = status
else:
# sys.exit(0) means no problems -> True, anything != 0
# means problems.
exit_status_bool[key] = (status == 0)
else: else:
print("{}Checker disabled.{}".format( print("{}Checker disabled.{}".format(
col.Fore.BLUE, col.Fore.RESET)) col.Fore.BLUE, col.Fore.RESET))
print() print()
print("{}Exit status values:{}".format(col.Fore.YELLOW, col.Fore.RESET)) print("{}Exit status values:{}".format(col.Fore.YELLOW, col.Fore.RESET))
for (k, v) in exit_status.items(): for (k, v) in exit_status.items():
if v is True or (not isinstance(v, bool) and v == 0): ok = exit_status_bool[k]
color = col.Fore.GREEN color = col.Fore.GREEN if ok else col.Fore.RED
else: print('{} {} - {} ({}){}'.format(color, k, 'ok' if ok else 'FAIL',
color = col.Fore.RED v, col.Fore.RESET))
print('{} {} - {}{}'.format(color, k, v, col.Fore.RESET))
if all(val in (True, 0) for val in exit_status): if all(exit_status_bool):
return 0 return 0
else: else:
return 1 return 1