# HG changeset patch # User wbell # Date 1272118880 0 # Node ID ab1f18d0e98ca80d23c509314ede565827c95f29 # Parent ab91df14f670d5881ee285cac70f840a0201d7a3 Merge of [834] to 0.6 diff --git a/bitten/model.py b/bitten/model.py --- a/bitten/model.py +++ b/bitten/model.py @@ -14,6 +14,8 @@ from trac.db import Table, Column, Index from trac.resource import Resource from trac.util.text import to_unicode +from trac.util.datefmt import to_timestamp, utcmin, utcmax +from datetime import datetime import codecs import os @@ -186,6 +188,36 @@ select = classmethod(select) + def min_rev_time(self, env): + """Returns the time of the minimum revision being built for this + configuration. Returns utcmin if not specified. + """ + repos = env.get_repository() + + min_time = utcmin + if self.min_rev: + min_time = repos.get_changeset(self.min_rev).date + + if isinstance(min_time, datetime): # Trac>=0.11 + min_time = to_timestamp(min_time) + + return min_time + + def max_rev_time(self, env): + """Returns the time of the maximum revision being built for this + configuration. Returns utcmax if not specified. + """ + repos = env.get_repository() + + max_time = utcmax + if self.max_rev: + max_time = repos.get_changeset(self.max_rev).date + + if isinstance(max_time, datetime): # Trac>=0.11 + max_time = to_timestamp(max_time) + + return max_time + class TargetPlatform(object): """Target platform for a build configuration.""" diff --git a/bitten/report/coverage.py b/bitten/report/coverage.py --- a/bitten/report/coverage.py +++ b/bitten/report/coverage.py @@ -42,11 +42,14 @@ ON (item_percentage.report=report.id AND item_percentage.name='percentage' AND item_percentage.item=item_lines.item) WHERE build.config=%%s AND report.category='coverage' + AND build.rev_time >= %%s AND build.rev_time <= %%s GROUP BY build.rev_time, build.rev, build.platform ORDER BY build.rev_time""" % (db.cast('item_lines.value', 'int'), db.cast('item_lines.value', 'int'), db.cast('item_percentage.value', 'int')), - (config.name,)) + (config.name, + config.min_rev_time(self.env), + config.max_rev_time(self.env))) prev_rev = None coverage = [] diff --git a/bitten/report/lint.py b/bitten/report/lint.py --- a/bitten/report/lint.py +++ b/bitten/report/lint.py @@ -45,8 +45,11 @@ 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,) +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) diff --git a/bitten/report/testing.py b/bitten/report/testing.py --- a/bitten/report/testing.py +++ b/bitten/report/testing.py @@ -35,8 +35,11 @@ LEFT OUTER JOIN bitten_report_item AS item_status ON (item_status.report=report.id AND item_status.name='status') WHERE build.config=%s AND report.category='test' + AND build.rev_time >= %s AND build.rev_time <= %s GROUP BY build.rev_time, build.rev, build.platform, item_status.value -ORDER BY build.rev_time, build.platform""", (config.name,)) +ORDER BY build.rev_time, build.platform""", (config.name, + config.min_rev_time(self.env), + config.max_rev_time(self.env))) prev_rev = None prev_platform, platform_total = None, 0 diff --git a/bitten/report/tests/coverage.py b/bitten/report/tests/coverage.py --- a/bitten/report/tests/coverage.py +++ b/bitten/report/tests/coverage.py @@ -39,7 +39,8 @@ def test_no_reports(self): req = Mock() - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) generator = TestCoverageChartGenerator(self.env) template, data = generator.generate_chart_data(req, config, 'coverage') self.assertEqual('bitten_chart_coverage.html', template) @@ -49,7 +50,8 @@ self.assertEqual('Coverage', data['data'][2][0]) def test_single_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) build.insert() @@ -71,7 +73,8 @@ self.assertEqual(3, data['data'][2][1]) def test_multi_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) build.insert() diff --git a/bitten/report/tests/lint.py b/bitten/report/tests/lint.py --- a/bitten/report/tests/lint.py +++ b/bitten/report/tests/lint.py @@ -35,7 +35,8 @@ def test_no_reports(self): req = Mock() - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) generator = PyLintChartGenerator(self.env) template, data = generator.generate_chart_data(req, config, 'lint') self.assertEqual('bitten_chart_lint.html', template) @@ -48,7 +49,8 @@ self.assertEqual('Warning', data['data'][5][0]) def test_single_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) build.insert() @@ -80,7 +82,8 @@ self.assertEqual(2, data['data'][5][1]) def test_multi_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) diff --git a/bitten/report/tests/testing.py b/bitten/report/tests/testing.py --- a/bitten/report/tests/testing.py +++ b/bitten/report/tests/testing.py @@ -37,7 +37,8 @@ def test_no_reports(self): req = Mock() - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) generator = TestResultsChartGenerator(self.env) template, data = generator.generate_chart_data(req, config, 'test') self.assertEqual('bitten_chart_tests.html', template) @@ -47,7 +48,8 @@ self.assertEqual('Failures', data['data'][2][0]) def test_single_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) build.insert() @@ -69,7 +71,8 @@ self.assertEqual(1, data['data'][2][1]) def test_multi_platform(self): - config = Mock(name='trunk') + config = Mock(name='trunk', min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) build = Build(self.env, config='trunk', platform=1, rev=123, rev_time=42) @@ -114,7 +117,9 @@ cursor.execute(stmt) def test_testcase_errors_and_failures(self): - config = Mock(name='trunk', path='/somewhere') + config = Mock(name='trunk', path='/somewhere', + min_rev_time=lambda env: 0, + max_rev_time=lambda env: 1000) step = Mock(name='foo') build = Build(self.env, config=config.name, platform=1, rev=123, diff --git a/bitten/web_ui.py b/bitten/web_ui.py --- a/bitten/web_ui.py +++ b/bitten/web_ui.py @@ -13,6 +13,7 @@ import posixpath import re from StringIO import StringIO +from datetime import datetime import pkg_resources from genshi.builder import tag @@ -391,11 +392,13 @@ if has_reports: chart_generators = [] + report_categories = list(self._report_categories_for_config(config)) for generator in ReportChartController(self.env).generators: for category in generator.get_supported_categories(): - chart_generators.append({ - 'href': req.href.build(config.name, 'chart/' + category) - }) + if category in report_categories: + chart_generators.append({ + 'href': req.href.build(config.name, 'chart/' + category) + }) data['config']['charts'] = chart_generators charts_license = self.config.get('bitten', 'charts_license') if charts_license: @@ -450,6 +453,26 @@ prevnext_nav (req, 'Page') return data + def _report_categories_for_config(self, config): + """Yields the categories of reports that exist for active builds + of this configuration. + """ + + db = self.env.get_db_cnx() + repos = self.env.get_repository() + cursor = db.cursor() + + cursor.execute("""SELECT DISTINCT report.category as category +FROM bitten_build AS build +JOIN bitten_report AS report ON (report.build=build.id) +WHERE build.config=%s AND build.rev_time >= %s AND build.rev_time <= %s""", + (config.name, + config.min_rev_time(self.env), + config.max_rev_time(self.env))) + + for (category,) in cursor: + yield category + class BuildController(Component): """Renders the build page.""" @@ -672,10 +695,10 @@ if summarizer: tmpl, data = summarizer.render_summary(req, config, build, step, report.category) + reports.append({'category': report.category, + 'template': tmpl, 'data': data}) else: tmpl = data = None - reports.append({'category': report.category, - 'template': tmpl, 'data': data}) return reports