| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import time | 29 import time |
| 30 import logging | 30 import logging |
| 31 import re | 31 import re |
| 32 import urllib | 32 import urllib |
| 33 import webapp2 |
| 33 | 34 |
| 34 from google.appengine.api import users | 35 from google.appengine.api import users |
| 35 from google.appengine.ext import webapp | |
| 36 from google.appengine.ext.webapp import template | 36 from google.appengine.ext.webapp import template |
| 37 from google.appengine.ext import db | 37 from google.appengine.ext import db |
| 38 | 38 |
| 39 from model.jsonresults import JsonResults | 39 from model.jsonresults import JsonResults |
| 40 from model.testfile import TestFile | 40 from model.testfile import TestFile |
| 41 | 41 |
| 42 PARAM_MASTER = "master" | 42 PARAM_MASTER = "master" |
| 43 PARAM_BUILDER = "builder" | 43 PARAM_BUILDER = "builder" |
| 44 PARAM_DIR = "dir" | 44 PARAM_DIR = "dir" |
| 45 PARAM_FILE = "file" | 45 PARAM_FILE = "file" |
| 46 PARAM_NAME = "name" | 46 PARAM_NAME = "name" |
| 47 PARAM_KEY = "key" | 47 PARAM_KEY = "key" |
| 48 PARAM_TEST_TYPE = "testtype" | 48 PARAM_TEST_TYPE = "testtype" |
| 49 PARAM_INCREMENTAL = "incremental" | 49 PARAM_INCREMENTAL = "incremental" |
| 50 PARAM_TEST_LIST_JSON = "testlistjson" | 50 PARAM_TEST_LIST_JSON = "testlistjson" |
| 51 PARAM_CALLBACK = "callback" | 51 PARAM_CALLBACK = "callback" |
| 52 | 52 |
| 53 | 53 |
| 54 def _replace_jsonp_callback(json, callback_name): | 54 def _replace_jsonp_callback(json, callback_name): |
| 55 if callback_name and re.search(r"^[A-Za-z0-9_]+$", callback_name): | 55 if callback_name and re.search(r"^[A-Za-z0-9_]+$", callback_name): |
| 56 if re.search(r"^[A-Za-z0-9_]+[(]", json): | 56 if re.search(r"^[A-Za-z0-9_]+[(]", json): |
| 57 return re.sub(r"^[A-Za-z0-9_]+[(]", callback_name + "(", json) | 57 return re.sub(r"^[A-Za-z0-9_]+[(]", callback_name + "(", json) |
| 58 return callback_name + "(" + json + ")" | 58 return callback_name + "(" + json + ")" |
| 59 | 59 |
| 60 return json | 60 return json |
| 61 | 61 |
| 62 | 62 |
| 63 class DeleteFile(webapp.RequestHandler): | 63 class DeleteFile(webapp2.RequestHandler): |
| 64 """Delete test file for a given builder and name from datastore.""" | 64 """Delete test file for a given builder and name from datastore.""" |
| 65 | 65 |
| 66 def get(self): | 66 def get(self): |
| 67 key = self.request.get(PARAM_KEY) | 67 key = self.request.get(PARAM_KEY) |
| 68 master = self.request.get(PARAM_MASTER) | 68 master = self.request.get(PARAM_MASTER) |
| 69 builder = self.request.get(PARAM_BUILDER) | 69 builder = self.request.get(PARAM_BUILDER) |
| 70 test_type = self.request.get(PARAM_TEST_TYPE) | 70 test_type = self.request.get(PARAM_TEST_TYPE) |
| 71 name = self.request.get(PARAM_NAME) | 71 name = self.request.get(PARAM_NAME) |
| 72 | 72 |
| 73 logging.debug( | 73 logging.debug( |
| 74 "Deleting File, master: %s, builder: %s, test_type: %s, name: %s, ke
y: %s.", | 74 "Deleting File, master: %s, builder: %s, test_type: %s, name: %s, ke
y: %s.", |
| 75 master, builder, test_type, name, key) | 75 master, builder, test_type, name, key) |
| 76 | 76 |
| 77 TestFile.delete_file(key, master, builder, test_type, name, 100) | 77 TestFile.delete_file(key, master, builder, test_type, name, 100) |
| 78 | 78 |
| 79 # Display file list after deleting the file. | 79 # Display file list after deleting the file. |
| 80 self.redirect("/testfile?master=%s&builder=%s&testtype=%s&name=%s" | 80 self.redirect("/testfile?master=%s&builder=%s&testtype=%s&name=%s" |
| 81 % (master, builder, test_type, name)) | 81 % (master, builder, test_type, name)) |
| 82 | 82 |
| 83 | 83 |
| 84 class GetFile(webapp.RequestHandler): | 84 class GetFile(webapp2.RequestHandler): |
| 85 """Get file content or list of files for given builder and name.""" | 85 """Get file content or list of files for given builder and name.""" |
| 86 | 86 |
| 87 def _get_file_list(self, master, builder, test_type, name, callback_name=Non
e): | 87 def _get_file_list(self, master, builder, test_type, name, callback_name=Non
e): |
| 88 """Get and display a list of files that matches builder and file name. | 88 """Get and display a list of files that matches builder and file name. |
| 89 | 89 |
| 90 Args: | 90 Args: |
| 91 builder: builder name | 91 builder: builder name |
| 92 test_type: type of the test | 92 test_type: type of the test |
| 93 name: file name | 93 name: file name |
| 94 """ | 94 """ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 json, date = self._get_test_list_json(master, builder, test_type) | 203 json, date = self._get_test_list_json(master, builder, test_type) |
| 204 else: | 204 else: |
| 205 json, date = self._get_file_content(master, builder, test_type, name
) | 205 json, date = self._get_file_content(master, builder, test_type, name
) |
| 206 | 206 |
| 207 if json: | 207 if json: |
| 208 json = _replace_jsonp_callback(json, callback_name) | 208 json = _replace_jsonp_callback(json, callback_name) |
| 209 | 209 |
| 210 self._serve_json(json, date) | 210 self._serve_json(json, date) |
| 211 | 211 |
| 212 | 212 |
| 213 class Upload(webapp.RequestHandler): | 213 class Upload(webapp2.RequestHandler): |
| 214 """Upload test results file to datastore.""" | 214 """Upload test results file to datastore.""" |
| 215 | 215 |
| 216 def post(self): | 216 def post(self): |
| 217 file_params = self.request.POST.getall(PARAM_FILE) | 217 file_params = self.request.POST.getall(PARAM_FILE) |
| 218 if not file_params: | 218 if not file_params: |
| 219 self.response.out.write("FAIL: missing upload file field.") | 219 self.response.out.write("FAIL: missing upload file field.") |
| 220 return | 220 return |
| 221 | 221 |
| 222 builder = self.request.get(PARAM_BUILDER) | 222 builder = self.request.get(PARAM_BUILDER) |
| 223 if not builder: | 223 if not builder: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 if errors: | 261 if errors: |
| 262 messages = "FAIL: " + "; ".join(errors) | 262 messages = "FAIL: " + "; ".join(errors) |
| 263 logging.warning(messages) | 263 logging.warning(messages) |
| 264 self.response.set_status(500, messages) | 264 self.response.set_status(500, messages) |
| 265 self.response.out.write("FAIL") | 265 self.response.out.write("FAIL") |
| 266 else: | 266 else: |
| 267 self.response.set_status(200) | 267 self.response.set_status(200) |
| 268 self.response.out.write("OK") | 268 self.response.out.write("OK") |
| 269 | 269 |
| 270 | 270 |
| 271 class UploadForm(webapp.RequestHandler): | 271 class UploadForm(webapp2.RequestHandler): |
| 272 """Show a form so user can upload a file.""" | 272 """Show a form so user can upload a file.""" |
| 273 | 273 |
| 274 def get(self): | 274 def get(self): |
| 275 template_values = { | 275 template_values = { |
| 276 "upload_url": "/testfile/upload", | 276 "upload_url": "/testfile/upload", |
| 277 } | 277 } |
| 278 self.response.out.write(template.render("templates/uploadform.html", | 278 self.response.out.write(template.render("templates/uploadform.html", |
| 279 template_values)) | 279 template_values)) |
| OLD | NEW |