OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2003-2006 Sylvain Thenault (thenault@gmail.com). |
| 2 # Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE). |
| 3 # This program is free software; you can redistribute it and/or modify it under |
| 4 # the terms of the GNU General Public License as published by the Free Software |
| 5 # Foundation; either version 2 of the License, or (at your option) any later |
| 6 # version. |
| 7 # |
| 8 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 11 # |
| 12 # You should have received a copy of the GNU General Public License along with |
| 13 # this program; if not, write to the Free Software Foundation, Inc., |
| 14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 15 """HTML reporter""" |
| 16 |
| 17 import sys |
| 18 from cgi import escape |
| 19 |
| 20 from logilab.common.ureports import HTMLWriter, Section, Table |
| 21 |
| 22 from pylint.interfaces import IReporter |
| 23 from pylint.reporters import BaseReporter |
| 24 |
| 25 |
| 26 class HTMLReporter(BaseReporter): |
| 27 """report messages and layouts in HTML""" |
| 28 |
| 29 __implements__ = IReporter |
| 30 extension = 'html' |
| 31 |
| 32 def __init__(self, output=sys.stdout): |
| 33 BaseReporter.__init__(self, output) |
| 34 self.msgs = [] |
| 35 |
| 36 def add_message(self, msg_id, location, msg): |
| 37 """manage message of different type and in the context of path""" |
| 38 module, obj, line, col_offset = location[1:] |
| 39 if self.include_ids: |
| 40 sigle = msg_id |
| 41 else: |
| 42 sigle = msg_id[0] |
| 43 self.msgs += [sigle, module, obj, str(line), str(col_offset), escape(msg
)] |
| 44 |
| 45 def set_output(self, output=None): |
| 46 """set output stream |
| 47 |
| 48 messages buffered for old output is processed first""" |
| 49 if self.out and self.msgs: |
| 50 self._display(Section()) |
| 51 BaseReporter.set_output(self, output) |
| 52 |
| 53 def _display(self, layout): |
| 54 """launch layouts display |
| 55 |
| 56 overridden from BaseReporter to add insert the messages section |
| 57 (in add_message, message is not displayed, just collected so it |
| 58 can be displayed in an html table) |
| 59 """ |
| 60 if self.msgs: |
| 61 # add stored messages to the layout |
| 62 msgs = ['type', 'module', 'object', 'line', 'col_offset', 'message'] |
| 63 msgs += self.msgs |
| 64 sect = Section('Messages') |
| 65 layout.append(sect) |
| 66 sect.append(Table(cols=6, children=msgs, rheaders=1)) |
| 67 self.msgs = [] |
| 68 HTMLWriter().format(layout, self.out) |
| 69 |
OLD | NEW |