]>
Commit | Line | Data |
---|---|---|
f6e6ff79 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import tornado.web | |
4 | ||
2c909128 | 5 | from .handlers_base import BaseHandler |
f6e6ff79 MT |
6 | |
7 | class BuildsHandler(BaseHandler): | |
8 | def get(self): | |
eedc6432 MT |
9 | limit = self.get_argument("limit", None) |
10 | try: | |
11 | limit = int(limit) | |
12 | except (TypeError, ValueError): | |
13 | limit = 25 | |
14 | ||
15 | builds = self.pakfire.builds.get_all(limit=limit) | |
f6e6ff79 MT |
16 | |
17 | self.render("build-index.html", builds=builds) | |
18 | ||
19 | ||
20 | class BuildBaseHandler(BaseHandler): | |
21 | def get_build(self, uuid): | |
22 | build = self.pakfire.builds.get_by_uuid(uuid) | |
23 | if not build: | |
24 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
25 | ||
26 | return build | |
27 | ||
28 | ||
29 | class BuildDetailHandler(BuildBaseHandler): | |
30 | def get(self, uuid): | |
31 | build = self.get_build(uuid) | |
32 | ||
33 | # Cache the log. | |
34 | log = build.get_log() | |
35 | ||
36 | if build.repo: | |
d629da45 | 37 | next_repo = build.repo.next |
f6e6ff79 MT |
38 | else: |
39 | next_repo = None | |
40 | ||
41 | # Bugs. | |
42 | bugs = build.get_bugs() | |
43 | ||
44 | self.render("build-detail.html", build=build, log=log, pkg=build.pkg, | |
45 | distro=build.distro, bugs=bugs, repo=build.repo, next_repo=next_repo) | |
46 | ||
47 | ||
48 | class BuildDeleteHandler(BuildBaseHandler): | |
49 | @tornado.web.authenticated | |
50 | def get(self, uuid): | |
51 | build = self.get_build(uuid) | |
52 | ||
53 | # Check if the user has got sufficient rights to do this modification. | |
54 | if not build.has_perm(self.current_user): | |
55 | raise tornado.web.HTTPError(403) | |
56 | ||
57 | # Check if the user confirmed the action. | |
58 | confirmed = self.get_argument("confirmed", None) | |
59 | if confirmed: | |
60 | # Save the name of the package to redirect the user | |
61 | # to the other packages of that name. | |
62 | package_name = build.pkg.name | |
63 | ||
64 | # Delete the build and everything that comes with it. | |
a08fbdef MT |
65 | with self.db.transaction(): |
66 | build.delete() | |
f6e6ff79 MT |
67 | |
68 | return self.redirect("/package/%s" % package_name) | |
69 | ||
70 | self.render("build-delete.html", build=build) | |
71 | ||
72 | ||
73 | class BuildBugsHandler(BaseHandler): | |
74 | @tornado.web.authenticated | |
75 | def get(self, uuid): | |
76 | build = self.pakfire.builds.get_by_uuid(uuid) | |
77 | if not build: | |
78 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
79 | ||
80 | # Check if the user has got the right to alter this build. | |
81 | if not build.has_perm(self.current_user): | |
82 | raise tornado.web.HTTPError(403) | |
83 | ||
84 | # Bugs. | |
85 | fixed_bugs = build.get_bugs() | |
86 | open_bugs = [] | |
87 | ||
88 | for bug in self.pakfire.bugzilla.get_bugs_from_component(build.pkg.name): | |
89 | if bug in fixed_bugs: | |
90 | continue | |
91 | ||
92 | open_bugs.append(bug) | |
93 | ||
94 | self.render("build-bugs.html", build=build, pkg=build.pkg, | |
95 | fixed_bugs=fixed_bugs, open_bugs=open_bugs) | |
96 | ||
97 | @tornado.web.authenticated | |
98 | def post(self, uuid): | |
99 | build = self.pakfire.builds.get_by_uuid(uuid) | |
100 | if not build: | |
101 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
102 | ||
103 | # Check if the user has got the right to alter this build. | |
104 | if not build.has_perm(self.current_user): | |
105 | raise tornado.web.HTTPError(403) | |
106 | ||
107 | action = self.get_argument("action", None) | |
108 | bugid = self.get_argument("bugid") | |
109 | ||
110 | # Convert the bug id to integer. | |
111 | try: | |
112 | bugid = int(bugid) | |
113 | except ValueError: | |
114 | raise tornado.web.HTTPError(400, "Bad bug id given: %s" % bugid) | |
115 | ||
116 | if action == "add": | |
117 | # Add bug to the build. | |
118 | build.add_bug(bugid, user=self.current_user) | |
119 | ||
120 | elif action == "remove": | |
121 | # Remove bug from the build. | |
122 | build.rem_bug(bugid, user=self.current_user) | |
123 | ||
124 | else: | |
125 | raise tornado.web.HTTPError(400, "Unhandled action: %s" % action) | |
126 | ||
127 | self.redirect("/build/%s/bugs" % build.uuid) | |
128 | ||
129 | ||
62c7e7cd MT |
130 | class BuildsCommentsHandler(BaseHandler): |
131 | def get(self, user_name=None): | |
132 | user = None | |
133 | if user_name: | |
134 | user = self.pakfire.users.get_by_name(user_name) | |
135 | ||
136 | limit = self.get_argument("limit", 10) | |
137 | offset = self.get_argument("offset", 0) | |
138 | ||
139 | try: | |
140 | limit = int(limit) | |
141 | offset = int(offset) | |
142 | except: | |
143 | raise tornado.web.HTTPError(400) | |
144 | ||
145 | # Try to get one more comment than requested and check if there | |
146 | # is a next page that it to be shown. | |
147 | comments = self.pakfire.builds.get_comments(limit=limit + 1, | |
148 | offset=offset, user=user) | |
149 | ||
150 | # Set markers for next and prev pages. | |
151 | have_next = len(comments) > limit | |
152 | have_prev = offset > limit | |
153 | ||
154 | # Remove the extra element from the list. | |
155 | comments = comments[:limit] | |
156 | ||
157 | self.render("builds/comments.html", comments=comments, limit=limit, | |
158 | offset=offset + limit, user=user, have_prev=have_prev, have_next=have_next) | |
159 | ||
160 | ||
f6e6ff79 MT |
161 | class BuildStateHandler(BaseHandler): |
162 | def get(self, uuid): | |
163 | build = self.pakfire.builds.get_by_uuid(uuid) | |
164 | if not build: | |
165 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
166 | ||
167 | self.render("build-state.html", build=build) | |
168 | ||
169 | @tornado.web.authenticated | |
170 | def post(self, uuid): | |
171 | build = self.pakfire.builds.get_by_uuid(uuid) | |
172 | if not build: | |
173 | raise tornado.web.HTTPError(404, "No such build: %s" % uuid) | |
174 | ||
175 | # Check if user has the right to perform this action. | |
176 | if not build.has_perm(self.current_user): | |
177 | raise tornado.web.HTTPError(403, "User is not allowed to perform this action") | |
178 | ||
179 | # Check if given state is valid. | |
180 | state = self.get_argument("state", None) | |
181 | if not state in ("broken", "unbreak", "obsolete"): | |
182 | raise tornado.web.HTTPError(400, "Invalid argument given: %s" % state) | |
183 | ||
184 | # XXX this is not quite accurate | |
185 | if state == "unbreak": | |
186 | state = "stable" | |
187 | ||
188 | rem_from_repo = self.get_argument("rem_from_repo", False) | |
189 | if rem_from_repo == "on": | |
190 | rem_from_repo = True | |
191 | ||
192 | # Perform the state change. | |
193 | build.update_state(state, user=self.current_user, remove=rem_from_repo) | |
194 | ||
195 | self.redirect("/build/%s" % build.uuid) | |
196 | ||
197 | ||
198 | class BuildQueueHandler(BaseHandler): | |
199 | def get(self): | |
6782ce55 MT |
200 | self.render("build-queue.html", jobs=self.backend.jobqueue, |
201 | average_waiting_time=self.backend.jobqueue.average_waiting_time) | |
f6e6ff79 MT |
202 | |
203 | ||
204 | class BuildDetailCommentHandler(BaseHandler): | |
205 | @tornado.web.authenticated | |
206 | def post(self, uuid): | |
207 | build = self.pakfire.builds.get_by_uuid(uuid) | |
208 | ||
209 | if not build: | |
210 | raise tornado.web.HTTPError(404, "Build not found") | |
211 | ||
212 | vote = self.get_argument("vote", "none") | |
213 | ||
214 | if vote == "up": | |
215 | vote = 1 | |
216 | elif vote == "down": | |
217 | vote = -1 | |
218 | else: | |
219 | vote = 0 | |
220 | ||
221 | text = self.get_argument("text", "") | |
222 | ||
223 | # Add a new comment to the build. | |
224 | if text or vote: | |
225 | build.add_comment(self.current_user, text, vote) | |
226 | ||
227 | # Redirect to the build detail page. | |
228 | self.redirect("/build/%s" % build.uuid) | |
229 | ||
230 | ||
231 | class BuildManageHandler(BaseHandler): | |
232 | @tornado.web.authenticated | |
233 | def get(self, uuid): | |
234 | build = self.pakfire.builds.get_by_uuid(uuid) | |
235 | if not build: | |
236 | raise tornado.web.HTTPError(404, "Build not found: %s" % uuid) | |
237 | ||
238 | mode = "user" | |
239 | if self.current_user.is_admin(): | |
240 | mode = self.get_argument("mode", "user") | |
241 | ||
242 | # Get the next repo. | |
243 | if build.repo: | |
d629da45 | 244 | next_repo = build.repo.next |
f6e6ff79 MT |
245 | else: |
246 | next_repo = build.distro.first_repo | |
247 | ||
248 | self.render("build-manage.html", mode=mode, build=build, | |
249 | distro=build.distro, repo=build.repo, next_repo=next_repo) | |
250 | ||
251 | @tornado.web.authenticated | |
252 | def post(self, uuid): | |
253 | build = self.pakfire.builds.get_by_uuid(uuid) | |
254 | if not build: | |
255 | raise tornado.web.HTTPError(404, "Build not found: %s" % uuid) | |
256 | ||
257 | # check for sufficient permissions | |
258 | if not build.has_perm(self.current_user): | |
259 | raise tornado.web.HTTPError(403) | |
260 | ||
261 | action = self.get_argument("action") | |
262 | assert action in ("push", "unpush") | |
263 | ||
264 | current_repo = build.repo | |
265 | ||
266 | if action == "unpush": | |
267 | current_repo.rem_build(build, user=self.current_user) | |
268 | ||
269 | elif action == "push": | |
270 | repo_name = self.get_argument("repo") | |
271 | next_repo = build.distro.get_repo(repo_name) | |
272 | ||
273 | if not next_repo: | |
274 | raise tornado.web.HTTPError(404, "No such repository: %s" % next_repo) | |
275 | ||
276 | if not self.current_user.is_admin(): | |
d629da45 | 277 | if not distro.repo.next == next_repo: |
f6e6ff79 MT |
278 | raise tornado.web.HTTPError(403) |
279 | ||
280 | if current_repo: | |
281 | current_repo.move_build(build, next_repo, user=self.current_user) | |
282 | else: | |
283 | next_repo.add_build(build, user=self.current_user) | |
284 | ||
285 | self.redirect("/build/%s" % build.uuid) | |
286 | ||
287 | ||
288 | class BuildPriorityHandler(BaseHandler): | |
289 | @tornado.web.authenticated | |
290 | def get(self, uuid): | |
291 | build = self.pakfire.builds.get_by_uuid(uuid) | |
292 | ||
293 | if not build: | |
294 | raise tornado.web.HTTPError(404, "Build not found") | |
295 | ||
296 | self.render("build-priority.html", build=build) | |
297 | ||
298 | @tornado.web.authenticated | |
299 | def post(self, uuid): | |
300 | build = self.pakfire.builds.get_by_uuid(uuid) | |
301 | ||
302 | if not build: | |
303 | raise tornado.web.HTTPError(404, "Build not found") | |
304 | ||
305 | # Get the priority from the request data and convert it to an integer. | |
306 | # If that cannot be done, we default to zero. | |
307 | prio = self.get_argument("priority") | |
308 | try: | |
309 | prio = int(prio) | |
310 | except TypeError: | |
311 | prio = 0 | |
312 | ||
313 | # Check if the value is in a valid range. | |
314 | if not prio in (-2, -1, 0, 1, 2): | |
315 | prio = 0 | |
316 | ||
317 | # Save priority. | |
318 | build.priority = prio | |
319 | ||
320 | self.redirect("/build/%s" % build.uuid) | |
321 | ||
322 | ||
323 | class BuildWatchersHandler(BaseHandler): | |
324 | def get(self, uuid): | |
325 | build = self.pakfire.builds.get_by_uuid(uuid) | |
326 | ||
327 | if not build: | |
328 | raise tornado.web.HTTPError(404, "Build not found") | |
329 | ||
330 | # Get a list of all watchers and sort them by their realname. | |
331 | watchers = build.get_watchers() | |
332 | watchers.sort(key=lambda watcher: watcher.realname) | |
333 | ||
334 | self.render("builds-watchers-list.html", build=build, watchers=watchers) | |
335 | ||
336 | ||
337 | class BuildWatchersAddHandler(BaseHandler): | |
338 | @tornado.web.authenticated | |
339 | def get(self, uuid, error_msg=None): | |
340 | build = self.pakfire.builds.get_by_uuid(uuid) | |
341 | ||
342 | if not build: | |
343 | raise tornado.web.HTTPError(404, "Build not found") | |
344 | ||
345 | # Get a list of all users that are currently watching this build. | |
346 | watchers = build.get_watchers() | |
347 | ||
348 | self.render("builds-watchers-add.html", error_msg=error_msg, | |
349 | build=build, users=self.pakfire.users.get_all(), watchers=watchers) | |
350 | ||
351 | @tornado.web.authenticated | |
352 | def post(self, uuid): | |
353 | build = self.pakfire.builds.get_by_uuid(uuid) | |
354 | ||
355 | if not build: | |
356 | raise tornado.web.HTTPError(404, "Build not found") | |
357 | ||
358 | # Get the user id of the new watcher. | |
359 | user_id = self.current_user.id | |
360 | ||
361 | if self.current_user.is_admin(): | |
362 | user_id = self.get_argument("user_id", self.current_user.id) | |
363 | assert user_id | |
364 | ||
365 | user = self.pakfire.users.get_by_id(user_id) | |
366 | if not user: | |
367 | _ = self.locale.translate | |
368 | error_msg = _("User not found.") | |
369 | ||
370 | return self.get(uuid, error_msg=error_msg) | |
371 | ||
372 | # Actually add the user to the list of watchers. | |
373 | build.add_watcher(user) | |
374 | ||
375 | # Send user back to the build detail page. | |
376 | self.redirect("/build/%s" % build.uuid) | |
377 | ||
378 | ||
379 | class BuildListHandler(BaseHandler): | |
380 | def get(self): | |
381 | builder = self.get_argument("builder", None) | |
382 | state = self.get_argument("state", None) | |
383 | ||
384 | builds = self.pakfire.builds.get_latest(state=state, builder=builder, | |
385 | limit=25) | |
386 | ||
387 | self.render("build-list.html", builds=builds) | |
388 | ||
389 | ||
390 | class BuildFilterHandler(BaseHandler): | |
391 | def get(self): | |
392 | builders = self.pakfire.builders.get_all() | |
393 | distros = self.pakfire.distros.get_all() | |
394 | ||
395 | self.render("build-filter.html", builders=builders, distros=distros) | |
396 |