source: issm/branches/trunk-jpl-damage/scripts/cloc2html.py@ 12168

Last change on this file since 12168 was 12168, checked in by cborstad, 13 years ago

merged trunk-jpl into branch through revision 12167

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: ISO-8859-1 -*-
3#inspired from http://qwiki.stanford.edu/images/d/df/Latex2qwiki.txt
4import sys, re, os
5
6ISSM_DIR=os.getenv('ISSM_DIR');
7if(not ISSM_DIR): raise NameError('ISSM_DIR undefined')
8
9infile = open('temp','r')
10outfile = open('temp.html','w')
11file_text = infile.readlines()
12
13#write header
14outfile.write('<table width="600px" rules=none border=0 bordercolor="#000000" cellpadding="3" align="center" style="border-collapse:collapse;">\n')
15style_r='style="text-align:right;"'
16style_c='style="text-align:center;"'
17style_l='style="text-align:left;"'
18color = ' bgcolor=#7AA9DD ' #dark blue
19color1 = ' bgcolor=#C6E2FF ' #light blue
20color2 = ' bgcolor=#FFFFFF ' #white
21
22count = 0
23toggle = 0
24for 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
81outfile.write('</table>\n')
82
83#close all files
84infile.close()
85outfile.close()
Note: See TracBrowser for help on using the repository browser.