Edgewall Software

source: trunk/bitten/report/lint.py @ 1001

Last change on this file since 1001 was 910, checked in by osimons, 13 years ago

Updated copyright to 2010.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/python-source
File size: 6.2 KB
CovLine 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2007 Jeffrey Kyllo <jkyllo-eatlint@echospiral.com>
4#
5# Based on code from the Bitten project:
6# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
7# Copyright (C) 2007-2010 Edgewall Software
8# All rights reserved.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at http://echospiral.com/trac/eatlint/wiki/License.
13
114__docformat__ = 'restructuredtext en'
15
116from trac.core import *
117from bitten.api import IReportChartGenerator, IReportSummarizer
18
19
220class PyLintChartGenerator(Component):
121    implements(IReportChartGenerator)
22
23    # IReportChartGenerator methods
24
125    def get_supported_categories(self):
126        return ['lint']
27
128    def generate_chart_data(self, req, config, category):
329        assert category == 'lint'
30
331        db = self.env.get_db_cnx()
332        cursor = db.cursor()
33
34        #self.log.debug('config.name=\'%s\'' % (config.name,))
035        query = """
036select build.rev,
037 (select count(*) from bitten_report_item as item
038  where item.report = report.id and item.name='category' and item.value='convention'),
039 (select count(*) from bitten_report_item as item
040  where item.report = report.id and item.name='category' and item.value='error'),
041 (select count(*) from bitten_report_item as item
042  where item.report = report.id and item.name='category' and item.value='refactor'),
043 (select count(*) from bitten_report_item as item
044  where item.report = report.id and item.name='category' and item.value='warning')
045from bitten_report as report
046 left outer join bitten_build as build ON (report.build=build.id)
047where build.config='%s' and report.category='lint'
048  and build.rev_time >= %s and build.rev_time <= %s
049group by build.rev_time, build.rev, build.platform, report.id
350order by build.rev_time;""" % (config.name,
351                               config.min_rev_time(self.env),
352                               config.max_rev_time(self.env))
53
54        #self.log.debug('sql=\'%s\'' % (query,))
355        cursor.execute(query)
56
357        lint = []
358        prev_rev = None
359        prev_counts = None
60
661        for rev, conv, err, ref, warn in cursor:
362            total = conv + err + ref + warn
363            curr_counts = [rev, total, conv, err, ref, warn]
364            if rev != prev_rev:
265                lint.append(curr_counts)
266            else:
67                # cunningly / dubiously set rev = max(rev, rev) along with the counts
768                lint[-1] = [max(prev, curr) for prev, curr in zip(curr_counts, lint[-1])]
69                # recalculate total
170                lint[-1][1] = sum(lint[-1][2:])
371            prev_rev = rev
72
373        data = {'title': 'Lint Problems by Type',
374                'data': [
575                    {'label': 'Total Problems', 'data': [[item[0], item[1]] for item in lint], 'lines': {'fill': True}},
576                    {'label': 'Convention', 'data': [[item[0], item[2]] for item in lint]},
577                    {'label': 'Error', 'data': [[item[0], item[3]] for item in lint]},
578                    {'label': 'Refactor', 'data': [[item[0], item[4]] for item in lint]},
579                    {'label': 'Warning', 'data': [[item[0], item[5]] for item in lint]},
580                ],
381                'options': {
382                    'legend': {'position': 'sw', 'backgroundOpacity': 0.7},
383                    'xaxis': {'tickDecimals': 0},
384                    'yaxis': {'tickDecimals': 0},
385                },
386               }
87
388        return 'json.txt', {"json": data}
89
90
291class PyLintSummarizer(Component):
192    implements(IReportSummarizer)
93
94    # IReportSummarizer methods
95
196    def get_supported_categories(self):
197        return ['lint']
98
199    def render_summary(self, req, config, build, step, category):
0100        assert category == 'lint'
101
0102        db = self.env.get_db_cnx()
0103        cursor = db.cursor()
0104        cursor.execute("""
0105SELECT item_type.value AS type, item_file.value AS file,
0106    item_line.value as line, item_category.value as category,
0107    report.category as report_category
0108FROM bitten_report AS report
0109 LEFT OUTER JOIN bitten_report_item AS item_type
0110  ON (item_type.report=report.id AND item_type.name='type')
0111 LEFT OUTER JOIN bitten_report_item AS item_file
0112  ON (item_file.report=report.id AND
0113    item_file.item=item_type.item AND
0114    item_file.name='file')
0115 LEFT OUTER JOIN bitten_report_item AS item_line
0116  ON (item_line.report=report.id AND
0117    item_line.item=item_type.item AND
0118    item_line.name='lines')
0119 LEFT OUTER JOIN bitten_report_item AS item_category
0120  ON (item_category.report=report.id AND
0121    item_category.item=item_type.item AND
0122    item_category.name='category')
0123WHERE report.category='lint' AND build=%s AND step=%s
0124ORDER BY item_type.value""", (build.id, step.name))
125
0126        file_data = {}
127
0128        type_total = {}
0129        category_total = {}
0130        line_total = 0
0131        file_total = 0
0132        seen_files = {}
133
0134        for type, file, line, category, report_category in cursor:
0135            if not file_data.has_key(file):
0136                file_data[file] = {'file': file, 'type': {}, 'lines': 0, 'category': {}}
137
0138            d = file_data[file]
139            #d = {'type': type, 'line': line, 'category': category}
0140            if not d['type'].has_key(type):
0141                d['type'][type] = 0
0142            d['type'][type] += 1
143
0144            d['lines'] += 1
0145            line_total += 1
146
0147            if not d['category'].has_key(category):
0148                d['category'][category] = 0
0149            d['category'][category] += 1
150
0151            if file:
0152                d['href'] = req.href.browser(config.path, file)
153
0154            if not type_total.has_key(type):
0155                type_total[type] = 0
0156            type_total[type] += 1
157
0158            if not category_total.has_key(category):
0159                category_total[category] = 0
0160            category_total[category] += 1
161
0162            if not seen_files.has_key(file):
0163                seen_files[file] = 0
0164                file_total += 1
165
0166        data = []
0167        for d in file_data.values():
0168            d['catnames'] = d['category'].keys()
0169            data.append(d)
170
0171        template_data = {}
0172        template_data['data'] = data
0173        template_data['totals'] = {'type': type_total, 'category': category_total, 'files': file_total, 'lines': line_total}
174
0175        return 'bitten_summary_lint.html', template_data
Note: See TracBrowser for help on using the repository browser.