]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/alog2html
Added new package: dosfstools.
[ipfire-3.x.git] / tools / alog2html
1 #!/usr/bin/python
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21 # Author: 08-2008 - Heiner Schmeling #
22 ###############################################################################
23
24 ### define variables
25 HEADER='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
26 "http://www.w3.org/TR/html4/loose.dtd">
27 <html>
28 <head>
29 <title>Beschreibung der Seite</title>
30 <style type="text/css">
31 * {
32 font-size:14px;
33 }
34
35 .black{color:#000000;}
36 .red{color:#ff0000;}
37 .green{color:#00ff00;}
38 .yellow{color:#ff0000;}
39 .blue{color:#0000ff;}
40 .magenta{color:#ff0000;}
41 .cyan{color:#ff0000;}
42 .white{color:#ffffff;}
43 .ul {text-decoration:underline}
44 .b {font-weight:bold}
45
46 .bggray {background-color:#eeeeee;}
47
48 .tal {text-align:left;}
49 .tar {text-align:right;}
50 .tac {text-align:center;}
51 </style>
52 </head>
53 <body>
54 <TABLE BORDER="0" cellspacing="0">
55 '''
56
57 FOOTER='''</TABLE>
58 </body>
59 </html>
60 '''
61
62 sESC='\x1b['
63 sBEL='\x07'
64 sSpace='\x20'
65 lineNr = 0 # Counter for readed lines
66 hg_colStr='' # define variable for Backgroundcolor
67
68 ### definition for lots of variable 'linelist'
69 ## linelist=[[pos,fgcolor,hgcolor,bold,text]]
70 # pos = current Cursorposition
71 # fgcolor = Vordergrund Farbe
72 # hgcolor = Hintergrund Farbe
73 # bold = ist Bold aktiv (0/1)
74 # text = Text
75
76
77 print HEADER
78
79 ### beginning
80 while 1:
81 try:
82 line = raw_input() # read from standard device
83 lineNr += 1 # increment linecounter
84 except EOFError:
85 break # break/exit is "End Of File"
86
87
88 if len(line)>0 and line[-1]=='\x0d' : # evtl. vorhandenen '/r' entfernen
89 line=line[:-1]
90 line=line.replace(sBEL,sSpace).strip()
91
92 isBoldOn = 0 # is Bold active ?
93 linelist = [] # define emty list
94
95 new_String = ''
96 new_line_split = []
97 colStr = ""
98 BoldOn=""
99 pos = 0
100
101 line_split = line.split(sESC) # Split readed line with sESC separator
102 cnt_line_split = len(line_split) # len/count of line_split
103
104 ### decode escape sequences
105 for splitNr in range(0,cnt_line_split):
106
107 lsStr = line_split[splitNr] # string of array (line split string)
108
109 num_cnt = 0 # count for numbers
110
111 if splitNr == 0 : # split nr 0 have not EscapeSequences
112 new_String=line_split[0]
113 if len(lsStr)>0:
114 test_ = [pos,colStr,hg_colStr,BoldOn,lsStr]
115 linelist.append(test_)
116 pos +=len(lsStr)
117 else:
118 lsStr_len = len(lsStr) # Ueberpruefung der Teilstring-Laenge
119 if lsStr_len > 5 :
120 lsStr_len = 5
121
122 for x1 in range(0,lsStr_len):
123 found=''
124 zeichen=lsStr[x1]
125 if zeichen == ";" :
126 if num_cnt == 1 :
127 if lsStr[x1-1] == '0' and isBoldOn == 1:
128 isBoldOn = 0
129 BoldOn=""
130 elif lsStr[x1-1] == '1' and isBoldOn == 0:
131 isBoldOn = 1
132 BoldOn=" b"
133 else:
134 print 'ERROR: BOLD nicht 0 oder 1'
135 else:
136 print 'ERROR: >2 Zahlen in fuer BOLD'
137 num_cnt = 0 # reset count for numbers
138 continue
139 elif zeichen.isdigit() :
140 num_cnt += 1
141 continue
142 elif zeichen == 'J' :
143 found='J'
144 break
145 elif zeichen == 'H' :
146 found='H'
147 break
148 elif zeichen == 'G' :
149 found='G'
150 pos = int(lsStr[x1-num_cnt:x1])
151 break
152 elif zeichen == 'm' :
153 found='m'
154 color = lsStr[x1-1]
155 if color == '0' :
156 colStr='white'
157 elif color == '1' :
158 colStr='red'
159 elif color == '2' :
160 colStr='green'
161 elif color == '3' :
162 colStr='yellow'
163 elif color == '4' :
164 colStr='blue'
165 elif color == '5' :
166 colStr='magenta'
167 elif color == '6' :
168 colStr='cyan'
169 elif color == '7' :
170 colStr='black'
171 elif color == '8' :
172 colStr='888'
173 elif color == '9' :
174 colStr='' # reset Color
175 break
176
177 if found <> '' :
178 if colStr<>'' or BoldOn<>'' :
179 new_String +='<span class="%s%s">%s</span>' % (colStr,BoldOn,lsStr[x1+1:])
180 else:
181 new_String +=lsStr[x1+1:]
182
183 _lsStr=lsStr[x1+1:]
184 if _lsStr<>'' :
185 if not _lsStr.isspace() :
186 test_ = [pos,colStr,hg_colStr,BoldOn,_lsStr]
187 linelist.append(test_)
188 pos +=len(_lsStr)
189 new_line_split.append(_lsStr)
190
191 ### begin table <tr>
192 if lineNr % 2 != 0 :
193 print '<tr class="bggray">'
194 else :
195 print '<tr>'
196
197 ### first table entry 'linecounter'
198 print '\t<td class="tar">%d: </td>' % (lineNr)
199
200 ### other table entrys
201 linelist_cnt=len(linelist)
202 if linelist_cnt > 0 :
203
204 cnt_bracket=0 # Count string '[' for Tab's
205 for cnt in range(0,linelist_cnt):
206 cnt_bracket+=linelist[cnt][4].count('[')
207
208 if linelist[0][4].count('*') == 3 and linelist_cnt == 5 : # Find 3 x '*'
209 for cnt in range(0,13):
210 if cnt == 0 : print '\t<td class="b">%s</td>' % (linelist[0][4])
211 elif cnt == 2 : print '\t<td class="tac b">%s</td>' % (linelist[1][4])
212 elif cnt == 5 : print '\t<td class="tac b">%s</td>' % (linelist[2][4])
213 elif cnt == 8 : print '\t<td class="tac b">%s</td>' % (linelist[3][4])
214 elif cnt == 11 : print '\t<td class="tac b">%s</td>' % (linelist[4][4])
215 else : print '\t<td></td>'
216 else :
217 cnt_tabs = linelist_cnt-(cnt_bracket*3)
218 for cnt in range(0,cnt_tabs) :
219 if cnt == 0 :
220 if linelist[cnt][1] or linelist[cnt][2] :
221 print '\t<td class="'+linelist[cnt][1]+linelist[cnt][2]+'">',
222 else :
223 print '\t<td>',
224 if linelist[cnt][3] :
225 print '<b>'+linelist[cnt][4]+'</b>',
226 else :
227 print linelist[cnt][4],
228 print '</td>'
229
230 if linelist[0][0] == 0 :
231 start = 1
232 else :
233 start = 0
234 for cnt in range(start, 13-cnt_bracket*3 ) : # Fill empty tabs
235 print '\t<td></td>'
236
237 for cnt in range(cnt_tabs,linelist_cnt) :
238 try:
239 if linelist[cnt][1] or linelist[cnt][2] or linelist[cnt][3] :
240 print '\t<td class="tar '+linelist[cnt][1]+linelist[cnt][2]+linelist[cnt][3]+'">',
241 else :
242 print '\t<td>',
243 print linelist[cnt][4]+'</td>'
244 except IndexError:
245 print '<p class="red b">traceerror line %s in modul alog2html : <span class="blue">%s</span></p>' % (lineNr, line)
246 break
247
248 else :
249 for cnt in range(0, 13) : # Fill empty tabs
250 print '\t<td></td>'
251
252 ### close table </tr>
253 print '</tr>'
254
255 print FOOTER