Home | History | Annotate | Download | only in build
      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 
     19 import fileinput
     20 import re
     21 import sys
     22 
     23 RED = "\033[31m"
     24 YELLOW = "\033[33m"
     25 RESET = "\033[0m"
     26 
     27 ERROR = re.compile(r"^Error:")
     28 WARNING = re.compile(r"^Warning:")
     29 STARTS_WITH_WS = re.compile(r"^\s")
     30 
     31 for 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,
     41 print RESET
     42 
     43