1 # Copyright (C) 2009 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
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
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.
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.
32 # Request a modern Django
33 from google
.appengine
.dist
import use_library
34 use_library('django', '1.1')
36 from google
.appengine
.ext
.webapp
import template
37 from google
.appengine
.api
import users
38 from google
.appengine
.ext
import webapp
, db
39 from google
.appengine
.ext
.webapp
.util
import run_wsgi_app
41 webapp
.template
.register_template_library('filters.webkit_extras')
44 class QueueStatus(db
.Model
):
45 author
= db
.UserProperty()
46 queue_name
= db
.StringProperty()
47 active_bug_id
= db
.IntegerProperty()
48 active_patch_id
= db
.IntegerProperty()
49 message
= db
.StringProperty(multiline
=True)
50 date
= db
.DateTimeProperty(auto_now_add
=True)
51 results_file
= db
.BlobProperty()
54 class MainPage(webapp
.RequestHandler
):
56 statuses_query
= QueueStatus
.all().filter('queue_name =', 'commit-queue').order('-date')
57 statuses
= statuses_query
.fetch(6)
59 return self
.response
.out
.write("No status to report.")
61 'last_status' : statuses
[0],
62 'recent_statuses' : statuses
[1:],
64 self
.response
.out
.write(template
.render('index.html', template_values
))
67 class PatchStatus(webapp
.RequestHandler
):
68 def get(self
, queue_name
, attachment_id
):
69 statuses
= QueueStatus
.all().filter('queue_name =', queue_name
).filter('active_patch_id =', int(attachment_id
)).order('-date').fetch(1)
73 self
.response
.out
.write(statuses
[0].message
)
76 class StatusSummary(object):
77 def _status_to_code(self
, status
):
84 return code_names
.get(status
, "none")
86 def _queue_name_to_code(self
, queue_name
):
88 "style-queue": "style",
90 return code_names
[queue_name
]
99 def summarize(self
, attachment_id
):
100 if self
._summary
.get(attachment_id
):
101 return self
._summary
.get(attachment_id
)
103 attachment_summary
= {}
104 for queue
in self
.queues
:
105 statuses
= QueueStatus
.all().filter('queue_name =', queue
).filter('active_patch_id =', attachment_id
).order('-date').fetch(1)
106 status_code
= self
._status
_to
_code
(statuses
[0].message
if statuses
else None)
107 queue_code
= self
._queue
_name
_to
_code
(queue
)
108 attachment_summary
[queue_code
] = status_code
110 self
._summary
[attachment_id
] = attachment_summary
111 return attachment_summary
114 class StatusBubble(webapp
.RequestHandler
):
115 def get(self
, attachment_id
):
116 status_summary
= StatusSummary()
118 "queue_status" : status_summary
.summarize(int(attachment_id
)),
120 self
.response
.out
.write(template
.render('status_bubble.html', template_values
))
123 class UpdateStatus(webapp
.RequestHandler
):
125 self
.response
.out
.write(template
.render('update_status.html', None))
127 def _int_from_request(self
, name
):
128 string_value
= self
.request
.get(name
)
130 int_value
= int(string_value
)
132 except ValueError, TypeError:
137 queue_status
= QueueStatus()
139 if users
.get_current_user():
140 queue_status
.author
= users
.get_current_user()
142 queue_name
= self
.request
.get('queue_name')
143 queue_status
.queue_name
= queue_name
144 queue_status
.active_bug_id
= self
._int
_from
_request
('bug_id')
145 queue_status
.active_patch_id
= self
._int
_from
_request
('patch_id')
146 queue_status
.message
= self
.request
.get('status')
147 results_file
= self
.request
.get("results_file")
148 queue_status
.results_file
= db
.Blob(results_file
)
153 class ShowResults(webapp
.RequestHandler
):
154 def get(self
, status_id
):
155 status
= QueueStatus
.get_by_id(int(status_id
))
159 self
.response
.headers
["Content-Type"] = "text/plain"
160 self
.response
.out
.write(status
.results_file
)
165 ('/update-status', UpdateStatus
),
166 (r
'/patch-status/(.*)/(.*)', PatchStatus
),
167 (r
'/status-bubble/(.*)', StatusBubble
),
168 (r
'/results/(.*)', ShowResults
)
171 application
= webapp
.WSGIApplication(routes
, debug
=True)
174 run_wsgi_app(application
)
176 if __name__
== "__main__":