OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from google.appengine.ext import ndb |
| 6 |
| 7 |
| 8 class BaseBuildModel(ndb.Model): # pragma: no cover |
| 9 """A base class to provide computed properties from the key. |
| 10 |
| 11 The computed properties are master name, builder name, and build number. |
| 12 Subclasses should set its key as: |
| 13 build_id = BaseBuildModel.CreateBuildId( |
| 14 master_name, builder_name, build_number) |
| 15 ndb.Key('KindName', build_id, 'Optional_KindName', optional_id, ...) |
| 16 """ |
| 17 |
| 18 @staticmethod |
| 19 def CreateBuildId(master_name, builder_name, build_number): |
| 20 return '%s/%s/%s' % (master_name, builder_name, build_number) |
| 21 |
| 22 @ndb.ComputedProperty |
| 23 def master_name(self): |
| 24 return self.key.pairs()[0][1].split('/')[0] |
| 25 |
| 26 @ndb.ComputedProperty |
| 27 def builder_name(self): |
| 28 return self.key.pairs()[0][1].split('/')[1] |
| 29 |
| 30 @ndb.ComputedProperty |
| 31 def build_number(self): |
| 32 return int(self.key.pairs()[0][1].split('/')[2]) |
OLD | NEW |