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