|
| 1 | +import subprocess |
| 2 | +import re |
| 3 | + |
| 4 | +# Define ANSI escape codes for colors |
| 5 | +RED = '\033[91m' |
| 6 | +GREEN = '\033[92m' |
| 7 | +GRAY = '\033[90m' |
| 8 | +RESET = '\033[0m' |
| 9 | + |
| 10 | +def filter_make_output(): |
| 11 | + |
| 12 | + # Define multiple patterns to ignore |
| 13 | + ignore_patterns = [ |
| 14 | + "Pygments lexer name 'bw' is not known", |
| 15 | + "Pygments lexer name 'lammps' is not known", |
| 16 | + ".. label:: start_", |
| 17 | + ".. label:: end_", |
| 18 | + "Unknown directive type" |
| 19 | + ] |
| 20 | + |
| 21 | + # Define a pattern to identify warnings (example pattern, adjust as needed) |
| 22 | + warning_pattern = re.compile('|'.join(re.escape(p) for p in ["WARNING:", "ERROR:"])) |
| 23 | + |
| 24 | + # Combine ignore patterns into a single regex pattern |
| 25 | + ignore_pattern = re.compile('|'.join(re.escape(p) for p in ignore_patterns)) |
| 26 | + |
| 27 | + # Run 'make clean' |
| 28 | + subprocess.run(['make', 'clean'], check=True) |
| 29 | + |
| 30 | + # Run 'make html' and capture output |
| 31 | + process = subprocess.Popen(['make', 'html'], |
| 32 | + stdout=subprocess.PIPE, |
| 33 | + stderr=subprocess.STDOUT, text=True) |
| 34 | + |
| 35 | + # Read and filter output |
| 36 | + output_lines = [] |
| 37 | + for line in process.stdout: |
| 38 | + if len(line) > 1: |
| 39 | + if not ignore_pattern.search(line): |
| 40 | + # Determine the color based on whether the line matches the warning pattern |
| 41 | + if warning_pattern.search(line): |
| 42 | + output_lines.append(RED + line + RESET) |
| 43 | + else: |
| 44 | + output_lines.append(GRAY + line + RESET) |
| 45 | + |
| 46 | + # Wait for the process to complete |
| 47 | + process.wait() |
| 48 | + |
| 49 | + # Print the filtered output |
| 50 | + print(''.join(output_lines), end='') |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + filter_make_output() |
0 commit comments