| Index: appengine/findit/model/base_build_model.py
|
| diff --git a/appengine/findit/model/base_build_model.py b/appengine/findit/model/base_build_model.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..73a9f84dd1741ac77df461882f852899f943be6f
|
| --- /dev/null
|
| +++ b/appengine/findit/model/base_build_model.py
|
| @@ -0,0 +1,32 @@
|
| +# Copyright 2014 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +from google.appengine.ext import ndb
|
| +
|
| +
|
| +class BaseBuildModel(ndb.Model): # pragma: no cover
|
| + """A base class to provide computed properties from the key.
|
| +
|
| + The computed properties are master name, builder name, and build number.
|
| + Subclasses should set its key as:
|
| + build_id = BaseBuildModel.CreateBuildId(
|
| + master_name, builder_name, build_number)
|
| + ndb.Key('KindName', build_id, 'Optional_KindName', optional_id, ...)
|
| + """
|
| +
|
| + @staticmethod
|
| + def CreateBuildId(master_name, builder_name, build_number):
|
| + return '%s/%s/%s' % (master_name, builder_name, build_number)
|
| +
|
| + @ndb.ComputedProperty
|
| + def master_name(self):
|
| + return self.key.pairs()[0][1].split('/')[0]
|
| +
|
| + @ndb.ComputedProperty
|
| + def builder_name(self):
|
| + return self.key.pairs()[0][1].split('/')[1]
|
| +
|
| + @ndb.ComputedProperty
|
| + def build_number(self):
|
| + return int(self.key.pairs()[0][1].split('/')[2])
|
|
|