mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 09:49:33 +02:00
bitbake: toaster: move MostRecentBuildsView to its own widget
This view is specific to the builds dashboard rather than gernic api so like ToasterTable and ToasterTypeAhead we class it as a widget as it has a single purpose. Also clean up some flake8 identified issues. Original author of the code moved in this commit is Elliot Smith. (Bitbake rev: 05428514e64ec896faae4055619e149e98bc8f57) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
4d0bc8d521
commit
8ba7ccd252
@@ -33,10 +33,8 @@ from bldcontrol import bbcontroller
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.views.generic import View
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils import timezone
|
||||
from django.db.models import Q, F
|
||||
from django.db import Error
|
||||
from toastergui.templatetags.projecttags import json, sectohms, get_tasks
|
||||
from toastergui.templatetags.projecttags import filtered_filesizeformat
|
||||
|
||||
logger = logging.getLogger("toaster")
|
||||
@@ -227,112 +225,6 @@ class XhrLayer(View):
|
||||
})
|
||||
|
||||
|
||||
class MostRecentBuildsView(View):
|
||||
def _was_yesterday_or_earlier(self, completed_on):
|
||||
now = timezone.now()
|
||||
delta = now - completed_on
|
||||
|
||||
if delta.days >= 1:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""
|
||||
Returns a list of builds in JSON format.
|
||||
"""
|
||||
project = None
|
||||
|
||||
project_id = request.GET.get('project_id', None)
|
||||
if project_id:
|
||||
try:
|
||||
project = Project.objects.get(pk=project_id)
|
||||
except:
|
||||
# if project lookup fails, assume no project
|
||||
pass
|
||||
|
||||
recent_build_objs = Build.get_recent(project)
|
||||
recent_builds = []
|
||||
|
||||
for build_obj in recent_build_objs:
|
||||
dashboard_url = reverse('builddashboard', args=(build_obj.pk,))
|
||||
buildtime_url = reverse('buildtime', args=(build_obj.pk,))
|
||||
rebuild_url = \
|
||||
reverse('xhr_buildrequest', args=(build_obj.project.pk,))
|
||||
cancel_url = \
|
||||
reverse('xhr_buildrequest', args=(build_obj.project.pk,))
|
||||
|
||||
build = {}
|
||||
build['id'] = build_obj.pk
|
||||
build['dashboard_url'] = dashboard_url
|
||||
|
||||
buildrequest_id = None
|
||||
if hasattr(build_obj, 'buildrequest'):
|
||||
buildrequest_id = build_obj.buildrequest.pk
|
||||
build['buildrequest_id'] = buildrequest_id
|
||||
|
||||
build['recipes_parsed_percentage'] = \
|
||||
int((build_obj.recipes_parsed /
|
||||
build_obj.recipes_to_parse) * 100)
|
||||
|
||||
tasks_complete_percentage = 0
|
||||
if build_obj.outcome in (Build.SUCCEEDED, Build.FAILED):
|
||||
tasks_complete_percentage = 100
|
||||
elif build_obj.outcome == Build.IN_PROGRESS:
|
||||
tasks_complete_percentage = build_obj.completeper()
|
||||
build['tasks_complete_percentage'] = tasks_complete_percentage
|
||||
|
||||
build['state'] = build_obj.get_state()
|
||||
|
||||
build['errors'] = build_obj.errors.count()
|
||||
build['dashboard_errors_url'] = dashboard_url + '#errors'
|
||||
|
||||
build['warnings'] = build_obj.warnings.count()
|
||||
build['dashboard_warnings_url'] = dashboard_url + '#warnings'
|
||||
|
||||
build['buildtime'] = sectohms(build_obj.timespent_seconds)
|
||||
build['buildtime_url'] = buildtime_url
|
||||
|
||||
build['rebuild_url'] = rebuild_url
|
||||
build['cancel_url'] = cancel_url
|
||||
|
||||
build['is_default_project_build'] = build_obj.project.is_default
|
||||
|
||||
build['build_targets_json'] = \
|
||||
json(get_tasks(build_obj.target_set.all()))
|
||||
|
||||
# convert completed_on time to user's timezone
|
||||
completed_on = timezone.localtime(build_obj.completed_on)
|
||||
|
||||
completed_on_template = '%H:%M'
|
||||
if self._was_yesterday_or_earlier(completed_on):
|
||||
completed_on_template = '%d/%m/%Y ' + completed_on_template
|
||||
build['completed_on'] = completed_on.strftime(
|
||||
completed_on_template)
|
||||
|
||||
targets = []
|
||||
target_objs = build_obj.get_sorted_target_list()
|
||||
for target_obj in target_objs:
|
||||
if target_obj.task:
|
||||
targets.append(target_obj.target + ':' + target_obj.task)
|
||||
else:
|
||||
targets.append(target_obj.target)
|
||||
build['targets'] = ' '.join(targets)
|
||||
|
||||
# abbreviated form of the full target list
|
||||
abbreviated_targets = ''
|
||||
num_targets = len(targets)
|
||||
if num_targets > 0:
|
||||
abbreviated_targets = targets[0]
|
||||
if num_targets > 1:
|
||||
abbreviated_targets += (' +%s' % (num_targets - 1))
|
||||
build['targets_abbreviated'] = abbreviated_targets
|
||||
|
||||
recent_builds.append(build)
|
||||
|
||||
return JsonResponse(recent_builds, safe=False)
|
||||
|
||||
|
||||
class XhrCustomRecipe(View):
|
||||
""" Create a custom image recipe """
|
||||
|
||||
|
||||
Reference in New Issue
Block a user