• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2#  Copyright (C) 2015 The Android Open Source Project
3#
4#  Licensed under the Apache License, Version 2.0 (the "License");
5#  you may not use this file except in compliance with the License.
6#  You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#  Unless required by applicable law or agreed to in writing, software
11#  distributed under the License is distributed on an "AS IS" BASIS,
12#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#  See the License for the specific language governing permissions and
14#  limitations under the License.
15#
16# Given an input stream look for Error: and Warning: lines and colorize those to
17# the output
18
19import fileinput
20import re
21import sys
22
23RED = "\033[31m"
24YELLOW = "\033[33m"
25RESET = "\033[0m"
26
27ERROR = re.compile(r"^Error:")
28WARNING = re.compile(r"^Warning:")
29STARTS_WITH_WS = re.compile(r"^\s")
30
31for line in fileinput.input():
32  if ERROR.match(line):
33    print RED + line,
34  elif WARNING.match(line):
35    print YELLOW + line,
36  elif STARTS_WITH_WS.match(line):
37    # If the line starts with a space use the same coloring as the previous line
38    print line,
39  else:
40    print RESET + line,
41print RESET
42
43