import sys import re import termcolor PROTO_COLORS = { "tcp":"white", "rdma":"yellow" } PROTO = sys.argv[1] VERS_COLORS = { "v3":"red", "v4.0":"green", "v4.1":"blue", "v4.2":"yellow" } VERS = f"v{sys.argv[2]}" COLOR = VERS_COLORS[VERS] prefix = termcolor.colored("[", "white", attrs=["bold"]) prefix += termcolor.colored(PROTO.rjust(4), PROTO_COLORS[PROTO], attrs=["dark"]) prefix += termcolor.colored(",", "white", attrs=["bold"]) prefix += termcolor.colored(VERS.ljust(4), COLOR, attrs=["bold"]) prefix += termcolor.colored("] ", "white", attrs=["bold"]) CONFIG = [ ] def add_config(line): [ key, val ] = [ s.strip() for s in re.split("--", line) ] if key == "MKFS_OPTIONS": return elif key == "MOUNT_OPTIONS" and val[:2] != "-o": return parts = [ prefix ] parts.append(termcolor.colored(key.ljust(14), COLOR, attrs=["bold"])) parts.append(termcolor.colored("-- ", "white", attrs=["dark"])) parts.append(termcolor.colored(val, "white", attrs=["bold"])) CONFIG.append("".join(parts)) def print_config(): if len(CONFIG) > 0: print("\n".join(CONFIG), end="\n\n") CONFIG.clear() def print_test(match): parts = [ prefix ] parts.append(termcolor.colored(match.group(1), COLOR, attrs=["bold"])) if m := re.match("(\[not run\])(.*?\n)", match.group(2)): return parts.append(termcolor.colored(m.group(1), "yellow")) parts.append(termcolor.colored(m.group(2), "white", attrs=["bold"])) elif m := re.match("(\d+s)( ... +)(\d+s\n)", match.group(2)): parts.append(termcolor.colored(m.group(1), "green")) parts.append(termcolor.colored(m.group(2), "white", attrs=["dark"])) parts.append(termcolor.colored(m.group(3), "green")) elif re.match("\d+s\n", match.group(2)): parts.append(termcolor.colored(match.group(2), "green")) else: # Test failed line = re.sub("\]-", "\] -", match.group(2)) parts.append(termcolor.colored(line, "magenta", attrs=["bold"])) print("".join(parts), end="") def print_diff(line): print(prefix, end="") if re.match(" +@@.*?@@\n", line): termcolor.cprint(line, color="yellow", attrs=["dark"], end="") elif re.match(" +-", line): termcolor.cprint(line, color="magenta", attrs=["dark"], end="") elif re.match(" +\+", line): termcolor.cprint(line, color="cyan", attrs=["dark"], end="") elif re.match(" +\(Run", line): termcolor.cprint(line, color="magenta", attrs=["bold"], end="") else: termcolor.cprint(line, color="white", attrs=["dark"], end="") for line in sys.stdin: if line == "\n": print_config() elif re.match("^[A-Z_]+[ ]+-- .*?\n", line): if match := re.match("(^PLATFORM(.*?)PREEMPT)(.*?\n)", line): add_config(match.group(1)) line = f"COMPILED -- {match.group(3)}" add_config(line) elif match := re.match("(^[a-z]+/[\d]+[ | ]+)(.*?\n)", line): print_test(match) elif match := re.match("^ (.*?)\n", line): print_diff(line) else: #pass print(prefix, end="") print(line, end="")