annotate bitten/trac_ext/web_ui.py @ 114:ecc062d4fd55

Paths to files and directories in the build log output are rendered as links to the repository browser.
author cmlenz
date Sun, 07 Aug 2005 09:03:16 +0000
parents a38eabd4b6e1
children b63ed684c29c
rev   line source
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
1 # -*- coding: iso8859-1 -*-
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
2 #
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
4 #
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
5 # Bitten is free software; you can redistribute it and/or
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
6 # modify it under the terms of the GNU General Public License as
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
7 # published by the Free Software Foundation; either version 2 of the
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
8 # License, or (at your option) any later version.
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
9 #
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
10 # Trac is distributed in the hope that it will be useful,
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
13 # General Public License for more details.
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
14 #
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
18 #
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
19 # Author: Christopher Lenz <cmlenz@gmx.de>
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
20
79
87098cbcdc90 * Use default locations when {{{htdocs_dir}}} and {{{templates_dir}}} isn't configured in {{{trac.ini}}}.
cmlenz
parents: 76
diff changeset
21 import os.path
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
22 import re
81
7129b8a2f125 Fix error when running from an installed instance where the {{{htdocs_dir}}} and/or {{{templates_dir}}} options aren't set.
cmlenz
parents: 80
diff changeset
23 import sys
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
24 from time import localtime, strftime
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
25
99
efc1eed69ba8 Make Bitten deployable in Trac as a [http://peak.telecommunity.com/DevCenter/PythonEggs Python egg].
cmlenz
parents: 98
diff changeset
26 import pkg_resources
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
27 from trac.core import *
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
28 from trac.Timeline import ITimelineEventProvider
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
29 from trac.util import escape, pretty_timedelta
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
30 from trac.web.chrome import INavigationContributor, ITemplateProvider, \
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
31 add_link, add_stylesheet
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
32 from trac.web.main import IRequestHandler
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
33 from trac.wiki import wiki_to_html
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
34 from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, BuildLog
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
35
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
36
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
37 class ILogFormatter(Interface):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
38 """Extension point interface for components that format build log
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
39 messages."""
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
40
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
41 def get_formatter(req, build, step, type):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
42 """Return a function that gets called for every log message.
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
43
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
44 The function must take two positional arguments, `level` and `message`,
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
45 and return the formatted message.
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
46 """
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
47
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
48
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
49 class BuildModule(Component):
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
50 """Implements the Bitten web interface."""
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
51
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
52 implements(INavigationContributor, IRequestHandler, ITimelineEventProvider,
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
53 ITemplateProvider)
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
54
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
55 log_formatters = ExtensionPoint(ILogFormatter)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
56
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
57 _status_label = {Build.IN_PROGRESS: 'in progress',
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
58 Build.SUCCESS: 'completed',
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
59 Build.FAILURE: 'failed'}
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
60 _level_label = {BuildLog.DEBUG: 'debug',
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
61 BuildLog.INFO: 'info',
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
62 BuildLog.WARNING: 'warning',
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
63 BuildLog.ERROR: 'error'}
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
64
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
65 # INavigationContributor methods
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
66
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
67 def get_active_navigation_item(self, req):
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
68 return 'build'
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
69
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
70 def get_navigation_items(self, req):
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
71 if not req.perm.has_permission('BUILD_VIEW'):
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
72 return
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
73 yield 'mainnav', 'build', \
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
74 '<a href="%s" accesskey="5">Build Status</a>' \
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
75 % self.env.href.build()
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
76
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
77 # IRequestHandler methods
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
78
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
79 def match_request(self, req):
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
80 match = re.match(r'/build(?:/([\w.-]+))?(?:/([\d]+))?', req.path_info)
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
81 if match:
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
82 if match.group(1):
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
83 req.args['config'] = match.group(1)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
84 if match.group(2):
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
85 req.args['id'] = match.group(2)
35
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
86 return True
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
87
67631e1d4d45 Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
cmlenz
parents:
diff changeset
88 def process_request(self, req):
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
89 req.perm.assert_permission('BUILD_VIEW')
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
90
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
91 action = req.args.get('action')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
92 config = req.args.get('config')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
93 id = req.args.get('id')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
94
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
95 if req.method == 'POST':
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
96 if config:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
97 if action == 'new':
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
98 self._do_create_platform(req, config)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
99 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
100 platform_id = req.args.get('platform')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
101 if platform_id:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
102 if action == 'edit':
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
103 self._do_save_platform(req, config, platform_id)
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
104 elif 'delete' in req.args:
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
105 self._do_delete_platforms(req)
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
106 self._render_config_form(req, config)
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
107 elif 'new' in req.args:
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
108 platform = TargetPlatform(self.env, config=config)
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
109 self._render_platform_form(req, platform)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
110 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
111 self._do_save_config(req, config)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
112 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
113 if action == 'new':
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
114 self._do_create_config(req)
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
115 else:
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
116 if id:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
117 self._render_build(req, id)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
118 elif config:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
119 if action == 'edit':
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
120 platform_id = req.args.get('platform')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
121 if platform_id:
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
122 platform = TargetPlatform.fetch(self.env,
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
123 int(platform_id))
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
124 self._render_platform_form(req, platform)
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
125 elif 'new' in req.args:
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
126 platform = TargetPlatform(self.env, config=config)
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
127 self._render_platform_form(req, platform)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
128 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
129 self._render_config_form(req, config)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
130 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
131 self._render_config(req, config)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
132 else:
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
133 if action == 'new':
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
134 self._render_config_form(req)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
135 else:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
136 self._render_overview(req)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
137
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
138 add_stylesheet(req, 'build.css')
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
139 return 'build.cs', None
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
140
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
141 # ITemplatesProvider methods
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
142
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
143 def get_htdocs_dir(self):
99
efc1eed69ba8 Make Bitten deployable in Trac as a [http://peak.telecommunity.com/DevCenter/PythonEggs Python egg].
cmlenz
parents: 98
diff changeset
144 return pkg_resources.resource_filename(__name__, 'htdocs')
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
145
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
146 def get_templates_dir(self):
99
efc1eed69ba8 Make Bitten deployable in Trac as a [http://peak.telecommunity.com/DevCenter/PythonEggs Python egg].
cmlenz
parents: 98
diff changeset
147 return pkg_resources.resource_filename(__name__, 'templates')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
148
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
149 # ITimelineEventProvider methods
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
150
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
151 def get_timeline_filters(self, req):
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
152 if req.perm.has_permission('BUILD_VIEW'):
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
153 yield ('build', 'Builds')
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
154
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
155 def get_timeline_events(self, req, start, stop, filters):
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
156 if 'build' in filters:
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
157 add_stylesheet(req, 'build.css')
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
158 db = self.env.get_db_cnx()
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
159 cursor = db.cursor()
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
160 cursor.execute("SELECT b.id,b.config,c.label,b.rev,p.name,b.slave,"
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
161 "b.stopped,b.status FROM bitten_build AS b"
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
162 " INNER JOIN bitten_config AS c ON (c.name=b.config)"
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
163 " INNER JOIN bitten_platform AS p ON (p.id=b.platform) "
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
164 "WHERE b.stopped>=%s AND b.stopped<=%s "
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
165 "AND b.status IN (%s, %s) ORDER BY b.stopped",
67
6ffa99b442bf Fix error in timeline when builds are in progress.
cmlenz
parents: 65
diff changeset
166 (start, stop, Build.SUCCESS, Build.FAILURE))
65
5f9bcb4966b7 Produce different kinds of events in the {{{ITimelineEventProvider}}} implementation, depending on whether the build failed or succeeded; for future use when Bitten provides its own CSS style sheet and images.
cmlenz
parents: 64
diff changeset
167 event_kinds = {Build.SUCCESS: 'successbuild',
5f9bcb4966b7 Produce different kinds of events in the {{{ITimelineEventProvider}}} implementation, depending on whether the build failed or succeeded; for future use when Bitten provides its own CSS style sheet and images.
cmlenz
parents: 64
diff changeset
168 Build.FAILURE: 'failedbuild'}
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
169 for id, config, label, rev, platform, slave, stopped, status in cursor:
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
170 title = 'Build of <em>%s [%s]</em> by %s (%s) %s' \
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
171 % (escape(label), escape(rev), escape(slave),
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
172 escape(platform), self._status_label[status])
79
87098cbcdc90 * Use default locations when {{{htdocs_dir}}} and {{{templates_dir}}} isn't configured in {{{trac.ini}}}.
cmlenz
parents: 76
diff changeset
173 if req.args.get('format') == 'rss':
87098cbcdc90 * Use default locations when {{{htdocs_dir}}} and {{{templates_dir}}} isn't configured in {{{trac.ini}}}.
cmlenz
parents: 76
diff changeset
174 href = self.env.abs_href.build(config, id)
87098cbcdc90 * Use default locations when {{{htdocs_dir}}} and {{{templates_dir}}} isn't configured in {{{trac.ini}}}.
cmlenz
parents: 76
diff changeset
175 else:
87098cbcdc90 * Use default locations when {{{htdocs_dir}}} and {{{templates_dir}}} isn't configured in {{{trac.ini}}}.
cmlenz
parents: 76
diff changeset
176 href = self.env.href.build(config, id)
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
177 yield event_kinds[status], href, title, stopped, None, ''
64
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
178
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
179 # Internal methods
de1a7499f4d6 Basic timeline provider for builds.
cmlenz
parents: 60
diff changeset
180
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
181 def _do_create_config(self, req):
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
182 """Create a new build configuration."""
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
183 req.perm.assert_permission('BUILD_CREATE')
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
184
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
185 if 'cancel' in req.args:
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
186 req.redirect(self.env.href.build())
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
187
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
188 config = BuildConfig(self.env, name=req.args.get('name'),
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
189 path=req.args.get('path', ''),
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
190 label=req.args.get('label', ''),
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
191 active=req.args.has_key('active'),
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
192 description=req.args.get('description'))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
193 config.insert()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
194
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
195 req.redirect(self.env.href.build(config.name))
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
196
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
197 def _do_save_config(self, req, config_name):
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
198 """Save changes to a build configuration."""
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
199 req.perm.assert_permission('BUILD_MODIFY')
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
200
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
201 if 'cancel' in req.args:
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
202 req.redirect(self.env.href.build(config_name))
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
203
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
204 config = BuildConfig.fetch(self.env, config_name)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
205 assert config, 'Build configuration "%s" does not exist' % config_name
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
206 config.name = req.args.get('name')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
207 config.active = req.args.has_key('active')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
208 config.label = req.args.get('label', '')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
209 config.path = req.args.get('path', '')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
210 config.description = req.args.get('description', '')
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
211 config.update()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
212
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
213 req.redirect(self.env.href.build(config.name))
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
214
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
215 def _do_create_platform(self, req, config_name):
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
216 """Create a new target platform."""
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
217 req.perm.assert_permission('BUILD_MODIFY')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
218
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
219 if 'cancel' in req.args:
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
220 req.redirect(self.env.href.build(config_name, action='edit'))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
221
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
222 platform = TargetPlatform(self.env, config=config_name,
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
223 name=req.args.get('name'))
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
224
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
225 properties = [int(key[9:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
226 if key.startswith('property_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
227 properties.sort()
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
228 patterns = [int(key[8:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
229 if key.startswith('pattern_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
230 patterns.sort()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
231 platform.rules = [(req.args.get('property_%d' % property),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
232 req.args.get('pattern_%d' % pattern))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
233 for property, pattern in zip(properties, patterns)]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
234
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
235 add_rules = [int(key[9:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
236 if key.startswith('add_rule_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
237 if add_rules:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
238 platform.rules.insert(add_rules[0] + 1, ('', ''))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
239 self._render_platform_form(req, platform)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
240 return
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
241 rm_rules = [int(key[8:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
242 if key.startswith('rm_rule_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
243 if rm_rules:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
244 del platform.rules[rm_rules[0]]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
245 self._render_platform_form(req, platform)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
246 return
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
247
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
248 platform.insert()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
249
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
250 req.redirect(self.env.href.build(config_name, action='edit'))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
251
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
252 def _do_delete_platforms(self, req):
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
253 """Delete selected target platforms."""
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
254 req.perm.assert_permission('BUILD_MODIFY')
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
255 self.log.debug('_do_delete_platforms')
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
256
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
257 db = self.env.get_db_cnx()
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
258 for platform_id in [int(id) for id in req.args.get('delete_platform')]:
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
259 platform = TargetPlatform.fetch(self.env, platform_id, db=db)
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
260 self.log.info('Deleting target platform %s of configuration %s',
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
261 platform.name, platform.config)
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
262 platform.delete(db=db)
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
263 db.commit()
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
264
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
265 def _do_save_platform(self, req, config_name, platform_id):
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
266 """Save changes to a target platform."""
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
267 req.perm.assert_permission('BUILD_MODIFY')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
268
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
269 if 'cancel' in req.args:
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
270 req.redirect(self.env.href.build(config_name, action='edit'))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
271
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
272 platform = TargetPlatform.fetch(self.env, platform_id)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
273 platform.name = req.args.get('name')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
274
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
275 properties = [int(key[9:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
276 if key.startswith('property_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
277 properties.sort()
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
278 patterns = [int(key[8:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
279 if key.startswith('pattern_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
280 patterns.sort()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
281 platform.rules = [(req.args.get('property_%d' % property),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
282 req.args.get('pattern_%d' % pattern))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
283 for property, pattern in zip(properties, patterns)]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
284
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
285 add_rules = [int(key[9:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
286 if key.startswith('add_rule_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
287 if add_rules:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
288 platform.rules.insert(add_rules[0] + 1, ('', ''))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
289 self._render_platform_form(req, platform)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
290 return
98
1d9dc07acd3d Use {{{in req.args}}} instead of {{{in req.args.keys()}}}.
cmlenz
parents: 96
diff changeset
291 rm_rules = [int(key[8:]) for key in req.args
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
292 if key.startswith('rm_rule_')]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
293 if rm_rules:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
294 del platform.rules[rm_rules[0]]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
295 self._render_platform_form(req, platform)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
296 return
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
297
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
298 platform.update()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
299
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
300 req.redirect(self.env.href.build(config_name, action='edit'))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
301
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
302 def _render_overview(self, req):
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
303 req.hdf['title'] = 'Build Status'
45
80bc0fae3ed1 Renamed {{{Configuration}}} to {{{BuildConfig}}}.
cmlenz
parents: 41
diff changeset
304 configurations = BuildConfig.select(self.env, include_inactive=True)
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
305 for idx, config in enumerate(configurations):
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
306 description = config.description
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
307 if description:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
308 description = wiki_to_html(description, self.env, req)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
309 req.hdf['build.configs.%d' % idx] = {
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
310 'name': config.name, 'label': config.label or config.name,
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
311 'path': config.path, 'description': description,
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
312 'href': self.env.href.build(config.name)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
313 }
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
314 req.hdf['build.mode'] = 'overview'
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
315 req.hdf['build.can_create'] = req.perm.has_permission('BUILD_CREATE')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
316
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
317 def _render_config(self, req, config_name):
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
318 config = BuildConfig.fetch(self.env, config_name)
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
319 req.hdf['title'] = 'Build Configuration "%s"' \
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
320 % escape(config.label or config.name)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
321 add_link(req, 'up', self.env.href.build(), 'Build Status')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
322 description = config.description
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
323 if description:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
324 description = wiki_to_html(description, self.env, req)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
325 req.hdf['build.config'] = {
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
326 'name': config.name, 'label': config.label, 'path': config.path,
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
327 'active': config.active, 'description': description,
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
328 'browser_href': self.env.href.browser(config.path),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
329 'can_modify': req.perm.has_permission('BUILD_MODIFY')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
330 }
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
331 req.hdf['build.mode'] = 'view_config'
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
332
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
333 platforms = TargetPlatform.select(self.env, config=config_name)
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
334 req.hdf['build.platforms'] = [
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
335 {'name': platform.name, 'id': platform.id} for platform in platforms
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
336 ]
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
337
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
338 repos = self.env.get_repository(req.authname)
111
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
339 try:
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
340 root = repos.get_node(config.path)
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
341 num = 0
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
342 for idx, (path, rev, chg) in enumerate(root.get_history()):
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
343 prefix = 'build.builds.%d' % rev
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
344 req.hdf[prefix + '.href'] = self.env.href.changeset(rev)
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
345 for build in Build.select(self.env, config=config.name, rev=rev):
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
346 if build.status == Build.PENDING:
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
347 continue
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
348 req.hdf['%s.%s' % (prefix, build.platform)] = self._build_to_hdf(req, build)
111
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
349 if idx > 4:
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
350 break
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
351 except TracError, e:
8d76fd3918a5 Don't just bail on the build configuration page if an invalid repository path is configured.
cmlenz
parents: 99
diff changeset
352 self.log.error('Error accessing repository info', exc_info=True)
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
353
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
354 def _render_config_form(self, req, config_name=None):
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
355 config = BuildConfig.fetch(self.env, config_name)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
356 if config:
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
357 req.perm.assert_permission('BUILD_MODIFY')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
358 req.hdf['build.config'] = {
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
359 'name': config.name, 'label': config.label, 'path': config.path,
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
360 'active': config.active, 'description': config.description,
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
361 'exists': config.exists
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
362 }
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
363
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
364 req.hdf['title'] = 'Edit Build Configuration "%s"' \
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
365 % escape(config.label or config.name)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
366 for idx, platform in enumerate(TargetPlatform.select(self.env,
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
367 config_name)):
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
368 req.hdf['build.platforms.%d' % idx] = {
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
369 'id': platform.id, 'name': platform.name,
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
370 'href': self.env.href.build(config_name, action='edit',
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
371 platform=platform.id)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
372 }
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
373 else:
50
0d5ad32948b7 Restrict access to web interface with custom permission actions.
cmlenz
parents: 47
diff changeset
374 req.perm.assert_permission('BUILD_CREATE')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
375 req.hdf['title'] = 'Create Build Configuration'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
376 req.hdf['build.mode'] = 'edit_config'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents: 35
diff changeset
377
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
378 def _render_platform_form(self, req, platform):
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
379 req.perm.assert_permission('BUILD_MODIFY')
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
380 if platform.exists:
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
381 req.hdf['title'] = 'Edit Target Platform "%s"' \
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
382 % escape(platform.name)
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
383 else:
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
384 req.hdf['title'] = 'Add Target Platform'
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
385 req.hdf['build.platform'] = {
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
386 'name': platform.name, 'id': platform.id, 'exists': platform.exists,
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
387 'rules': [{'property': propname, 'pattern': pattern}
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
388 for propname, pattern in platform.rules] or [('', '')]
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
389 }
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
390 req.hdf['build.mode'] = 'edit_platform'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
391
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
392 def _render_build(self, req, build_id):
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
393 build = Build.fetch(self.env, build_id)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
394 assert build, 'Build %s does not exist' % build_id
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
395 add_link(req, 'up', self.env.href.build(build.config),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
396 'Build Configuration')
91
91db738c6a74 Fix status display for in-progress builds.
cmlenz
parents: 82
diff changeset
397 status2title = {Build.SUCCESS: 'Success', Build.FAILURE: 'Failure',
91db738c6a74 Fix status display for in-progress builds.
cmlenz
parents: 82
diff changeset
398 Build.IN_PROGRESS: 'In Progress'}
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
399 req.hdf['title'] = 'Build %s - %s' % (build_id,
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
400 status2title[build.status])
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
401 req.hdf['build'] = self._build_to_hdf(req, build, include_output=True)
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
402 req.hdf['build.mode'] = 'view_build'
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
403
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 91
diff changeset
404 config = BuildConfig.fetch(self.env, build.config)
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
405 req.hdf['build.config'] = {
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
406 'name': config.label,
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
407 'href': self.env.href.build(config.name)
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
408 }
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
409
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
410 def _build_to_hdf(self, req, build, include_output=False):
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
411 hdf = {'id': build.id, 'name': build.slave, 'rev': build.rev,
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
412 'status': self._status_label[build.status],
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
413 'cls': self._status_label[build.status].replace(' ', '-'),
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
414 'href': self.env.href.build(build.config, build.id),
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
415 'chgset_href': self.env.href.changeset(build.rev)}
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
416 if build.started:
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
417 hdf['started'] = strftime('%x %X', localtime(build.started))
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
418 hdf['started_delta'] = pretty_timedelta(build.started)
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
419 if build.stopped:
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
420 hdf['stopped'] = strftime('%x %X', localtime(build.stopped))
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
421 hdf['stopped_delta'] = pretty_timedelta(build.stopped)
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
422 hdf['duration'] = pretty_timedelta(build.stopped, build.started)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
423 hdf['slave'] = {
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
424 'name': build.slave,
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
425 'ip_address': build.slave_info.get(Build.IP_ADDRESS),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
426 'os': build.slave_info.get(Build.OS_NAME),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
427 'os.family': build.slave_info.get(Build.OS_FAMILY),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
428 'os.version': build.slave_info.get(Build.OS_VERSION),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
429 'machine': build.slave_info.get(Build.MACHINE),
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
430 'processor': build.slave_info.get(Build.PROCESSOR)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 69
diff changeset
431 }
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
432 db = self.env.get_db_cnx()
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
433 steps = []
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
434 for step in BuildStep.select(self.env, build=build.id, db=db):
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
435 steps.append({
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
436 'name': step.name, 'description': step.description,
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
437 'duration': pretty_timedelta(step.started, step.stopped)
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
438 })
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
439 if include_output:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
440 for log in BuildLog.select(self.env, build=build.id,
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 111
diff changeset
441 step=step.name, db=db):
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
442 formatters = []
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
443 items = []
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
444 for formatter in self.log_formatters:
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
445 formatters.append(formatter.get_formatter(req, build,
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
446 step,
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
447 log.type))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
448 for level, message in log.messages:
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
449 for format in formatters:
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
450 message = format(level, message)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
451 items.append({'level': level, 'message': message})
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
452 steps[-1]['log'] = items
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
453 hdf['steps'] = steps
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 79
diff changeset
454
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 67
diff changeset
455 return hdf
114
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
456
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
457
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
458 class SourceFileLinkFormatter(Component):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
459 """Finds references to files and directories in the repository in the build
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
460 log and renders them as links to the repository browser."""
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
461
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
462 implements(ILogFormatter)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
463
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
464 def get_formatter(self, req, build, step, type):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
465 config = BuildConfig.fetch(self.env, build.config)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
466 repos = self.env.get_repository(req.authname)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
467 nodes = []
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
468 def _walk(node):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
469 for child in node.get_entries():
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
470 path = child.path[len(config.path) + 1:]
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
471 pattern = re.compile("([\s'\"])(%s)([\s'\"])" % re.escape(path))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
472 nodes.append((child.path, pattern))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
473 if child.isdir:
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
474 _walk(child)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
475 _walk(repos.get_node(config.path, build.rev))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
476 nodes.sort(lambda x, y: -cmp(len(x[0]), len(y[0])))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
477
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
478 def _formatter(level, message):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
479 for path, pattern in nodes:
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
480 def _replace(m):
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
481 return '%s<a href="%s">%s</a>%s' % (m.group(1),
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
482 self.env.href.browser(path, rev=build.rev),
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
483 m.group(2), m.group(3))
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
484 message = pattern.sub(_replace, message)
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
485 return message
ecc062d4fd55 Paths to files and directories in the build log output are rendered as links to the repository browser.
cmlenz
parents: 112
diff changeset
486 return _formatter
Copyright (C) 2012-2017 Edgewall Software