initial import
[vuplus_webkit] / Tools / RebaselineQueueServer / handlers / builderqueue.py
1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #     * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 from urllib import unquote_plus
30
31 from google.appengine.ext import webapp
32 from google.appengine.ext.webapp import template
33 from django.utils import simplejson
34
35 from model.queueentry import QueueEntry
36
37
38 class QueueHandler(webapp.RequestHandler):
39     def get(self, builder_name):
40         self._get(unquote_plus(builder_name))
41
42     def post(self, builder_name):
43         self._post(unquote_plus(builder_name))
44
45     def _queued_test_names(self, builder_name):
46         return [entry.test for entry in QueueEntry.entries_for_builder(builder_name)]
47         
48     def _queue_list_url(self, builder_name):
49         return '/builder/%s/queue' % builder_name
50
51
52 class QueueEdit(QueueHandler):
53     def _get(self, builder_name):
54         test_names = self._queued_test_names(builder_name)
55         self.response.out.write(
56             template.render("templates/builder-queue-edit.html", {
57                 'builder_name': builder_name,
58                 'queued_test_names': simplejson.dumps(test_names),
59             }))
60
61
62 class QueueAdd(QueueHandler):
63     def _post(self, builder_name):
64         current_tests = set(self._queued_test_names(builder_name))
65         tests = set(self.request.get_all('test')).difference(current_tests)
66         
67         for test in tests:
68             QueueEntry.add(builder_name, test)
69
70         self.redirect(self._queue_list_url(builder_name))
71
72
73 class QueueRemove(QueueHandler):
74     def _post(self, builder_name):
75         tests = self.request.get_all('test')
76
77         for test in tests:
78             QueueEntry.remove(builder_name, test)
79
80         self.redirect(self._queue_list_url(builder_name))
81
82
83 class QueueHtml(QueueHandler):
84     def _get(self, builder_name):
85         self.response.out.write(
86             template.render("templates/builder-queue-list.html", {
87                     'builder_name': builder_name,
88                     'entries': QueueEntry.entries_for_builder(builder_name),
89                 }))
90
91
92 class QueueJson(QueueHandler):
93     def _get(self, builder_name):
94         queue_json = {'tests': self._queued_test_names(builder_name)}
95         self.response.out.write(simplejson.dumps(queue_json))