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