Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:48

0001 from __future__ import print_function
0002 from __future__ import absolute_import
0003 import sys
0004 from .colors import *
0005 write = sys.stdout.write
0006 
0007 def PrettyPrintTable(Headers,Data,ColWidths,WarningCol=[],border='*'):
0008    PrintHLine(ColWidths,border)
0009    PrintLine(Headers,ColWidths,False,border)
0010    PrintHLine(ColWidths,border)
0011    if WarningCol==[]:
0012       WarningCol=[False]*len(Data)
0013    for [line,Warn] in zip(Data,WarningCol):
0014        PrintLine(line,ColWidths,Warn,border)
0015    PrintHLine(ColWidths,border)
0016 
0017 def PrintHLine(ColWidths,border): ## writes a horizontal line of the right width
0018     #write = sys.stdout.write
0019     for entry in ColWidths:
0020         write(border)
0021         for i in range(entry):
0022             write(border)
0023     write(border)
0024     write('\n')
0025 
0026 def PrintLine(line,ColWidths,Warn,border):
0027     assert Warn in [True,False]
0028     try:
0029        assert len(line)==len(ColWidths)
0030     except:
0031        print(line)
0032        print(ColWidths)
0033        raise
0034     if Warn:
0035         write(bcolors.FAIL)
0036     for [width, entry] in zip(ColWidths,line):
0037         write(border)
0038         try:
0039             entry = str(entry)
0040         except:
0041             print("\n\n\n Weird Data .. Bailing out\n\n")
0042             sys.exit(0)
0043         for i in range(width):
0044             if i==0:
0045                 write(' ')
0046             elif i<len(entry)+1:
0047                 write(entry[i-1])
0048             else:
0049                 write(' ')
0050     write(border)
0051     write('\n')
0052     write(bcolors.ENDC)