Skip to content

Instantly share code, notes, and snippets.

@dinoocch
Created December 5, 2015 01:59
Show Gist options
  • Save dinoocch/621a676cabd8dbd7f33a to your computer and use it in GitHub Desktop.
Save dinoocch/621a676cabd8dbd7f33a to your computer and use it in GitHub Desktop.
import fileinput
class bcolors:
FAIL = '\033[5;31m'
ENDC = '\033[0m'
BOLD = '\033[1m'
computers = []
current = (None, [])
for line in fileinput.input():
line = line.strip()
if current[1] == "FAILED" and ">>" not in line and "|" not in line:
continue
if current[0] is None:
host = line.split(" | ")[0].split(".")[0]
if "FAILED" in line:
computers.append((host, ["FAILED"]))
current = (None,"FAILED")
else:
current = (host, [])
continue
if line == "":
computers.append(current)
current = (None, [])
continue
current = (current[0], current[1] + [line])
computers.sort(key=lambda computers: computers[0])
maxH = 0
maxC = 0
for c in computers:
maxH = max(maxH, len(c[0]))
for i in c[1]:
maxC = max(len(i), maxC)
maxH += 2
maxC += 2
print " " + "-" * maxH + "|" + "-" * maxC
for c in computers:
print " " + bcolors.BOLD + c[0] + bcolors.ENDC + " " * (maxH-len(c[0])) + "|",
for (i, line) in enumerate(c[1]):
if "FAILED" in line:
print bcolors.FAIL + line + bcolors.ENDC
else:
print line
if i < len(c[1])-1:
print " " * (maxH+1) + "|",
print " " + "-" * maxH + "|" + "-" * maxC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment