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