+# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2016 Google, Inc
#
-# SPDX-License-Identifier: GPL-2.0+
-#
# Terminal output logging.
#
import terminal
# Output verbosity levels that we support
-ERROR = 0
-WARNING = 1
-NOTICE = 2
-INFO = 3
-DEBUG = 4
+ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(6)
+
+in_progress = False
"""
This class handles output of progress and other useful information
def ClearProgress():
"""Clear any active progress message on the terminal."""
- if verbose > 0 and stdout_is_tty:
+ global in_progress
+ if verbose > 0 and stdout_is_tty and in_progress:
_stdout.write('\r%s\r' % (" " * len (_progress)))
_stdout.flush()
+ in_progress = False
def Progress(msg, warning=False, trailer='...'):
"""Display progress information.
Args:
msg: Message to display.
warning: True if this is a warning."""
+ global in_progress
ClearProgress()
if verbose > 0:
_progress = msg + trailer
col = _color.YELLOW if warning else _color.GREEN
_stdout.write('\r' + _color.Color(col, _progress))
_stdout.flush()
+ in_progress = True
else:
_stdout.write(_progress + '\n')
ClearProgress()
if color:
msg = _color.Color(color, msg)
- _stdout.write(msg + '\n')
+ print(msg)
def DoOutput(level, msg):
"""Output a message to the terminal.
Args:
msg; Message to display.
"""
- _Output(0, msg, _color.RED)
+ _Output(ERROR, msg, _color.RED)
def Warning(msg):
"""Display a warning message
Args:
msg; Message to display.
"""
- _Output(1, msg, _color.YELLOW)
+ _Output(WARNING, msg, _color.YELLOW)
def Notice(msg):
"""Display an important infomation message
Args:
msg; Message to display.
"""
- _Output(2, msg)
+ _Output(NOTICE, msg)
def Info(msg):
"""Display an infomation message
Args:
msg; Message to display.
"""
- _Output(3, msg)
+ _Output(INFO, msg)
+
+def Detail(msg):
+ """Display a detailed message
+
+ Args:
+ msg; Message to display.
+ """
+ _Output(DETAIL, msg)
def Debug(msg):
"""Display a debug message
Args:
msg; Message to display.
"""
- _Output(4, msg)
+ _Output(DEBUG, msg)
def UserOutput(msg):
"""Display a message regardless of the current output level.