1 # Copyright (C) 2010 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.
29 from datetime import datetime
32 from google.appengine.ext import db
34 from datastorefile import DataStoreFile
37 class TestFile(DataStoreFile):
38 master = db.StringProperty()
39 builder = db.StringProperty()
40 test_type = db.StringProperty()
41 build_number = db.IntegerProperty()
44 def file_information(self):
45 return "master: %s, builder: %s, test_type: %s, build_number: %r, name: %s." % (
46 self.master, self.builder, self.test_type, self.build_number, self.name)
49 def delete_file(cls, key, master, builder, test_type, build_number, name, before, limit):
53 logging.warning("File not found, key: %s.", key)
59 files = cls.get_files(master, builder, test_type, build_number, name, before, load_data=False, limit=limit)
62 "File not found, master: %s, builder: %s, test_type:%s, name: %s, before: %s.",
63 master, builder, test_type, name, before)
72 def get_files(cls, master, builder, test_type, build_number, name, before=None, load_data=True, limit=1):
73 query = TestFile.all()
75 query = query.filter("master =", master)
77 query = query.filter("builder =", builder)
79 query = query.filter("test_type =", test_type)
80 if build_number == 'latest':
81 query = query.sort('-build_number')
82 elif build_number is not None and build_number != 'None':
83 # TestFile objects that were added to the persistent DB before the build_number
84 # property was added will have a default build_number of None. When those files
85 # appear in a list view generated from templates/showfilelist.html, the URL
86 # to get the individual file contents will have '&buildnumber=None' in it.
87 # Hence, we ignore the string 'None' in build_number query parameter.
89 query = query.filter("build_number =", int(build_number))
90 except (TypeError, ValueError):
91 logging.error("Could not convert buildnumber parameter '%s' to an integer", build_number)
94 query = query.filter("name =", name)
96 date = datetime.strptime(before, "%Y-%m-%dT%H:%M:%SZ")
97 query = query.filter("date <", date)
99 files = query.order("-date").fetch(limit)
107 def save_file(cls, file, data):
109 status_string = "Saved file. %s" % file.file_information
112 status_string = "Couldn't save file. %s" % file.file_information
114 return status_string, status_code
117 def add_file(cls, master, builder, test_type, build_number, name, data):
120 file.builder = builder
121 file.test_type = test_type
122 file.build_number = build_number
124 return cls.save_file(file, data)
126 def save(self, data):
127 if not self.save_data(data):
130 self.date = datetime.now()
135 def _delete_all(self):