CMS 3D CMS Logo

TablePrint.py
Go to the documentation of this file.
1 import sys
2 from colors import *
3 write = sys.stdout.write
4 
5 def PrettyPrintTable(Headers,Data,ColWidths,WarningCol=[],border='*'):
6  PrintHLine(ColWidths,border)
7  PrintLine(Headers,ColWidths,False,border)
8  PrintHLine(ColWidths,border)
9  if WarningCol==[]:
10  WarningCol=[False]*len(Data)
11  for [line,Warn] in zip(Data,WarningCol):
12  PrintLine(line,ColWidths,Warn,border)
13  PrintHLine(ColWidths,border)
14 
15 def PrintHLine(ColWidths,border): ## writes a horizontal line of the right width
16  #write = sys.stdout.write
17  for entry in ColWidths:
18  write(border)
19  for i in range(entry):
20  write(border)
21  write(border)
22  write('\n')
23 
24 def PrintLine(line,ColWidths,Warn,border):
25  assert Warn in [True,False]
26  try:
27  assert len(line)==len(ColWidths)
28  except:
29  print line
30  print ColWidths
31  raise
32  if Warn:
33  write(bcolors.FAIL)
34  for [width, entry] in zip(ColWidths,line):
35  write(border)
36  try:
37  entry = str(entry)
38  except:
39  print "\n\n\n Weird Data .. Bailing out\n\n"
40  sys.exit(0)
41  for i in range(width):
42  if i==0:
43  write(' ')
44  elif i<len(entry)+1:
45  write(entry[i-1])
46  else:
47  write(' ')
48  write(border)
49  write('\n')
50  write(bcolors.ENDC)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def PrintLine(line, ColWidths, Warn, border)
Definition: TablePrint.py:24
def PrettyPrintTable(Headers, Data, ColWidths, WarningCol=[], border='*')
Definition: TablePrint.py:5
def write(self, setup)
def PrintHLine(ColWidths, border)
Definition: TablePrint.py:15