Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : enter_the_matrix
---------------------------------------------------------------
commit fa2693b70341cda6ee3f538390c08df0f6da07a0
Author: Richard Marko <rmarko(a)fedoraproject.org>
Date: Tue Nov 12 17:32:36 2013 +0100
[frontend] add Build <-> Chroot relation
Signed-off-by: Richard Marko <rmarko(a)fedoraproject.org>
---------------------------------------------------------------
coprs_frontend/coprs/models.py | 58 +++++++++++++++++++++++++++-------------
1 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index 41c0b3f..48cf8a0 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -199,10 +199,6 @@ class Build(db.Model, Serializer):
pkgs = db.Column(db.Text)
# was this build canceled by user?
canceled = db.Column(db.Boolean, default = False)
- ## These two are present for every build, as they might change in Copr
- ## between submitting and starting build => we want to keep them as submitted
- # list of space separated mock chroot names
- chroots = db.Column(db.Text, nullable = False)
# list of space separated additional repos
repos = db.Column(db.Text)
## the three below represent time of important events for this build
@@ -212,9 +208,6 @@ class Build(db.Model, Serializer):
ended_on = db.Column(db.Integer)
# url of the build results
results = db.Column(db.Text)
- # status as returned by backend, see build.state for value explanation
- # (TODO: this would deserve an enum)
- status = db.Column(db.Integer)
# memory requirements for backend builder
memory_reqs = db.Column(db.Integer, default = constants.DEFAULT_BUILD_MEMORY)
# maximum allowed time of build, build will fail if exceeded
@@ -226,26 +219,41 @@ class Build(db.Model, Serializer):
copr_id = db.Column(db.Integer, db.ForeignKey('copr.id'))
copr = db.relationship('Copr', backref = db.backref('builds'))
+ chroots = association_proxy('build_chroots', 'mock_chroot')
+
@property
- def state(self):
- """Return text representation of status of this
build"""
- if self.status == 1:
- return 'succeeded'
- elif self.status == 0:
- return 'failed'
+ def chroot_states(self):
+ return map(lambda chroot: chroot.status, self.build_chroots)
+
+ @property
+ def has_pending_chroot(self):
+ return helpers.StatusEnum('pending') in self.chroot_states
+
+ @property
+ def status(self):
+ """ Return build status according to build status of its chroots
"""
if self.canceled:
- return 'canceled'
- if not self.ended_on and self.started_on:
- return 'running'
- return 'pending'
+ return helpers.StatusEnum('canceled')
+
+ for state in ['failed', 'running', 'pending',
'succeeded']:
+ if helpers.StatusEnum(state) in self.chroot_states:
+ return helpers.StatusEnum(state)
+
+ @property
+ def state(self):
+ """ Return text representation of status of this build
"""
+ return helpers.StatusEnum(self.status)
@property
def cancelable(self):
- """Find out if this build is cancelable.
+ """
+ Find out if this build is cancelable.
ATM, build is cancelable only if it wasn't grabbed by backend.
"""
- return self.state == 'pending'
+
+ return self.status == helpers.StatusEnum('pending')
+
class MockChroot(db.Model, Serializer):
"""Representation of mock chroot"""
@@ -278,6 +286,18 @@ class CoprChroot(db.Model, Serializer):
single_parent=True,
cascade='all,delete,delete-orphan'))
+
+class BuildChroot(db.Model, Serializer):
+ """Representation of Build<->MockChroot
relation"""
+ mock_chroot_id = db.Column(db.Integer, db.ForeignKey('mock_chroot.id'),
+ primary_key=True)
+ mock_chroot = db.relationship('MockChroot',
backref=db.backref('builds'))
+ build_id = db.Column(db.Integer, db.ForeignKey('build.id'),
+ primary_key=True)
+ build = db.relationship('Build',
backref=db.backref('build_chroots'))
+ status = db.Column(db.Integer, default=helpers.StatusEnum('pending'))
+
+
class LegalFlag(db.Model, Serializer):
id = db.Column(db.Integer, primary_key=True)
# message from user who raised the flag (what he thinks is wrong)