Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: generate_test_report.py

Issue 3266004: Move RunCommand, and Info/Warning/Die into common pylib (Closed) Base URL: ssh://git@chromiumos-git//crosutils.git
Patch Set: rebased Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cros_mark_as_stable_unittest.py ('k') | lib/cros_build_lib.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: generate_test_report.py
diff --git a/generate_test_report.py b/generate_test_report.py
index fe05a311a742bd4843f9ec2114a3d13d5417a662..f5d32dbbeae36b7c215dec7c1797f695db0c786e 100755
--- a/generate_test_report.py
+++ b/generate_test_report.py
@@ -17,51 +17,12 @@ import os
import re
import sys
+sys.path.append(os.path.join(os.path.dirname(__file__), 'lib'))
+from cros_build_lib import Color, Die
_STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
-class Color(object):
- """Conditionally wraps text in ANSI color escape sequences."""
- BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
- BOLD = -1
- COLOR_START = '\033[1;%dm'
- BOLD_START = '\033[1m'
- RESET = '\033[0m'
-
- def __init__(self, enabled=True):
- self._enabled = enabled
-
- def Color(self, color, text):
- """Returns text with conditionally added color escape sequences.
-
- Args:
- color: Text color -- one of the color constants defined in this class.
- text: The text to color.
-
- Returns:
- If self._enabled is False, returns the original text. If it's True,
- returns text with color escape sequences based on the value of color.
- """
- if not self._enabled:
- return text
- if color == self.BOLD:
- start = self.BOLD_START
- else:
- start = self.COLOR_START % (color + 30)
- return start + text + self.RESET
-
-
-def Die(message):
- """Emits a red error message and halts execution.
-
- Args:
- message: The message to be emitted before exiting.
- """
- print Color(_STDOUT_IS_TTY).Color(Color.RED, '\nERROR: ' + message)
- sys.exit(1)
-
-
class ReportGenerator(object):
"""Collects and displays data from autoserv results directories.
« no previous file with comments | « cros_mark_as_stable_unittest.py ('k') | lib/cros_build_lib.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698