Fixed #23686 -- Tweak color output of the system check framework.
Thanks Tim Graham for the review.
This commit is contained in:
parent
e55fc60f81
commit
bdb4118b1a
|
@ -38,6 +38,13 @@ class CommandError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SystemCheckError(CommandError):
|
||||||
|
"""
|
||||||
|
The system check framework detected unrecoverable errors.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CommandParser(ArgumentParser):
|
class CommandParser(ArgumentParser):
|
||||||
"""
|
"""
|
||||||
Customized ArgumentParser class to improve some error messages and prevent
|
Customized ArgumentParser class to improve some error messages and prevent
|
||||||
|
@ -385,6 +392,10 @@ class BaseCommand(object):
|
||||||
if options.traceback or not isinstance(e, CommandError):
|
if options.traceback or not isinstance(e, CommandError):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# SystemCheckError takes care of its own formatting.
|
||||||
|
if isinstance(e, SystemCheckError):
|
||||||
|
self.stderr.write(str(e), lambda x: x)
|
||||||
|
else:
|
||||||
self.stderr.write('%s: %s' % (e.__class__.__name__, e))
|
self.stderr.write('%s: %s' % (e.__class__.__name__, e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -468,7 +479,7 @@ class BaseCommand(object):
|
||||||
include_deployment_checks=include_deployment_checks,
|
include_deployment_checks=include_deployment_checks,
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = ""
|
header, body, footer = "", "", ""
|
||||||
visible_issue_count = 0 # excludes silenced warnings
|
visible_issue_count = 0 # excludes silenced warnings
|
||||||
|
|
||||||
if all_issues:
|
if all_issues:
|
||||||
|
@ -489,19 +500,20 @@ class BaseCommand(object):
|
||||||
if issues:
|
if issues:
|
||||||
visible_issue_count += len(issues)
|
visible_issue_count += len(issues)
|
||||||
formatted = (
|
formatted = (
|
||||||
color_style().ERROR(force_str(e))
|
self.style.ERROR(force_str(e))
|
||||||
if e.is_serious()
|
if e.is_serious()
|
||||||
else color_style().WARNING(force_str(e))
|
else self.style.WARNING(force_str(e))
|
||||||
for e in issues)
|
for e in issues)
|
||||||
formatted = "\n".join(sorted(formatted))
|
formatted = "\n".join(sorted(formatted))
|
||||||
msg += '\n%s:\n%s\n' % (group_name, formatted)
|
body += '\n%s:\n%s\n' % (group_name, formatted)
|
||||||
if msg:
|
|
||||||
msg = "System check identified some issues:\n%s" % msg
|
if visible_issue_count:
|
||||||
|
header = "System check identified some issues:\n"
|
||||||
|
|
||||||
if display_num_errors:
|
if display_num_errors:
|
||||||
if msg:
|
if visible_issue_count:
|
||||||
msg += '\n'
|
footer += '\n'
|
||||||
msg += "System check identified %s (%s silenced)." % (
|
footer += "System check identified %s (%s silenced)." % (
|
||||||
"no issues" if visible_issue_count == 0 else
|
"no issues" if visible_issue_count == 0 else
|
||||||
"1 issue" if visible_issue_count == 1 else
|
"1 issue" if visible_issue_count == 1 else
|
||||||
"%s issues" % visible_issue_count,
|
"%s issues" % visible_issue_count,
|
||||||
|
@ -509,10 +521,15 @@ class BaseCommand(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
if any(e.is_serious() and not e.is_silenced() for e in all_issues):
|
if any(e.is_serious() and not e.is_silenced() for e in all_issues):
|
||||||
raise CommandError(msg)
|
msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer
|
||||||
elif msg and visible_issue_count:
|
raise SystemCheckError(msg)
|
||||||
self.stderr.write(msg)
|
else:
|
||||||
elif msg:
|
msg = header + body + footer
|
||||||
|
|
||||||
|
if msg:
|
||||||
|
if visible_issue_count:
|
||||||
|
self.stderr.write(msg, lambda x: x)
|
||||||
|
else:
|
||||||
self.stdout.write(msg)
|
self.stdout.write(msg)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
@ -1162,7 +1162,7 @@ class ManageCheck(AdminScriptTestCase):
|
||||||
args = ['check']
|
args = ['check']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
expected_err = (
|
expected_err = (
|
||||||
"CommandError: System check identified some issues:\n"
|
"SystemCheckError: System check identified some issues:\n"
|
||||||
"\n"
|
"\n"
|
||||||
"ERRORS:\n"
|
"ERRORS:\n"
|
||||||
"?: An error\n"
|
"?: An error\n"
|
||||||
|
|
Loading…
Reference in New Issue