1d0825bca7fe65beaee391d30da42e937db621564Steve Block# Copyright (C) 2009 Google Inc. All rights reserved.
2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# Redistribution and use in source and binary forms, with or without
4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# modification, are permitted provided that the following conditions are
5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# met:
6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Redistributions of source code must retain the above copyright
8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# notice, this list of conditions and the following disclaimer.
9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Redistributions in binary form must reproduce the above
10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# copyright notice, this list of conditions and the following disclaimer
11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# in the documentation and/or other materials provided with the
12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# distribution.
13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#     * Neither the name of Google Inc. nor the names of its
14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# contributors may be used to endorse or promote products derived from
15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# this software without specific prior written permission.
16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#
17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
29d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom google.appengine.api import users
30d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom google.appengine.ext import webapp, db
31d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom google.appengine.ext.webapp import template
32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
33dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom handlers.updatebase import UpdateBase
34d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom model.attachment import Attachment
35d0825bca7fe65beaee391d30da42e937db621564Steve Blockfrom model.queuestatus import QueueStatus
36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
38dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass UpdateStatus(UpdateBase):
39d0825bca7fe65beaee391d30da42e937db621564Steve Block    def get(self):
40d0825bca7fe65beaee391d30da42e937db621564Steve Block        self.response.out.write(template.render("templates/updatestatus.html", None))
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
426c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    def _queue_status_from_request(self):
43d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status = QueueStatus()
44643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
456c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        # FIXME: I think this can be removed, no one uses it.
46d0825bca7fe65beaee391d30da42e937db621564Steve Block        if users.get_current_user():
47d0825bca7fe65beaee391d30da42e937db621564Steve Block            queue_status.author = users.get_current_user()
48643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
49d0825bca7fe65beaee391d30da42e937db621564Steve Block        bug_id = self._int_from_request("bug_id")
50d0825bca7fe65beaee391d30da42e937db621564Steve Block        patch_id = self._int_from_request("patch_id")
51d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_name = self.request.get("queue_name")
52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        bot_id = self.request.get("bot_id")
53d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.queue_name = queue_name
54a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        queue_status.bot_id = bot_id
55d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.active_bug_id = bug_id
56d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.active_patch_id = patch_id
57d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.message = self.request.get("status")
58d0825bca7fe65beaee391d30da42e937db621564Steve Block        results_file = self.request.get("results_file")
59d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.results_file = db.Blob(str(results_file))
606c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        return queue_status
616c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
626c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen    def post(self):
636c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        queue_status = self._queue_status_from_request()
64d0825bca7fe65beaee391d30da42e937db621564Steve Block        queue_status.put()
656c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        Attachment.dirty(queue_status.active_patch_id)
66d0825bca7fe65beaee391d30da42e937db621564Steve Block        self.response.out.write(queue_status.key().id())
67