Mercurial > bitten > bitten-test
annotate bitten/admin.py @ 609:022bcceb90b7
0.6dev: Removing whitespace from target platform rules admin. Fixes #336.
author | osimons |
---|---|
date | Sat, 01 Aug 2009 00:48:47 +0000 |
parents | 5d396356bf7a |
children | 0c11c58d1985 |
rev | line source |
---|---|
429 | 1 # -*- coding: utf-8 -*- |
2 # | |
3 # Copyright (C) 2007 Edgewall Software | |
4 # All rights reserved. | |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://bitten.edgewall.org/wiki/License. | |
9 | |
10 """Implementation of the web administration interface.""" | |
11 | |
432 | 12 from pkg_resources import require, DistributionNotFound |
429 | 13 import re |
14 | |
15 from trac.core import * | |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
16 from trac.admin import IAdminPanelProvider |
557
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
17 from trac.web.chrome import add_stylesheet, add_script |
429 | 18 |
19 from bitten.model import BuildConfig, TargetPlatform | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
20 from bitten.recipe import Recipe, InvalidRecipeError |
429 | 21 from bitten.util import xmlio |
22 | |
23 | |
24 class BuildMasterAdminPageProvider(Component): | |
25 """Web administration panel for configuring the build master.""" | |
26 | |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
27 implements(IAdminPanelProvider) |
429 | 28 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
29 # IAdminPanelProvider methods |
429 | 30 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
31 def get_admin_panels(self, req): |
429 | 32 if req.perm.has_permission('BUILD_ADMIN'): |
432 | 33 yield ('bitten', 'Builds', 'master', 'Master Settings') |
429 | 34 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
35 def render_admin_panel(self, req, cat, page, path_info): |
429 | 36 from bitten.master import BuildMaster |
37 master = BuildMaster(self.env) | |
38 | |
39 if req.method == 'POST': | |
433 | 40 self._save_config_changes(req, master) |
41 req.redirect(req.abs_href.admin(cat, page)) | |
429 | 42 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
43 data = {'master': master} |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
44 add_stylesheet(req, 'bitten/admin.css') |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
45 return 'bitten_admin_master.html', data |
429 | 46 |
433 | 47 # Internal methods |
48 | |
49 def _save_config_changes(self, req, master): | |
50 changed = False | |
51 | |
52 build_all = 'build_all' in req.args | |
53 if build_all != master.build_all: | |
54 self.config['bitten'].set('build_all', | |
55 build_all and 'yes' or 'no') | |
56 changed = True | |
57 | |
58 adjust_timestamps = 'adjust_timestamps' in req.args | |
59 if adjust_timestamps != master.adjust_timestamps: | |
60 self.config['bitten'].set('adjust_timestamps', | |
61 adjust_timestamps and 'yes' or 'no') | |
62 changed = True | |
63 | |
468
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
64 stabilize_wait = int(req.args.get('stabilize_wait', 0)) |
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
65 if stabilize_wait != master.stabilize_wait: |
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
66 self.config['bitten'].set('stabilize_wait', str(stabilize_wait)) |
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
67 changed = True |
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
68 |
433 | 69 slave_timeout = int(req.args.get('slave_timeout', 0)) |
70 if slave_timeout != master.slave_timeout: | |
71 self.config['bitten'].set('slave_timeout', str(slave_timeout)) | |
72 changed = True | |
73 | |
557
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
74 quick_status = 'quick_status' in req.args |
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
75 if quick_status != master.quick_status: |
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
76 self.config['bitten'].set('quick_status', |
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
77 quick_status and 'yes' or 'no') |
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
78 changed = True |
b4d3d9cbf200
Alter the appearance of the ''Build Status'' button, to show the current build status [eblot] - fixes #373
dfraser
parents:
516
diff
changeset
|
79 |
516
2f3b7c17d3c3
Switch to storing log messages in files rather than in database rows:
dfraser
parents:
503
diff
changeset
|
80 logs_dir = req.args.get('logs_dir', None) |
2f3b7c17d3c3
Switch to storing log messages in files rather than in database rows:
dfraser
parents:
503
diff
changeset
|
81 if logs_dir != master.logs_dir: |
2f3b7c17d3c3
Switch to storing log messages in files rather than in database rows:
dfraser
parents:
503
diff
changeset
|
82 self.config['bitten'].set('logs_dir', str(logs_dir)) |
2f3b7c17d3c3
Switch to storing log messages in files rather than in database rows:
dfraser
parents:
503
diff
changeset
|
83 changed = True |
2f3b7c17d3c3
Switch to storing log messages in files rather than in database rows:
dfraser
parents:
503
diff
changeset
|
84 |
433 | 85 if changed: |
86 self.config.save() | |
87 | |
88 return master | |
89 | |
429 | 90 |
91 class BuildConfigurationsAdminPageProvider(Component): | |
92 """Web administration panel for configuring the build master.""" | |
93 | |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
94 implements(IAdminPanelProvider) |
429 | 95 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
96 # IAdminPanelProvider methods |
429 | 97 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
98 def get_admin_panels(self, req): |
429 | 99 if req.perm.has_permission('BUILD_MODIFY'): |
432 | 100 yield ('bitten', 'Builds', 'configs', 'Configurations') |
429 | 101 |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
102 def render_admin_panel(self, req, cat, page, path_info): |
429 | 103 data = {} |
104 | |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
105 # Analyze url |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
106 try: |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
107 config_name, platform_id = path_info.split('/', 1) |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
108 except: |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
109 config_name = path_info |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
110 platform_id = None |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
111 |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
112 if config_name: # Existing build config |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
113 if platform_id or ( |
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
114 # Editing or creating one of the config's target platforms |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
115 req.method == 'POST' and 'new' in req.args): |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
116 |
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
117 if platform_id: # Editing target platform |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
118 platform_id = int(platform_id) |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
119 platform = TargetPlatform.fetch(self.env, platform_id) |
429 | 120 |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
121 if req.method == 'POST': |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
122 if 'cancel' in req.args or \ |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
123 self._update_platform(req, platform): |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
124 req.redirect(req.abs_href.admin(cat, page, |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
125 config_name)) |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
126 else: # creating target platform |
607
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
127 platform = self._create_platform(req, config_name) |
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
128 req.redirect(req.abs_href.admin(cat, page, |
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
129 config_name, platform.id)) |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
130 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
131 # Set up template variables |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
132 data['platform'] = { |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
133 'id': platform.id, 'name': platform.name, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
134 'exists': platform.exists, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
135 'rules': [ |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
136 {'property': propname, 'pattern': pattern} |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
137 for propname, pattern in platform.rules |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
138 ] or [('', '')] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
139 } |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
140 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
141 else: # Editing existing build config itself |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
142 config = BuildConfig.fetch(self.env, config_name) |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
143 platforms = list(TargetPlatform.select(self.env, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
144 config=config.name)) |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
145 |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
146 if req.method == 'POST': |
607
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
147 if 'remove' in req.args: # Remove selected platforms |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
148 self._remove_platforms(req) |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
149 req.redirect(req.abs_href.admin(cat, page, config.name)) |
468
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
150 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
151 elif 'save' in req.args: # Save this build config |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
152 self._update_config(req, config) |
468
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
153 |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
154 req.redirect(req.abs_href.admin(cat, page)) |
468
44c2b4ac6157
Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents:
467
diff
changeset
|
155 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
156 # Prepare template variables |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
157 data['config'] = { |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
158 'name': config.name, 'label': config.label or config.name, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
159 'active': config.active, 'path': config.path, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
160 'min_rev': config.min_rev, 'max_rev': config.max_rev, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
161 'description': config.description, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
162 'recipe': config.recipe, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
163 'platforms': [{ |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
164 'name': platform.name, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
165 'id': platform.id, |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
166 'href': req.href.admin('bitten', 'configs', config.name, |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
167 platform.id), |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
168 'rules': [{'property': propname, 'pattern': pattern} |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
169 for propname, pattern in platform.rules] |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
170 } for platform in platforms] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
171 } |
429 | 172 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
173 else: # At the top level build config list |
429 | 174 if req.method == 'POST': |
433 | 175 if 'add' in req.args: # Add build config |
176 config = self._create_config(req) | |
177 req.redirect(req.abs_href.admin(cat, page, config.name)) | |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
178 |
433 | 179 elif 'remove' in req.args: # Remove selected build configs |
180 self._remove_configs(req) | |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
181 |
433 | 182 elif 'apply' in req.args: # Update active state of configs |
183 self._activate_configs(req) | |
184 req.redirect(req.abs_href.admin(cat, page)) | |
429 | 185 |
467
5c9f34b18236
Apply patch that clarifies some code in the admin module. Closes #196. Thanks to David Abrahams.
cmlenz
parents:
455
diff
changeset
|
186 # Prepare template variables |
429 | 187 configs = [] |
188 for config in BuildConfig.select(self.env, include_inactive=True): | |
189 configs.append({ | |
190 'name': config.name, 'label': config.label or config.name, | |
191 'active': config.active, 'path': config.path, | |
192 'min_rev': config.min_rev, 'max_rev': config.max_rev, | |
193 'href': req.href.admin('bitten', 'configs', config.name), | |
572
1caaefd76375
0.6dev: Don't provide option to enable a build configuration without a recipe. Closes #168.
osimons
parents:
563
diff
changeset
|
194 'recipe': config.recipe and True or False |
429 | 195 }) |
196 data['configs'] = configs | |
197 | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
198 add_stylesheet(req, 'bitten/admin.css') |
563
a5a7e19399b5
Autocomplete path names in configuration using trac's autocompletion code (supports trac 0.11 and 0.12) (Emannuel Blot) - fixes #363
dfraser
parents:
557
diff
changeset
|
199 add_script(req, 'common/js/suggest.js') |
503
a7c795920c4a
Merging trac-0.11 branch to trunk. This revision is equivalent to [571].
wbell
parents:
468
diff
changeset
|
200 return 'bitten_admin_configs.html', data |
433 | 201 |
202 # Internal methods | |
203 | |
204 def _activate_configs(self, req): | |
434 | 205 req.perm.assert_permission('BUILD_MODIFY') |
206 | |
455
dc2c565600a9
Fix for deactivating all configurations on admin page. Closes #175.
cmlenz
parents:
436
diff
changeset
|
207 active = req.args.get('active') or [] |
dc2c565600a9
Fix for deactivating all configurations on admin page. Closes #175.
cmlenz
parents:
436
diff
changeset
|
208 active = isinstance(active, list) and active or [active] |
434 | 209 |
433 | 210 db = self.env.get_db_cnx() |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
211 for config in list(BuildConfig.select(self.env, db=db, |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
212 include_inactive=True)): |
433 | 213 config.active = config.name in active |
214 config.update(db=db) | |
215 db.commit() | |
216 | |
217 def _create_config(self, req): | |
218 req.perm.assert_permission('BUILD_CREATE') | |
434 | 219 |
433 | 220 config = BuildConfig(self.env) |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
221 self._update_config(req, config) |
433 | 222 return config |
223 | |
224 def _remove_configs(self, req): | |
225 req.perm.assert_permission('BUILD_DELETE') | |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
226 |
433 | 227 sel = req.args.get('sel') |
228 if not sel: | |
229 raise TracError('No configuration selected') | |
230 sel = isinstance(sel, list) and sel or [sel] | |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
231 |
433 | 232 db = self.env.get_db_cnx() |
233 for name in sel: | |
234 config = BuildConfig.fetch(self.env, name, db=db) | |
235 if not config: | |
236 raise TracError('Configuration %r not found' % name) | |
237 config.delete(db=db) | |
238 db.commit() | |
239 | |
240 def _update_config(self, req, config): | |
434 | 241 req.perm.assert_permission('BUILD_MODIFY') |
242 | |
433 | 243 name = req.args.get('name') |
244 if not name: | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
245 raise TracError('Missing required field "name"', 'Missing Field') |
433 | 246 if not re.match(r'^[\w.-]+$', name): |
247 raise TracError('The field "name" may only contain letters, ' | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
248 'digits, periods, or dashes.', 'Invalid Field') |
433 | 249 |
250 path = req.args.get('path', '') | |
251 repos = self.env.get_repository(req.authname) | |
252 max_rev = req.args.get('max_rev') or None | |
253 try: | |
254 node = repos.get_node(path, max_rev) | |
255 assert node.isdir, '%s is not a directory' % node.path | |
256 except (AssertionError, TracError), e: | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
257 raise TracError(unicode(e), 'Invalid Repository Path') |
433 | 258 if req.args.get('min_rev'): |
259 try: | |
260 repos.get_node(path, req.args.get('min_rev')) | |
261 except TracError, e: | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
262 raise TracError(unicode(e), 'Invalid Oldest Revision') |
433 | 263 |
264 recipe_xml = req.args.get('recipe', '') | |
265 if recipe_xml: | |
266 try: | |
267 Recipe(xmlio.parse(recipe_xml)).validate() | |
268 except xmlio.ParseError, e: | |
269 raise TracError('Failure parsing recipe: %s' % e, | |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
270 'Invalid Recipe') |
433 | 271 except InvalidRecipeError, e: |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
272 raise TracError(unicode(e), 'Invalid Recipe') |
433 | 273 |
274 config.name = name | |
275 config.path = repos.normalize_path(path) | |
276 config.recipe = recipe_xml | |
277 config.min_rev = req.args.get('min_rev') | |
278 config.max_rev = req.args.get('max_rev') | |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
279 config.label = req.args.get('label', config.name) |
433 | 280 config.description = req.args.get('description', '') |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
281 |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
282 if config.exists: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
283 config.update() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
284 else: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
285 config.insert() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
286 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
287 def _create_platform(self, req, config_name): |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
288 req.perm.assert_permission('BUILD_MODIFY') |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
289 |
607
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
290 name = req.args.get('platform_name') |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
291 if not name: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
292 raise TracError('Missing required field "name"', 'Missing field') |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
293 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
294 platform = TargetPlatform(self.env, config=config_name, name=name) |
607
5d396356bf7a
0.6dev: Reworked UI for adding Target Platform. Like elsewhere in Trac web admin, 'New Target Platform' is now a fieldset to the right of the listing. This fixes the issue discussed on #333.
osimons
parents:
572
diff
changeset
|
295 platform.insert() |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
296 return platform |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
297 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
298 def _remove_platforms(self, req): |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
299 req.perm.assert_permission('BUILD_MODIFY') |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
300 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
301 sel = req.args.get('sel') |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
302 if not sel: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
303 raise TracError('No platform selected') |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
304 sel = isinstance(sel, list) and sel or [sel] |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
305 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
306 db = self.env.get_db_cnx() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
307 for platform_id in sel: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
308 platform = TargetPlatform.fetch(self.env, platform_id, db=db) |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
309 if not platform: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
310 raise TracError('Target platform %r not found' % platform_id) |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
311 platform.delete(db=db) |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
312 db.commit() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
313 |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
314 def _update_platform(self, req, platform): |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
315 platform.name = req.args.get('name') |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
316 |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
317 properties = [int(key[9:]) for key in req.args.keys() |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
318 if key.startswith('property_')] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
319 properties.sort() |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
320 patterns = [int(key[8:]) for key in req.args.keys() |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
321 if key.startswith('pattern_')] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
322 patterns.sort() |
609
022bcceb90b7
0.6dev: Removing whitespace from target platform rules admin. Fixes #336.
osimons
parents:
607
diff
changeset
|
323 platform.rules = [(req.args.get('property_%d' % property).strip(), |
022bcceb90b7
0.6dev: Removing whitespace from target platform rules admin. Fixes #336.
osimons
parents:
607
diff
changeset
|
324 req.args.get('pattern_%d' % pattern).strip()) |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
325 for property, pattern in zip(properties, patterns) |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
326 if req.args.get('property_%d' % property)] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
327 |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
328 if platform.exists: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
329 platform.update() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
330 else: |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
331 platform.insert() |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
332 |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
333 add_rules = [int(key[9:]) for key in req.args.keys() |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
334 if key.startswith('add_rule_')] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
335 if add_rules: |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
336 platform.rules.insert(add_rules[0] + 1, ('', '')) |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
337 return False |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
338 rm_rules = [int(key[8:]) for key in req.args.keys() |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
339 if key.startswith('rm_rule_')] |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
340 if rm_rules: |
436
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
341 if rm_rules[0] < len(platform.rules): |
cfbc9ee622d5
Finish the move of build configuration management into the admin interface.
cmlenz
parents:
435
diff
changeset
|
342 del platform.rules[rm_rules[0]] |
435
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
343 return False |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
344 |
8424a8afd1a1
Started implementing platform editing via admin interface.
cmlenz
parents:
434
diff
changeset
|
345 return True |