Go to the documentation of this file.00001 import sys
00002 from colors import *
00003 write = sys.stdout.write
00004
00005 def PrettyPrintTable(Headers,Data,ColWidths,WarningCol=[],border='*'):
00006 PrintHLine(ColWidths,border)
00007 PrintLine(Headers,ColWidths,False,border)
00008 PrintHLine(ColWidths,border)
00009 if WarningCol==[]:
00010 WarningCol=[False]*len(Data)
00011 for [line,Warn] in zip(Data,WarningCol):
00012 PrintLine(line,ColWidths,Warn,border)
00013 PrintHLine(ColWidths,border)
00014
00015 def PrintHLine(ColWidths,border):
00016
00017 for entry in ColWidths:
00018 write(border)
00019 for i in range(entry):
00020 write(border)
00021 write(border)
00022 write('\n')
00023
00024 def PrintLine(line,ColWidths,Warn,border):
00025 assert Warn in [True,False]
00026 try:
00027 assert len(line)==len(ColWidths)
00028 except:
00029 print line
00030 print ColWidths
00031 raise
00032 if Warn:
00033 write(bcolors.FAIL)
00034 for [width, entry] in zip(ColWidths,line):
00035 write(border)
00036 try:
00037 entry = str(entry)
00038 except:
00039 print "\n\n\n Weird Data .. Bailing out\n\n"
00040 sys.exit(0)
00041 for i in range(width):
00042 if i==0:
00043 write(' ')
00044 elif i<len(entry)+1:
00045 write(entry[i-1])
00046 else:
00047 write(' ')
00048 write(border)
00049 write('\n')
00050 write(bcolors.ENDC)