| 1 | #!/usr/bin/env python
|
|---|
| 2 | # -*- coding: ISO-8859-1 -*-
|
|---|
| 3 | #inspired from http://qwiki.stanford.edu/images/d/df/Latex2qwiki.txt
|
|---|
| 4 | import sys, re, os
|
|---|
| 5 |
|
|---|
| 6 | ISSM_DIR=os.getenv('ISSM_DIR');
|
|---|
| 7 | if(not ISSM_DIR): raise NameError('ISSM_DIR undefined')
|
|---|
| 8 |
|
|---|
| 9 | infile = open('temp','r')
|
|---|
| 10 | outfile = open('temp.html','w')
|
|---|
| 11 | file_text = infile.readlines()
|
|---|
| 12 |
|
|---|
| 13 | #write header
|
|---|
| 14 | outfile.write('<table width="600px" rules=none border=0 bordercolor="#000000" cellpadding="3" align="center" style="border-collapse:collapse;">\n')
|
|---|
| 15 | style_r='style="text-align:right;"'
|
|---|
| 16 | style_c='style="text-align:center;"'
|
|---|
| 17 | style_l='style="text-align:left;"'
|
|---|
| 18 | color = ' bgcolor=#7AA9DD ' #dark blue
|
|---|
| 19 | color1 = ' bgcolor=#C6E2FF ' #light blue
|
|---|
| 20 | color2 = ' bgcolor=#FFFFFF ' #white
|
|---|
| 21 |
|
|---|
| 22 | count = 0
|
|---|
| 23 | toggle = 0
|
|---|
| 24 | for i in range(len(file_text)):
|
|---|
| 25 |
|
|---|
| 26 | #Get current lines except if first line
|
|---|
| 27 | if(i==0): continue
|
|---|
| 28 | line = file_text[i]
|
|---|
| 29 |
|
|---|
| 30 | pattern=r"----------------"
|
|---|
| 31 | if (re.search(pattern,line)):
|
|---|
| 32 | count+=1
|
|---|
| 33 | continue
|
|---|
| 34 |
|
|---|
| 35 | if(count==1):
|
|---|
| 36 | mystr = '<tr>\n'
|
|---|
| 37 | column = 1
|
|---|
| 38 | for i in line.split():
|
|---|
| 39 | if(column==1): mystr += '<th '+color+style_l+'>'+i+'</th>'; column+=1
|
|---|
| 40 | else: mystr += '<th '+color+style_r+'>'+i+'</th>'
|
|---|
| 41 | mystr += '<th '+color+style_r+'>Total</th>\n</th>\n'
|
|---|
| 42 | elif(count==2):
|
|---|
| 43 | total = 0
|
|---|
| 44 | column = 1
|
|---|
| 45 | if(toggle): mystr = '<tr>\n<th '+color1+style_l+'>'
|
|---|
| 46 | else: mystr = '<tr>\n<th '+color2+style_l+'>'
|
|---|
| 47 | for i in line.split():
|
|---|
| 48 | if(not i.isdigit()):
|
|---|
| 49 | mystr += ' '+i+' '
|
|---|
| 50 | else:
|
|---|
| 51 | if(column==1): mystr += '</th>'
|
|---|
| 52 | if(column>=2): total += int(i)
|
|---|
| 53 | if(toggle): mystr += '<td '+color1+style_r+'>'+i+'</td>'
|
|---|
| 54 | else: mystr += '<td '+color2+style_r+'>'+i+'</td>'
|
|---|
| 55 | column += 1
|
|---|
| 56 | if(toggle): mystr += '<td '+color1+style_r+'>'+str(total)+'</td>\n</tr>\n'
|
|---|
| 57 | else: mystr += '<td '+color2+style_r+'>'+str(total)+'</td>\n</tr>\n'
|
|---|
| 58 | toggle = 1 - toggle
|
|---|
| 59 | elif(count==3):
|
|---|
| 60 | total = 0
|
|---|
| 61 | column = 1
|
|---|
| 62 | if(toggle): mystr = '<tr>\n<th '+color1+style_l+'>'
|
|---|
| 63 | else: mystr = '<tr>\n<th '+color2+style_l+'>'
|
|---|
| 64 | for i in line.split():
|
|---|
| 65 | if(not i.isdigit()):
|
|---|
| 66 | mystr += ' '+i+' '
|
|---|
| 67 | else:
|
|---|
| 68 | if(column==1): mystr += '</th>'
|
|---|
| 69 | if(column>=2): total += int(i)
|
|---|
| 70 | if(toggle): mystr += '<td '+color1+style_r+'>'+i+'</td>'
|
|---|
| 71 | else: mystr += '<td '+color2+style_r+'>'+i+'</td>'
|
|---|
| 72 | column += 1
|
|---|
| 73 | if(toggle): mystr += '<td '+color1+style_r+'>'+str(total)+'</td>\n</tr>\n'
|
|---|
| 74 | else: mystr += '<td '+color2+style_r+'>'+str(total)+'</td>\n</tr>\n'
|
|---|
| 75 | else:
|
|---|
| 76 | continue
|
|---|
| 77 |
|
|---|
| 78 | outfile.write(mystr)
|
|---|
| 79 |
|
|---|
| 80 | #write header
|
|---|
| 81 | outfile.write('</table>\n')
|
|---|
| 82 |
|
|---|
| 83 | #close all files
|
|---|
| 84 | infile.close()
|
|---|
| 85 | outfile.close()
|
|---|