return [self.get_by_id(b.id, b) for b in self.db.query(query)]
- def get_by_user(self, user, type=None, public=None):
+ def get_by_user(self, user, type=None):
args = []
conditions = []
elif not type or type == "release":
pass # TODO
- if public is True:
- conditions.append("public = 'Y'")
- elif public is False:
- conditions.append("public = 'N'")
-
query = "SELECT builds.* AS id FROM builds \
JOIN packages ON builds.pkg_id = packages.id"
return builds
- def get_by_name(self, name, type=None, public=None, user=None, limit=None, offset=None):
+ def get_by_name(self, name, type=None, user=None, limit=None, offset=None):
args = [name,]
conditions = [
"packages.name = %s",
args.append(type)
or_conditions = []
- if public is True:
- or_conditions.append("public = 'Y'")
- elif public is False:
- or_conditions.append("public = 'N'")
-
if user and not user.is_admin():
or_conditions.append("builds.owner_id = %s")
args.append(user.id)
return [Build(self.backend, b.id, b) for b in self.db.query(query, *args)]
- def get_latest_by_name(self, name, type=None, public=None):
+ def get_latest_by_name(self, name, type=None):
query = "\
SELECT * FROM builds \
LEFT JOIN builds_latest ON builds.id = builds_latest.build_id \
query += " AND builds_latest.build_type = %s"
args.append(type)
- if public is True:
- query += " AND builds.public = %s"
- args.append("Y")
- elif public is False:
- query += " AND builds.public = %s"
- args.append("N")
-
# Get the last one only.
# Prefer release builds over scratch builds.
query += "\
if res:
return Build(self.backend, res.id, res)
- def get_active_builds(self, name, public=None):
+ def get_active_builds(self, name):
query = "\
SELECT * FROM builds \
LEFT JOIN builds_latest ON builds.id = builds_latest.build_id \
WHERE builds_latest.package_name = %s AND builds.type = %s"
args = [name, "release"]
- if public is True:
- query += " AND builds.public = %s"
- args.append("Y")
- elif public is False:
- query += " AND builds.public = %s"
- args.append("N")
-
builds = []
for row in self.db.query(query, *args):
b = Build(self.backend, row.id, row)
return build
- def get_changelog(self, name, public=None, limit=5, offset=0):
+ def get_changelog(self, name, limit=5, offset=0):
query = "SELECT builds.* FROM builds \
JOIN packages ON builds.pkg_id = packages.id \
WHERE \
packages.name = %s"
args = ["release", name,]
- if public == True:
- query += " AND builds.public = %s"
- args.append("Y")
- elif public == False:
- query += " AND builds.public = %s"
- args.append("N")
-
query += " ORDER BY builds.time_created DESC"
if limit:
return comments
- def get_build_times_summary(self, name=None, job_type=None, arch=None):
+ def get_build_times_summary(self, name=None, arch=None):
query = "\
SELECT \
builds_times.arch AS arch, \
conditions.append("packages.name = %s")
args.append(name)
- # Filter by job types.
- if job_type:
- conditions.append("builds_times.job_type = %s")
- args.append(job_type)
-
# Filter by arch.
if arch:
conditions.append("builds_times.arch = %s")
"""
self.db.execute("DELETE FROM builds_watchers WHERE build_id = %s", self.id)
- def reset(self):
- """
- Resets the whole build so it can start again (as it has never
- been started).
- """
- for job in self.jobs:
- job.reset()
-
- #self.__delete_bugs()
- self.__delete_comments()
- self.__delete_history()
- self.__delete_watchers()
-
- self.state = "building"
-
- # XXX empty log
-
@property
def info(self):
"""
def date(self):
return self.created.date()
- @property
- def public(self):
- """
- Is this build public?
- """
- return self.data.public
-
@lazy_property
def size(self):
"""
s_jobs = []
for job in self.jobs:
s_jobs.append("""<a class="state_%s %s" href="/job/%s">%s</a>""" % \
- (job.state, job.type, job.uuid, job.arch))
+ (job.state, "test" if job.test else "build", job.uuid, job.arch))
if s_jobs:
s += " [%s]" % ", ".join(s_jobs)
def critical_path(self):
return self.pkg.critical_path
- def get_jobs(self, type=None):
- """
- Returns a list of jobs of this build.
- """
- return self.backend.jobs.get_by_build(self.id, self, type=type)
+ def _get_jobs(self, query, *args):
+ ret = []
+ for job in self.backend.jobs._get_jobs(query, *args):
+ job.build = self
+ ret.append(job)
+
+ return ret
@lazy_property
def jobs(self):
"""
Get a list of all build jobs that are in this build.
"""
- return self.get_jobs(type="build")
+ return self._get_jobs("SELECT * FROM jobs \
+ WHERE build_id = %s AND test IS FALSE AND deleted_at IS NULL", self.id)
@property
def test_jobs(self):
- return self.get_jobs(type="test")
+ return self._get_jobs("SELECT * FROM jobs \
+ WHERE build_id = %s AND test IS TRUE AND deleted_at IS NULL", self.id)
@property
def all_jobs_finished(self):
return ret
- def create_autojobs(self, arches=None, type="build"):
+ def create_autojobs(self, arches=None, **kwargs):
jobs = []
# Arches may be passed to this function. If not we use all arches
if arch == "src":
continue
- job = self.add_job(arch, type=type)
+ job = self.add_job(arch, **kwargs)
jobs.append(job)
# Return all newly created jobs.
return jobs
- def add_job(self, arch, type="build"):
- job = self.backend.jobs.create(self, arch, type=type)
+ def add_job(self, arch, **kwargs):
+ job = self.backend.jobs.create(self, arch, **kwargs)
# Add new job to cache.
self.jobs.append(job)
def add_comment(self, user, text, score):
# Add the new comment to the database.
id = self.db.execute("INSERT INTO \
- builds_comments(build_id, user_id, text, credit, time_created) \
+ builds_comments(build_id, user_id, text, score, time_created) \
VALUES(%s, %s, %s, %s, NOW())",
self.id, user.id, text, score)
- # Update the credit cache
+ # Update the score cache
self.score += score
# Send the new comment to all watchers and stuff.
@lazy_property
def score(self):
- res = self.db.get("SELECT SUM(credit) AS score \
+ res = self.db.get("SELECT SUM(score) AS score \
FROM builds_comments WHERE build_id = %s", self.id)
return res.score or 0
- @property
- def credits(self):
- # XXX COMPAT
- return self.score
-
def get_commenters(self):
users = self.db.query("SELECT DISTINCT users.id AS id FROM builds_comments \
JOIN users ON builds_comments.user_id = users.id \