summaryrefslogtreecommitdiff
path: root/reporters
diff options
context:
space:
mode:
authorroot <devnull@localhost>2006-04-26 10:48:09 +0000
committerroot <devnull@localhost>2006-04-26 10:48:09 +0000
commiteea76f1da01a33dec2afc42119e001e4350aaea2 (patch)
tree3bb03a16daa8c780bf60c622dc288eb01cfca145 /reporters
downloadpylint-eea76f1da01a33dec2afc42119e001e4350aaea2.tar.gz
forget the past.
forget the past.
Diffstat (limited to 'reporters')
-rw-r--r--reporters/__init__.py67
-rw-r--r--reporters/html.py64
-rw-r--r--reporters/text.py151
3 files changed, 282 insertions, 0 deletions
diff --git a/reporters/__init__.py b/reporters/__init__.py
new file mode 100644
index 0000000..54d14bd
--- /dev/null
+++ b/reporters/__init__.py
@@ -0,0 +1,67 @@
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+"""utilities methods and classes for reporters
+
+ Copyright (c) 2000-2003 LOGILAB S.A. (Paris, FRANCE).
+ http://www.logilab.fr/ -- mailto:contact@logilab.fr
+"""
+
+__revision__ = "$Id: __init__.py,v 1.14 2005-01-20 15:12:56 syt Exp $"
+
+import sys
+
+CMPS = ['=', '-', '+']
+
+def diff_string(old, new):
+ """given a old and new int value, return a string representing the
+ difference
+ """
+ diff = abs(old - new)
+ diff_str = "%s%s" % (CMPS[cmp(old, new)], diff and ('%.2f' % diff) or '')
+ return diff_str
+
+
+class EmptyReport(Exception):
+ """raised when a report is empty and so should not be displayed"""
+
+class BaseReporter:
+ """base class for reporters"""
+
+ extension = ''
+
+ def __init__(self, output=sys.stdout):
+ self.linter = None
+ self.include_ids = None
+ self.section = 0
+ self.out = None
+ self.set_output(output)
+
+ def set_output(self, output):
+ """set output stream"""
+ self.out = output
+
+ def writeln(self, string=''):
+ """write a line in the output buffer"""
+ print >> self.out, string
+
+ def display_results(self, layout):
+ """display results encapsulated in the layout tree"""
+ self.section = 0
+ if self.include_ids and hasattr(layout, 'report_id'):
+ layout.children[0].children[0].data += ' (%s)' % layout.report_id
+ self._display(layout)
+
+ def _display(self, layout):
+ """display the layout"""
+ raise NotImplementedError()
+
diff --git a/reporters/html.py b/reporters/html.py
new file mode 100644
index 0000000..625c447
--- /dev/null
+++ b/reporters/html.py
@@ -0,0 +1,64 @@
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+""" Copyright (c) 2002-2006 LOGILAB S.A. (Paris, FRANCE).
+ http://www.logilab.fr/ -- mailto:contact@logilab.fr
+
+HTML reporter
+"""
+
+__revision__ = "$Id: html.py,v 1.14 2006-03-08 15:53:41 syt Exp $"
+
+import sys
+from cgi import escape
+
+from logilab.common.ureports import HTMLWriter, Section, Table
+
+from pylint.interfaces import IReporter
+from pylint.reporters import BaseReporter
+
+
+class HTMLReporter(BaseReporter):
+ """report messages and layouts in HTML
+ """
+
+ __implements__ = IReporter
+ extension = 'html'
+
+ def __init__(self, output=sys.stdout):
+ BaseReporter.__init__(self, output)
+ self.msgs = []
+
+ def add_message(self, msg_id, location, msg):
+ """manage message of different type and in the context of path"""
+ module, obj, line = location[1:]
+ if self.include_ids:
+ sigle = msg_id
+ else:
+ sigle = msg_id[0]
+ self.msgs += [sigle, module, obj, str(line), escape(msg)]
+
+ def _display(self, layout):
+ """launch layouts display
+
+ overriden from BaseReporter to add a blank line...
+ """
+ if self.msgs:
+ # add stored messages to the layout
+ msgs = ['type', 'module', 'object', 'line', 'message']
+ msgs += self.msgs
+ sect = Section('Messages')
+ layout.append(sect)
+ sect.append(Table(cols=5, children=msgs, rheaders=1))
+ self.msgs = []
+ HTMLWriter().format(layout, self.out)
+
diff --git a/reporters/text.py b/reporters/text.py
new file mode 100644
index 0000000..f4dfd2c
--- /dev/null
+++ b/reporters/text.py
@@ -0,0 +1,151 @@
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+""" Copyright (c) 2000-2003 LOGILAB S.A. (Paris, FRANCE).
+ http://www.logilab.fr/ -- mailto:contact@logilab.fr
+
+Plain text reporter
+"""
+
+__revision__ = "$Id: text.py,v 1.21 2005-12-28 00:24:35 syt Exp $"
+
+import os
+import sys
+
+from logilab.common.ureports import TextWriter
+from logilab.common.textutils import colorize_ansi
+
+from pylint.interfaces import IReporter
+from pylint.reporters import BaseReporter
+
+TITLE_UNDERLINES = ['', '=', '-', '.']
+
+
+## def modname_to_path(modname, prefix=os.getcwd() + os.sep):
+## """transform a module name into a path"""
+## module = load_module_from_name(modname).__file__.replace(prefix, '')
+## return module.replace('.pyc', '.py').replace('.pyo', '.py')
+
+
+class TextReporter(BaseReporter):
+ """reports messages and layouts in plain text
+ """
+
+ __implements__ = IReporter
+ extension = 'txt'
+
+ def __init__(self, output=sys.stdout):
+ BaseReporter.__init__(self, output)
+ self._modules = {}
+
+ def add_message(self, msg_id, location, msg):
+ """manage message of different type and in the context of path"""
+ module, obj, line = location[1:]
+ if not self._modules.has_key(module):
+ self.writeln('************* Module %s' % module)
+ self._modules[module] = 1
+ if obj:
+ obj = ':%s' % obj
+ if self.include_ids:
+ sigle = msg_id
+ else:
+ sigle = msg_id[0]
+ self.writeln('%s:%3s%s: %s' % (sigle, line, obj, msg))
+
+ def _display(self, layout):
+ """launch layouts display"""
+ print >> self.out
+ TextWriter().format(layout, self.out)
+
+
+class TextReporter2(TextReporter):
+ """a reporter very similar to TextReporter, but display messages in a form
+ recognized by most text editors :
+
+ <filename>:<linenum>:<msg>
+ """
+ def __init__(self, output=sys.stdout, relative=True):
+ TextReporter.__init__(self, output)
+ if relative:
+ self._prefix = os.getcwd() + os.sep
+ else:
+ self._prefix = ''
+
+ def add_message(self, msg_id, location, msg):
+ """manage message of different type and in the context of path"""
+ path, _, obj, line = location
+ if obj:
+ obj = ', %s' % obj
+ if self.include_ids:
+ sigle = msg_id
+ else:
+ sigle = msg_id[0]
+ if self._prefix:
+ path = path.replace(self._prefix, '')
+## try:
+## modpath = self._modules[module]
+## except KeyError:
+## modpath = self._modules[module] = self.linter.current_file or \
+## modname_to_path(module)
+ self.writeln('%s:%s: [%s%s] %s' % (path, line, sigle, obj, msg))
+
+
+class ColorizedTextReporter(TextReporter):
+ """Simple TextReporter that colorizes text output"""
+
+ COLOR_MAPPING = {
+ "I" : ("green", None),
+ 'C' : (None, "bold"),
+ 'R' : ("magenta", "bold, italic"),
+ 'W' : ("blue", None),
+ 'E' : ("red", "bold"),
+ 'F' : ("red", "bold, underline"),
+ 'S' : ("yellow", "inverse"), # S stands for module Separator
+ }
+
+ def __init__(self, output=sys.stdout, color_mapping = None):
+ TextReporter.__init__(self, output)
+ self.color_mapping = color_mapping or \
+ dict(ColorizedTextReporter.COLOR_MAPPING)
+
+
+ def _get_decoration(self, msg_id):
+ """Returns the tuple color, style associated with msg_id as defined
+ in self.color_mapping
+ """
+ try:
+ return self.color_mapping[msg_id]
+ except KeyError:
+ return None, None
+
+ def add_message(self, msg_id, location, msg):
+ """manage message of different types, and colorize output
+ using ansi escape codes
+ """
+ module, obj, line = location[1:]
+ if not self._modules.has_key(module):
+ color, style = self._get_decoration('S')
+ modsep = colorize_ansi('************* Module %s' % module,
+ color, style)
+ self.writeln(modsep)
+ self._modules[module] = 1
+ if obj:
+ obj = ':%s' % obj
+ if self.include_ids:
+ sigle = msg_id
+ else:
+ sigle = msg_id[0]
+ color, style = self._get_decoration(sigle)
+ msg = colorize_ansi(msg, color, style)
+ sigle = colorize_ansi(sigle, color, style)
+ self.writeln('%s:%3s%s: %s' % (sigle, line, obj, msg))
+