u_boot_pylib: Support a fatal level in tout
It is convenient to be able to print a message and exit. Add a new
'fatal' level to support this.
Update some assumptions about the level, so that the tools continue to
work as now.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 81f61e3..1946656 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -777,7 +777,7 @@
if args.cmd in ['ls', 'extract', 'replace', 'tool', 'sign']:
try:
- tout.init(args.verbosity)
+ tout.init(args.verbosity + 1)
if args.cmd == 'replace':
tools.prepare_output_dir(args.outdir, args.preserve)
else:
@@ -835,9 +835,9 @@
args.indir.append(board_pathname)
try:
- tout.init(args.verbosity)
+ tout.init(args.verbosity + 1)
elf.debug = args.debug
- cbfs_util.VERBOSE = args.verbosity > 2
+ cbfs_util.VERBOSE = args.verbosity > tout.NOTICE
state.use_fake_dtb = args.fake_dtb
# Normally we replace the 'u-boot' etype with 'u-boot-expanded', etc.
diff --git a/tools/u_boot_pylib/tout.py b/tools/u_boot_pylib/tout.py
index 37849d1..ca72108 100644
--- a/tools/u_boot_pylib/tout.py
+++ b/tools/u_boot_pylib/tout.py
@@ -9,7 +9,7 @@
from u_boot_pylib import terminal
# Output verbosity levels that we support
-ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6)
+FATAL, ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(7)
in_progress = False
@@ -42,12 +42,12 @@
Returns:
True if it thinks the user is there, and False otherwise
"""
- return stdout_is_tty and verbose > 0
+ return stdout_is_tty and verbose > ERROR
def clear_progress():
"""Clear any active progress message on the terminal."""
global in_progress
- if verbose > 0 and stdout_is_tty and in_progress:
+ if verbose > ERROR and stdout_is_tty and in_progress:
_stdout.write('\r%s\r' % (" " * len (_progress)))
_stdout.flush()
in_progress = False
@@ -60,7 +60,7 @@
warning: True if this is a warning."""
global in_progress
clear_progress()
- if verbose > 0:
+ if verbose > ERROR:
_progress = msg + trailer
if stdout_is_tty:
col = _color.YELLOW if warning else _color.GREEN
@@ -87,6 +87,8 @@
print(msg, file=sys.stderr)
else:
print(msg)
+ if level == FATAL:
+ sys.exit(1)
def do_output(level, msg):
"""Output a message to the terminal.
@@ -98,6 +100,14 @@
"""
_output(level, msg)
+def fatal(msg):
+ """Display an error message and exit
+
+ Args:
+ msg; Message to display.
+ """
+ _output(FATAL, msg, _color.RED)
+
def error(msg):
"""Display an error message
@@ -153,13 +163,13 @@
Args:
msg; Message to display.
"""
- _output(0, msg)
+ _output(ERROR, msg)
def init(_verbose=WARNING, stdout=sys.stdout, allow_colour=True):
"""Initialize a new output object.
Args:
- verbose: Verbosity level (0-4).
+ verbose: Verbosity level (0-6).
stdout: File to use for stdout.
"""
global verbose, _progress, _color, _stdout, stdout_is_tty