OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 """Parses and displays the contents of one or more autoserv result directories. | 7 """Parses and displays the contents of one or more autoserv result directories. |
8 | 8 |
9 This script parses the contents of one or more autoserv results folders and | 9 This script parses the contents of one or more autoserv results folders and |
10 generates test reports. | 10 generates test reports. |
11 """ | 11 """ |
12 | 12 |
13 | 13 |
14 import glob | 14 import glob |
15 import optparse | 15 import optparse |
16 import os | 16 import os |
17 import re | 17 import re |
18 import sys | 18 import sys |
19 | 19 |
| 20 sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')) |
| 21 from cros_build_lib import Color, Die |
20 | 22 |
21 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() | 23 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
22 | 24 |
23 | 25 |
24 class Color(object): | |
25 """Conditionally wraps text in ANSI color escape sequences.""" | |
26 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) | |
27 BOLD = -1 | |
28 COLOR_START = '\033[1;%dm' | |
29 BOLD_START = '\033[1m' | |
30 RESET = '\033[0m' | |
31 | |
32 def __init__(self, enabled=True): | |
33 self._enabled = enabled | |
34 | |
35 def Color(self, color, text): | |
36 """Returns text with conditionally added color escape sequences. | |
37 | |
38 Args: | |
39 color: Text color -- one of the color constants defined in this class. | |
40 text: The text to color. | |
41 | |
42 Returns: | |
43 If self._enabled is False, returns the original text. If it's True, | |
44 returns text with color escape sequences based on the value of color. | |
45 """ | |
46 if not self._enabled: | |
47 return text | |
48 if color == self.BOLD: | |
49 start = self.BOLD_START | |
50 else: | |
51 start = self.COLOR_START % (color + 30) | |
52 return start + text + self.RESET | |
53 | |
54 | |
55 def Die(message): | |
56 """Emits a red error message and halts execution. | |
57 | |
58 Args: | |
59 message: The message to be emitted before exiting. | |
60 """ | |
61 print Color(_STDOUT_IS_TTY).Color(Color.RED, '\nERROR: ' + message) | |
62 sys.exit(1) | |
63 | |
64 | |
65 class ReportGenerator(object): | 26 class ReportGenerator(object): |
66 """Collects and displays data from autoserv results directories. | 27 """Collects and displays data from autoserv results directories. |
67 | 28 |
68 This class collects status and performance data from one or more autoserv | 29 This class collects status and performance data from one or more autoserv |
69 result directories and generates test reports. | 30 result directories and generates test reports. |
70 """ | 31 """ |
71 | 32 |
72 _KEYVAL_INDENT = 2 | 33 _KEYVAL_INDENT = 2 |
73 | 34 |
74 def __init__(self, options, args): | 35 def __init__(self, options, args): |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 if not args: | 237 if not args: |
277 parser.print_help() | 238 parser.print_help() |
278 Die('no result directories provided') | 239 Die('no result directories provided') |
279 | 240 |
280 generator = ReportGenerator(options, args) | 241 generator = ReportGenerator(options, args) |
281 generator.Run() | 242 generator.Run() |
282 | 243 |
283 | 244 |
284 if __name__ == '__main__': | 245 if __name__ == '__main__': |
285 main() | 246 main() |
OLD | NEW |