| 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 | |
---|
1 | 14 | __docformat__ = 'restructuredtext en' |
---|
| 15 | |
---|
1 | 16 | from trac.core import * |
---|
1 | 17 | from bitten.api import IReportChartGenerator, IReportSummarizer |
---|
| 18 | |
---|
| 19 | |
---|
2 | 20 | class PyLintChartGenerator(Component): |
---|
1 | 21 | implements(IReportChartGenerator) |
---|
| 22 | |
---|
| 23 | # IReportChartGenerator methods |
---|
| 24 | |
---|
1 | 25 | def get_supported_categories(self): |
---|
1 | 26 | return ['lint'] |
---|
| 27 | |
---|
1 | 28 | def generate_chart_data(self, req, config, category): |
---|
3 | 29 | assert category == 'lint' |
---|
| 30 | |
---|
3 | 31 | db = self.env.get_db_cnx() |
---|
3 | 32 | cursor = db.cursor() |
---|
| 33 | |
---|
| 34 | #self.log.debug('config.name=\'%s\'' % (config.name,)) |
---|
0 | 35 | query = """ |
---|
0 | 36 | select build.rev, |
---|
0 | 37 | (select count(*) from bitten_report_item as item |
---|
0 | 38 | where item.report = report.id and item.name='category' and item.value='convention'), |
---|
0 | 39 | (select count(*) from bitten_report_item as item |
---|
0 | 40 | where item.report = report.id and item.name='category' and item.value='error'), |
---|
0 | 41 | (select count(*) from bitten_report_item as item |
---|
0 | 42 | where item.report = report.id and item.name='category' and item.value='refactor'), |
---|
0 | 43 | (select count(*) from bitten_report_item as item |
---|
0 | 44 | where item.report = report.id and item.name='category' and item.value='warning') |
---|
0 | 45 | from bitten_report as report |
---|
0 | 46 | left outer join bitten_build as build ON (report.build=build.id) |
---|
0 | 47 | where build.config='%s' and report.category='lint' |
---|
0 | 48 | and build.rev_time >= %s and build.rev_time <= %s |
---|
0 | 49 | group by build.rev_time, build.rev, build.platform, report.id |
---|
3 | 50 | order by build.rev_time;""" % (config.name, |
---|
3 | 51 | config.min_rev_time(self.env), |
---|
3 | 52 | config.max_rev_time(self.env)) |
---|
| 53 | |
---|
| 54 | #self.log.debug('sql=\'%s\'' % (query,)) |
---|
3 | 55 | cursor.execute(query) |
---|
| 56 | |
---|
3 | 57 | lint = [] |
---|
3 | 58 | prev_rev = None |
---|
3 | 59 | prev_counts = None |
---|
| 60 | |
---|
6 | 61 | for rev, conv, err, ref, warn in cursor: |
---|
3 | 62 | total = conv + err + ref + warn |
---|
3 | 63 | curr_counts = [rev, total, conv, err, ref, warn] |
---|
3 | 64 | if rev != prev_rev: |
---|
2 | 65 | lint.append(curr_counts) |
---|
2 | 66 | else: |
---|
| 67 | # cunningly / dubiously set rev = max(rev, rev) along with the counts |
---|
7 | 68 | lint[-1] = [max(prev, curr) for prev, curr in zip(curr_counts, lint[-1])] |
---|
| 69 | # recalculate total |
---|
1 | 70 | lint[-1][1] = sum(lint[-1][2:]) |
---|
3 | 71 | prev_rev = rev |
---|
| 72 | |
---|
3 | 73 | data = {'title': 'Lint Problems by Type', |
---|
3 | 74 | 'data': [ |
---|
5 | 75 | {'label': 'Total Problems', 'data': [[item[0], item[1]] for item in lint], 'lines': {'fill': True}}, |
---|
5 | 76 | {'label': 'Convention', 'data': [[item[0], item[2]] for item in lint]}, |
---|
5 | 77 | {'label': 'Error', 'data': [[item[0], item[3]] for item in lint]}, |
---|
5 | 78 | {'label': 'Refactor', 'data': [[item[0], item[4]] for item in lint]}, |
---|
5 | 79 | {'label': 'Warning', 'data': [[item[0], item[5]] for item in lint]}, |
---|
5 | 80 | ], |
---|
3 | 81 | 'options': { |
---|
3 | 82 | 'legend': {'position': 'sw', 'backgroundOpacity': 0.7}, |
---|
3 | 83 | 'xaxis': {'tickDecimals': 0}, |
---|
3 | 84 | 'yaxis': {'tickDecimals': 0}, |
---|
3 | 85 | }, |
---|
3 | 86 | } |
---|
| 87 | |
---|
3 | 88 | return 'json.txt', {"json": data} |
---|
| 89 | |
---|
| 90 | |
---|
2 | 91 | class PyLintSummarizer(Component): |
---|
1 | 92 | implements(IReportSummarizer) |
---|
| 93 | |
---|
| 94 | # IReportSummarizer methods |
---|
| 95 | |
---|
1 | 96 | def get_supported_categories(self): |
---|
1 | 97 | return ['lint'] |
---|
| 98 | |
---|
1 | 99 | def render_summary(self, req, config, build, step, category): |
---|
0 | 100 | assert category == 'lint' |
---|
| 101 | |
---|
0 | 102 | db = self.env.get_db_cnx() |
---|
0 | 103 | cursor = db.cursor() |
---|
0 | 104 | cursor.execute(""" |
---|
0 | 105 | SELECT item_type.value AS type, item_file.value AS file, |
---|
0 | 106 | item_line.value as line, item_category.value as category, |
---|
0 | 107 | report.category as report_category |
---|
0 | 108 | FROM bitten_report AS report |
---|
0 | 109 | LEFT OUTER JOIN bitten_report_item AS item_type |
---|
0 | 110 | ON (item_type.report=report.id AND item_type.name='type') |
---|
0 | 111 | LEFT OUTER JOIN bitten_report_item AS item_file |
---|
0 | 112 | ON (item_file.report=report.id AND |
---|
0 | 113 | item_file.item=item_type.item AND |
---|
0 | 114 | item_file.name='file') |
---|
0 | 115 | LEFT OUTER JOIN bitten_report_item AS item_line |
---|
0 | 116 | ON (item_line.report=report.id AND |
---|
0 | 117 | item_line.item=item_type.item AND |
---|
0 | 118 | item_line.name='lines') |
---|
0 | 119 | LEFT OUTER JOIN bitten_report_item AS item_category |
---|
0 | 120 | ON (item_category.report=report.id AND |
---|
0 | 121 | item_category.item=item_type.item AND |
---|
0 | 122 | item_category.name='category') |
---|
0 | 123 | WHERE report.category='lint' AND build=%s AND step=%s |
---|
0 | 124 | ORDER BY item_type.value""", (build.id, step.name)) |
---|
| 125 | |
---|
0 | 126 | file_data = {} |
---|
| 127 | |
---|
0 | 128 | type_total = {} |
---|
0 | 129 | category_total = {} |
---|
0 | 130 | line_total = 0 |
---|
0 | 131 | file_total = 0 |
---|
0 | 132 | seen_files = {} |
---|
| 133 | |
---|
0 | 134 | for type, file, line, category, report_category in cursor: |
---|
0 | 135 | if not file_data.has_key(file): |
---|
0 | 136 | file_data[file] = {'file': file, 'type': {}, 'lines': 0, 'category': {}} |
---|
| 137 | |
---|
0 | 138 | d = file_data[file] |
---|
| 139 | #d = {'type': type, 'line': line, 'category': category} |
---|
0 | 140 | if not d['type'].has_key(type): |
---|
0 | 141 | d['type'][type] = 0 |
---|
0 | 142 | d['type'][type] += 1 |
---|
| 143 | |
---|
0 | 144 | d['lines'] += 1 |
---|
0 | 145 | line_total += 1 |
---|
| 146 | |
---|
0 | 147 | if not d['category'].has_key(category): |
---|
0 | 148 | d['category'][category] = 0 |
---|
0 | 149 | d['category'][category] += 1 |
---|
| 150 | |
---|
0 | 151 | if file: |
---|
0 | 152 | d['href'] = req.href.browser(config.path, file) |
---|
| 153 | |
---|
0 | 154 | if not type_total.has_key(type): |
---|
0 | 155 | type_total[type] = 0 |
---|
0 | 156 | type_total[type] += 1 |
---|
| 157 | |
---|
0 | 158 | if not category_total.has_key(category): |
---|
0 | 159 | category_total[category] = 0 |
---|
0 | 160 | category_total[category] += 1 |
---|
| 161 | |
---|
0 | 162 | if not seen_files.has_key(file): |
---|
0 | 163 | seen_files[file] = 0 |
---|
0 | 164 | file_total += 1 |
---|
| 165 | |
---|
0 | 166 | data = [] |
---|
0 | 167 | for d in file_data.values(): |
---|
0 | 168 | d['catnames'] = d['category'].keys() |
---|
0 | 169 | data.append(d) |
---|
| 170 | |
---|
0 | 171 | template_data = {} |
---|
0 | 172 | template_data['data'] = data |
---|
0 | 173 | template_data['totals'] = {'type': type_total, 'category': category_total, 'files': file_total, 'lines': line_total} |
---|
| 174 | |
---|
0 | 175 | return 'bitten_summary_lint.html', template_data |
---|