CMS 3D CMS Logo

Functions | Variables

TablePrint Namespace Reference

Functions

def PrettyPrintTable
def PrintHLine
def PrintLine

Variables

 write = sys.stdout.write

Function Documentation

def TablePrint::PrettyPrintTable (   Headers,
  Data,
  ColWidths,
  WarningCol = [],
  border = '*' 
)

Definition at line 5 of file TablePrint.py.

00006                                                                      :
00007    PrintHLine(ColWidths,border)
00008    PrintLine(Headers,ColWidths,False,border)
00009    PrintHLine(ColWidths,border)
00010    if WarningCol==[]:
00011       WarningCol=[False]*len(Data)
00012    for [line,Warn] in zip(Data,WarningCol):
00013        PrintLine(line,ColWidths,Warn,border)
00014    PrintHLine(ColWidths,border)

def TablePrint::PrintHLine (   ColWidths,
  border 
)

Definition at line 15 of file TablePrint.py.

00015                                 : ## writes a horizontal line of the right width
00016     #write = sys.stdout.write
00017     for entry in ColWidths:
00018         write(border)
00019         for i in range(entry):
00020             write(border)
00021     write(border)
00022     write('\n')
00023 
def TablePrint::PrintLine (   line,
  ColWidths,
  Warn,
  border 
)

Definition at line 24 of file TablePrint.py.

00025                                          :
00026     assert Warn in [True,False]
00027     try:
00028        assert len(line)==len(ColWidths)
00029     except:
00030        print line
00031        print ColWidths
00032        raise
00033     if Warn:
00034         write(bcolors.FAIL)
00035     for [width, entry] in zip(ColWidths,line):
00036         write(border)
00037         try:
00038             entry = str(entry)
00039         except:
00040             print "\n\n\n Weird Data .. Bailing out\n\n"
00041             sys.exit(0)
00042         for i in range(width):
00043             if i==0:
00044                 write(' ')
00045             elif i<len(entry)+1:
00046                 write(entry[i-1])
00047             else:
00048                 write(' ')
00049     write(border)
00050     write('\n')
00051     write(bcolors.ENDC)

Variable Documentation

TablePrint::write = sys.stdout.write