diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-01-18 14:23:55 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-10 13:29:20 +0000 |
commit | efbffe3c298d57af34324639f2208e35735758a9 (patch) | |
tree | 211cb0601b9b1ed6fe6ad220cb03818080a3d725 /bitbake/lib | |
parent | b51478582f17bc9c43a92232e41246aec3e89f36 (diff) | |
download | poky-efbffe3c298d57af34324639f2208e35735758a9.tar.gz |
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>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 29 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/tables.py | 33 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/mrb_section.html | 7 | ||||
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 2 |
4 files changed, 46 insertions, 25 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index ba1eb0f2c8..1cf997cfe5 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -31,6 +31,7 @@ import django.db.models.signals | |||
31 | 31 | ||
32 | import os.path | 32 | import os.path |
33 | import re | 33 | import re |
34 | import itertools | ||
34 | 35 | ||
35 | import logging | 36 | import logging |
36 | logger = logging.getLogger("toaster") | 37 | logger = logging.getLogger("toaster") |
@@ -372,11 +373,37 @@ class Build(models.Model): | |||
372 | build_name = models.CharField(max_length=100) | 373 | build_name = models.CharField(max_length=100) |
373 | bitbake_version = models.CharField(max_length=50) | 374 | bitbake_version = models.CharField(max_length=50) |
374 | 375 | ||
376 | @staticmethod | ||
377 | def get_recent(project=None): | ||
378 | """ | ||
379 | Return recent builds as a list; if project is set, only return | ||
380 | builds for that project | ||
381 | """ | ||
382 | |||
383 | builds = Build.objects.all() | ||
384 | |||
385 | if project: | ||
386 | builds = builds.filter(project=project) | ||
387 | |||
388 | finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) | ||
389 | |||
390 | recent_builds = list(itertools.chain( | ||
391 | builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), | ||
392 | builds.filter(finished_criteria).order_by("-completed_on")[:3] | ||
393 | )) | ||
394 | |||
395 | # add percentage done property to each build; this is used | ||
396 | # to show build progress in mrb_section.html | ||
397 | for build in recent_builds: | ||
398 | build.percentDone = build.completeper() | ||
399 | |||
400 | return recent_builds | ||
401 | |||
375 | def completeper(self): | 402 | def completeper(self): |
376 | tf = Task.objects.filter(build = self) | 403 | tf = Task.objects.filter(build = self) |
377 | tfc = tf.count() | 404 | tfc = tf.count() |
378 | if tfc > 0: | 405 | if tfc > 0: |
379 | completeper = tf.exclude(order__isnull=True).count()*100/tf.count() | 406 | completeper = tf.exclude(order__isnull=True).count()*100/tfc |
380 | else: | 407 | else: |
381 | completeper = 0 | 408 | completeper = 0 |
382 | return completeper | 409 | return completeper |
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index ba2726d070..7fb3f8605e 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py | |||
@@ -28,7 +28,6 @@ from django.conf.urls import url | |||
28 | from django.core.urlresolvers import reverse, resolve | 28 | from django.core.urlresolvers import reverse, resolve |
29 | from django.http import HttpResponse | 29 | from django.http import HttpResponse |
30 | from django.views.generic import TemplateView | 30 | from django.views.generic import TemplateView |
31 | import itertools | ||
32 | 31 | ||
33 | from toastergui.tablefilter import TableFilter | 32 | from toastergui.tablefilter import TableFilter |
34 | from toastergui.tablefilter import TableFilterActionToggle | 33 | from toastergui.tablefilter import TableFilterActionToggle |
@@ -1060,17 +1059,9 @@ class BuildsTable(ToasterTable): | |||
1060 | def get_context_data(self, **kwargs): | 1059 | def get_context_data(self, **kwargs): |
1061 | context = super(BuildsTable, self).get_context_data(**kwargs) | 1060 | context = super(BuildsTable, self).get_context_data(**kwargs) |
1062 | 1061 | ||
1063 | # for the latest builds section | 1062 | # should be set in subclasses |
1064 | builds = self.get_builds() | 1063 | context['mru'] = [] |
1065 | 1064 | ||
1066 | finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) | ||
1067 | |||
1068 | latest_builds = itertools.chain( | ||
1069 | builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), | ||
1070 | builds.filter(finished_criteria).order_by("-completed_on")[:3] | ||
1071 | ) | ||
1072 | |||
1073 | context['mru'] = list(latest_builds) | ||
1074 | context['mrb_type'] = self.mrb_type | 1065 | context['mrb_type'] = self.mrb_type |
1075 | 1066 | ||
1076 | return context | 1067 | return context |
@@ -1481,6 +1472,12 @@ class AllBuildsTable(BuildsTable): | |||
1481 | static_data_name='project', | 1472 | static_data_name='project', |
1482 | static_data_template=project_template) | 1473 | static_data_template=project_template) |
1483 | 1474 | ||
1475 | def get_context_data(self, **kwargs): | ||
1476 | """ Get all builds for the recent builds area """ | ||
1477 | context = super(AllBuildsTable, self).get_context_data(**kwargs) | ||
1478 | context['mru'] = Build.get_recent() | ||
1479 | return context | ||
1480 | |||
1484 | class ProjectBuildsTable(BuildsTable): | 1481 | class ProjectBuildsTable(BuildsTable): |
1485 | """ | 1482 | """ |
1486 | Builds page for a single project; a BuildsTable, with the queryset | 1483 | Builds page for a single project; a BuildsTable, with the queryset |
@@ -1521,18 +1518,16 @@ class ProjectBuildsTable(BuildsTable): | |||
1521 | 1518 | ||
1522 | def get_context_data(self, **kwargs): | 1519 | def get_context_data(self, **kwargs): |
1523 | """ | 1520 | """ |
1521 | Get recent builds for this project, and the project itself | ||
1522 | |||
1524 | NOTE: self.project_id must be set before calling super(), | 1523 | NOTE: self.project_id must be set before calling super(), |
1525 | as it's used in get_context_data() | 1524 | as it's used in get_context_data() |
1526 | """ | 1525 | """ |
1527 | self.project_id = kwargs['pid'] | 1526 | self.project_id = kwargs['pid'] |
1528 | |||
1529 | context = super(ProjectBuildsTable, self).get_context_data(**kwargs) | 1527 | context = super(ProjectBuildsTable, self).get_context_data(**kwargs) |
1530 | context['project'] = Project.objects.get(pk=self.project_id) | ||
1531 | |||
1532 | return context | ||
1533 | |||
1534 | def get_builds(self): | ||
1535 | """ override: only return builds for the relevant project """ | ||
1536 | 1528 | ||
1537 | project = Project.objects.get(pk=self.project_id) | 1529 | project = Project.objects.get(pk=self.project_id) |
1538 | return Build.objects.filter(project=project) | 1530 | context['mru'] = Build.get_recent(project) |
1531 | context['project'] = project | ||
1532 | |||
1533 | return context | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/mrb_section.html b/bitbake/lib/toaster/toastergui/templates/mrb_section.html index 2e5eb5050b..da1253e1d5 100644 --- a/bitbake/lib/toaster/toastergui/templates/mrb_section.html +++ b/bitbake/lib/toaster/toastergui/templates/mrb_section.html | |||
@@ -165,7 +165,6 @@ $(document).ready(function(){ | |||
165 | progressTimer = window.setInterval(function() { | 165 | progressTimer = window.setInterval(function() { |
166 | libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, | 166 | libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, |
167 | function(prjInfo){ | 167 | function(prjInfo){ |
168 | |||
169 | /* These two are needed because a build can be 100% and still | 168 | /* These two are needed because a build can be 100% and still |
170 | * in progress due to the fact that the % done is updated at the | 169 | * in progress due to the fact that the % done is updated at the |
171 | * start of a task so it can be doing the last task at 100% | 170 | * start of a task so it can be doing the last task at 100% |
@@ -176,18 +175,18 @@ $(document).ready(function(){ | |||
176 | for (var i in prjInfo.builds){ | 175 | for (var i in prjInfo.builds){ |
177 | var build = prjInfo.builds[i]; | 176 | var build = prjInfo.builds[i]; |
178 | 177 | ||
179 | if (build.status === "In Progress" || | 178 | if (build.outcome === "In Progress" || |
180 | $(".progress .bar").length > 0){ | 179 | $(".progress .bar").length > 0){ |
181 | /* Update the build progress */ | 180 | /* Update the build progress */ |
182 | var percentDone; | 181 | var percentDone; |
183 | 182 | ||
184 | if (build.status !== "In Progress"){ | 183 | if (build.outcome !== "In Progress"){ |
185 | /* We have to ignore the value when it's Succeeded because it | 184 | /* We have to ignore the value when it's Succeeded because it |
186 | * goes back to 0 | 185 | * goes back to 0 |
187 | */ | 186 | */ |
188 | percentDone = 100; | 187 | percentDone = 100; |
189 | } else { | 188 | } else { |
190 | percentDone = build.build[0].completeper; | 189 | percentDone = build.percentDone; |
191 | inProgress++; | 190 | inProgress++; |
192 | } | 191 | } |
193 | 192 | ||
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 9ad2746881..da73d43c4f 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -2008,7 +2008,7 @@ if True: | |||
2008 | "completedbuilds": Build.objects.exclude(outcome = Build.IN_PROGRESS).filter(project_id = pid), | 2008 | "completedbuilds": Build.objects.exclude(outcome = Build.IN_PROGRESS).filter(project_id = pid), |
2009 | "prj" : {"name": prj.name, }, | 2009 | "prj" : {"name": prj.name, }, |
2010 | "buildrequests" : prj.build_set.filter(outcome=Build.IN_PROGRESS), | 2010 | "buildrequests" : prj.build_set.filter(outcome=Build.IN_PROGRESS), |
2011 | #"builds" : _project_recent_build_list(prj), | 2011 | "builds" : Build.get_recent(prj), |
2012 | "layers" : map(lambda x: { | 2012 | "layers" : map(lambda x: { |
2013 | "id": x.layercommit.pk, | 2013 | "id": x.layercommit.pk, |
2014 | "orderid": x.pk, | 2014 | "orderid": x.pk, |