bitbake: toaster: move recent builds query to model

The progress updater for the recent builds section makes a JSON
call to the project view URL to get progress for each build.
However, conversion of the builds pages to ToasterTable broke this,
as the JSON response no longer contained the data necessary to
populate the progress bars.

Move the recent builds query to the Build model, so that it is
accessible to the ToasterTables using it ("project builds" and
"all builds"), as well as to the "project" view.

Modify the code in the recent builds template to use the slightly
different objects returned by the recent builds query on Build.

(Bitbake rev: 5189252635ddc7b90c9a43aaed9f196c31e1dcad)

Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Elliot Smith
2016-01-18 14:23:55 +00:00
committed by Richard Purdie
parent b51478582f
commit efbffe3c29
4 changed files with 46 additions and 25 deletions

View File

@@ -31,6 +31,7 @@ import django.db.models.signals
import os.path
import re
import itertools
import logging
logger = logging.getLogger("toaster")
@@ -372,11 +373,37 @@ class Build(models.Model):
build_name = models.CharField(max_length=100)
bitbake_version = models.CharField(max_length=50)
@staticmethod
def get_recent(project=None):
"""
Return recent builds as a list; if project is set, only return
builds for that project
"""
builds = Build.objects.all()
if project:
builds = builds.filter(project=project)
finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED)
recent_builds = list(itertools.chain(
builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"),
builds.filter(finished_criteria).order_by("-completed_on")[:3]
))
# add percentage done property to each build; this is used
# to show build progress in mrb_section.html
for build in recent_builds:
build.percentDone = build.completeper()
return recent_builds
def completeper(self):
tf = Task.objects.filter(build = self)
tfc = tf.count()
if tfc > 0:
completeper = tf.exclude(order__isnull=True).count()*100/tf.count()
completeper = tf.exclude(order__isnull=True).count()*100/tfc
else:
completeper = 0
return completeper

View File

@@ -28,7 +28,6 @@ from django.conf.urls import url
from django.core.urlresolvers import reverse, resolve
from django.http import HttpResponse
from django.views.generic import TemplateView
import itertools
from toastergui.tablefilter import TableFilter
from toastergui.tablefilter import TableFilterActionToggle
@@ -1060,17 +1059,9 @@ class BuildsTable(ToasterTable):
def get_context_data(self, **kwargs):
context = super(BuildsTable, self).get_context_data(**kwargs)
# for the latest builds section
builds = self.get_builds()
# should be set in subclasses
context['mru'] = []
finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED)
latest_builds = itertools.chain(
builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"),
builds.filter(finished_criteria).order_by("-completed_on")[:3]
)
context['mru'] = list(latest_builds)
context['mrb_type'] = self.mrb_type
return context
@@ -1481,6 +1472,12 @@ class AllBuildsTable(BuildsTable):
static_data_name='project',
static_data_template=project_template)
def get_context_data(self, **kwargs):
""" Get all builds for the recent builds area """
context = super(AllBuildsTable, self).get_context_data(**kwargs)
context['mru'] = Build.get_recent()
return context
class ProjectBuildsTable(BuildsTable):
"""
Builds page for a single project; a BuildsTable, with the queryset
@@ -1521,18 +1518,16 @@ class ProjectBuildsTable(BuildsTable):
def get_context_data(self, **kwargs):
"""
Get recent builds for this project, and the project itself
NOTE: self.project_id must be set before calling super(),
as it's used in get_context_data()
"""
self.project_id = kwargs['pid']
context = super(ProjectBuildsTable, self).get_context_data(**kwargs)
context['project'] = Project.objects.get(pk=self.project_id)
return context
def get_builds(self):
""" override: only return builds for the relevant project """
project = Project.objects.get(pk=self.project_id)
return Build.objects.filter(project=project)
context['mru'] = Build.get_recent(project)
context['project'] = project
return context

View File

@@ -165,7 +165,6 @@ $(document).ready(function(){
progressTimer = window.setInterval(function() {
libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl,
function(prjInfo){
/* These two are needed because a build can be 100% and still
* in progress due to the fact that the % done is updated at the
* start of a task so it can be doing the last task at 100%
@@ -176,18 +175,18 @@ $(document).ready(function(){
for (var i in prjInfo.builds){
var build = prjInfo.builds[i];
if (build.status === "In Progress" ||
if (build.outcome === "In Progress" ||
$(".progress .bar").length > 0){
/* Update the build progress */
var percentDone;
if (build.status !== "In Progress"){
if (build.outcome !== "In Progress"){
/* We have to ignore the value when it's Succeeded because it
* goes back to 0
*/
percentDone = 100;
} else {
percentDone = build.build[0].completeper;
percentDone = build.percentDone;
inProgress++;
}

View File

@@ -2008,7 +2008,7 @@ if True:
"completedbuilds": Build.objects.exclude(outcome = Build.IN_PROGRESS).filter(project_id = pid),
"prj" : {"name": prj.name, },
"buildrequests" : prj.build_set.filter(outcome=Build.IN_PROGRESS),
#"builds" : _project_recent_build_list(prj),
"builds" : Build.get_recent(prj),
"layers" : map(lambda x: {
"id": x.layercommit.pk,
"orderid": x.pk,