OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Crocodile HTML output.""" | 5 """Crocodile HTML output.""" |
6 | 6 |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import time | 9 import time |
10 import xml.dom | 10 import xml.dom |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 def AddSectionHeader(self, table, caption, itemtype, is_file=False): | 186 def AddSectionHeader(self, table, caption, itemtype, is_file=False): |
187 """Adds a section header to the coverage table. | 187 """Adds a section header to the coverage table. |
188 | 188 |
189 Args: | 189 Args: |
190 table: Table to add rows to. | 190 table: Table to add rows to. |
191 caption: Caption for section, if not None. | 191 caption: Caption for section, if not None. |
192 itemtype: Type of items in this section, if not None. | 192 itemtype: Type of items in this section, if not None. |
193 is_file: Are items in this section files? | 193 is_file: Are items in this section files? |
194 """ | 194 """ |
195 | 195 |
196 caption = None | |
John Grabowski
2012/06/26 21:45:29
This is odd. caption is a param, which you force
pshenoy
2012/06/29 18:23:07
Sorry. I did this for testing purpose and forgot t
| |
196 if caption is not None: | 197 if caption is not None: |
197 table.E('tr').E('td', e_class='secdesc', colspan=8).Text(caption) | 198 table.E('tr').E('th', e_class='secdesc', colspan=8).Text(caption) |
198 | 199 |
199 sec_hdr = table.E('tr') | 200 sec_hdr = table.E('tr') |
200 | 201 |
201 if itemtype is not None: | 202 if itemtype is not None: |
202 sec_hdr.E('td', e_class='section').Text(itemtype) | 203 sec_hdr.E('th', e_class='section').Text(itemtype) |
203 | 204 |
204 sec_hdr.E('td', e_class='section').Text('Coverage') | 205 sec_hdr.E('th', e_class='section').Text('Coverage') |
205 sec_hdr.E('td', e_class='section', colspan=3).Text( | 206 sec_hdr.E('th', e_class='section', colspan=3).Text( |
206 'Lines executed / instrumented / missing') | 207 'Lines executed / instrumented / missing') |
207 | 208 |
208 graph = sec_hdr.E('td', e_class='section') | 209 graph = sec_hdr.E('th', e_class='section') |
209 graph.E('span', style='color:#00FF00').Text('exe') | 210 graph.E('span', style='color:#00FF00').Text('exe') |
210 graph.Text(' / ') | 211 graph.Text(' / ') |
211 graph.E('span', style='color:#FFFF00').Text('inst') | 212 graph.E('span', style='color:#FFFF00').Text('inst') |
212 graph.Text(' / ') | 213 graph.Text(' / ') |
213 graph.E('span', style='color:#FF0000').Text('miss') | 214 graph.E('span', style='color:#FF0000').Text('miss') |
214 | 215 |
215 if is_file: | 216 if is_file: |
216 sec_hdr.E('td', e_class='section').Text('Language') | 217 sec_hdr.E('th', e_class='section').Text('Language') |
217 sec_hdr.E('td', e_class='section').Text('Group') | 218 sec_hdr.E('th', e_class='section').Text('Group') |
218 else: | 219 else: |
219 sec_hdr.E('td', e_class='section', colspan=2) | 220 sec_hdr.E('th', e_class='section', colspan=2) |
220 | 221 |
221 def AddItem(self, table, itemname, stats, attrs, link=None): | 222 def AddItem(self, table, itemname, stats, attrs, link=None): |
222 """Adds a bar graph to the element. This is a series of <td> elements. | 223 """Adds a bar graph to the element. This is a series of <td> elements. |
223 | 224 |
224 Args: | 225 Args: |
225 table: Table to add item to. | 226 table: Table to add item to. |
226 itemname: Name of item. | 227 itemname: Name of item. |
227 stats: Stats object. | 228 stats: Stats object. |
228 attrs: Attributes dictionary; if None, no attributes will be printed. | 229 attrs: Attributes dictionary; if None, no attributes will be printed. |
229 link: Destination for itemname hyperlink, if not None. | 230 link: Destination for itemname hyperlink, if not None. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 | 352 |
352 if cov_dir.dirpath: | 353 if cov_dir.dirpath: |
353 title = 'Coverage for ' + cov_dir.dirpath + '/' | 354 title = 'Coverage for ' + cov_dir.dirpath + '/' |
354 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title) | 355 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title) |
355 else: | 356 else: |
356 title = 'Coverage summary' | 357 title = 'Coverage summary' |
357 f = self.CreateHtmlDoc('index.html', title) | 358 f = self.CreateHtmlDoc('index.html', title) |
358 | 359 |
359 body = f.body | 360 body = f.body |
360 | 361 |
362 dirs = [''] + cov_dir.dirpath.split('/') | |
363 num_dirs = len(dirs) | |
364 sort_jsfile = '../' * (num_dirs - 1) + 'sorttable.js' | |
365 script = body.E('script', src=sort_jsfile) | |
366 body.E('/script') | |
367 | |
361 # Write header section | 368 # Write header section |
362 if cov_dir.dirpath: | 369 if cov_dir.dirpath: |
363 self.AddCaptionForSubdir(body, cov_dir.dirpath) | 370 self.AddCaptionForSubdir(body, cov_dir.dirpath) |
364 else: | 371 else: |
365 body.E('h2').Text(title) | 372 body.E('h2').Text(title) |
366 | 373 |
367 table = body.E('table') | 374 table = body.E('table', e_class='sortable') |
368 | 375 table.E('h3').Text('Coverage by Group') |
369 # Coverage by group | 376 # Coverage by group |
370 self.AddSectionHeader(table, 'Coverage by Group', 'Group') | 377 self.AddSectionHeader(table, 'Coverage by Group', 'Group') |
371 | 378 |
372 for group in sorted(cov_dir.stats_by_group): | 379 for group in sorted(cov_dir.stats_by_group): |
373 self.AddItem(table, group, cov_dir.stats_by_group[group], None) | 380 self.AddItem(table, group, cov_dir.stats_by_group[group], None) |
374 | 381 |
382 table = body.E('table', e_class='sortable') | |
383 table.E('h3').Text('Subdirectories') | |
375 # List subdirs | 384 # List subdirs |
376 if cov_dir.subdirs: | 385 if cov_dir.subdirs: |
377 self.AddSectionHeader(table, 'Subdirectories', 'Subdirectory') | 386 self.AddSectionHeader(table, 'Subdirectories', 'Subdirectory') |
378 | 387 |
379 for d in sorted(cov_dir.subdirs): | 388 for d in sorted(cov_dir.subdirs): |
380 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'], | 389 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'], |
381 None, link=d + '/index.html') | 390 None, link=d + '/index.html') |
382 | 391 |
392 table = body.E('table', e_class='sortable') | |
393 table.E('h3').Text('Files in This Directory') | |
383 # List files | 394 # List files |
384 if cov_dir.files: | 395 if cov_dir.files: |
385 self.AddSectionHeader(table, 'Files in This Directory', 'Filename', | 396 self.AddSectionHeader(table, 'Files in This Directory', 'Filename', |
386 is_file=True) | 397 is_file=True) |
387 | 398 |
388 for filename in sorted(cov_dir.files): | 399 for filename in sorted(cov_dir.files): |
389 cov_file = cov_dir.files[filename] | 400 cov_file = cov_dir.files[filename] |
390 self.AddItem(table, filename, cov_file.stats, cov_file.attrs, | 401 self.AddItem(table, filename, cov_file.stats, cov_file.attrs, |
391 link=filename + '.html') | 402 link=filename + '.html') |
392 | 403 |
393 body.E('p', e_class='time').Text(self.time_string) | 404 body.E('p', e_class='time').Text(self.time_string) |
394 f.Write() | 405 f.Write() |
395 | 406 |
396 def WriteRoot(self): | 407 def WriteRoot(self): |
397 """Writes the files in the output root.""" | 408 """Writes the files in the output root.""" |
398 # Find ourselves | 409 # Find ourselves |
399 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0] | 410 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0] |
400 | 411 |
401 # Files to copy into output root | 412 # Files to copy into output root |
402 copy_files = [ | 413 copy_files = [ |
403 'croc.css', | 414 'croc.css', |
415 'sorttable.js', | |
404 ] | 416 ] |
405 | 417 |
406 # Copy files from our directory into the output directory | 418 # Copy files from our directory into the output directory |
407 for copy_file in copy_files: | 419 for copy_file in copy_files: |
408 print ' Copying %s' % copy_file | 420 print ' Copying %s' % copy_file |
409 shutil.copyfile(os.path.join(src_dir, copy_file), | 421 shutil.copyfile(os.path.join(src_dir, copy_file), |
410 os.path.join(self.output_root, copy_file)) | 422 os.path.join(self.output_root, copy_file)) |
411 | 423 |
412 def Write(self): | 424 def Write(self): |
413 """Writes HTML output.""" | 425 """Writes HTML output.""" |
(...skipping 11 matching lines...) Expand all Loading... | |
425 | 437 |
426 # Write this subdir | 438 # Write this subdir |
427 self.WriteSubdir(cov_dir) | 439 self.WriteSubdir(cov_dir) |
428 | 440 |
429 # Write files in this subdir | 441 # Write files in this subdir |
430 for cov_file in cov_dir.files.itervalues(): | 442 for cov_file in cov_dir.files.itervalues(): |
431 self.WriteFile(cov_file) | 443 self.WriteFile(cov_file) |
432 | 444 |
433 # Write files in root directory | 445 # Write files in root directory |
434 self.WriteRoot() | 446 self.WriteRoot() |
OLD | NEW |