diff options
| author | Michael Wood <michael.g.wood@intel.com> | 2016-09-26 13:59:29 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-09-30 16:52:21 +0100 |
| commit | 8ba7ccd25247539cbea8786026b375a2c9169aad (patch) | |
| tree | 753608bcad31b9a4ba027215261cf3a0b4daf2d8 /bitbake/lib/toaster/toastergui/api.py | |
| parent | 4d0bc8d52130fcc62c0d239fd7e0c79bec188c88 (diff) | |
| download | poky-8ba7ccd25247539cbea8786026b375a2c9169aad.tar.gz | |
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>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/api.py')
| -rw-r--r-- | bitbake/lib/toaster/toastergui/api.py | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 8876409964..5589118027 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py | |||
| @@ -33,10 +33,8 @@ from bldcontrol import bbcontroller | |||
| 33 | from django.http import HttpResponse, JsonResponse | 33 | from django.http import HttpResponse, JsonResponse |
| 34 | from django.views.generic import View | 34 | from django.views.generic import View |
| 35 | from django.core.urlresolvers import reverse | 35 | from django.core.urlresolvers import reverse |
| 36 | from django.utils import timezone | ||
| 37 | from django.db.models import Q, F | 36 | from django.db.models import Q, F |
| 38 | from django.db import Error | 37 | from django.db import Error |
| 39 | from toastergui.templatetags.projecttags import json, sectohms, get_tasks | ||
| 40 | from toastergui.templatetags.projecttags import filtered_filesizeformat | 38 | from toastergui.templatetags.projecttags import filtered_filesizeformat |
| 41 | 39 | ||
| 42 | logger = logging.getLogger("toaster") | 40 | logger = logging.getLogger("toaster") |
| @@ -227,112 +225,6 @@ class XhrLayer(View): | |||
| 227 | }) | 225 | }) |
| 228 | 226 | ||
| 229 | 227 | ||
| 230 | class MostRecentBuildsView(View): | ||
| 231 | def _was_yesterday_or_earlier(self, completed_on): | ||
| 232 | now = timezone.now() | ||
| 233 | delta = now - completed_on | ||
| 234 | |||
| 235 | if delta.days >= 1: | ||
| 236 | return True | ||
| 237 | |||
| 238 | return False | ||
| 239 | |||
| 240 | def get(self, request, *args, **kwargs): | ||
| 241 | """ | ||
| 242 | Returns a list of builds in JSON format. | ||
| 243 | """ | ||
| 244 | project = None | ||
| 245 | |||
| 246 | project_id = request.GET.get('project_id', None) | ||
| 247 | if project_id: | ||
| 248 | try: | ||
| 249 | project = Project.objects.get(pk=project_id) | ||
| 250 | except: | ||
| 251 | # if project lookup fails, assume no project | ||
| 252 | pass | ||
| 253 | |||
| 254 | recent_build_objs = Build.get_recent(project) | ||
| 255 | recent_builds = [] | ||
| 256 | |||
| 257 | for build_obj in recent_build_objs: | ||
| 258 | dashboard_url = reverse('builddashboard', args=(build_obj.pk,)) | ||
| 259 | buildtime_url = reverse('buildtime', args=(build_obj.pk,)) | ||
| 260 | rebuild_url = \ | ||
| 261 | reverse('xhr_buildrequest', args=(build_obj.project.pk,)) | ||
| 262 | cancel_url = \ | ||
| 263 | reverse('xhr_buildrequest', args=(build_obj.project.pk,)) | ||
| 264 | |||
| 265 | build = {} | ||
| 266 | build['id'] = build_obj.pk | ||
| 267 | build['dashboard_url'] = dashboard_url | ||
| 268 | |||
| 269 | buildrequest_id = None | ||
| 270 | if hasattr(build_obj, 'buildrequest'): | ||
| 271 | buildrequest_id = build_obj.buildrequest.pk | ||
| 272 | build['buildrequest_id'] = buildrequest_id | ||
| 273 | |||
| 274 | build['recipes_parsed_percentage'] = \ | ||
| 275 | int((build_obj.recipes_parsed / | ||
| 276 | build_obj.recipes_to_parse) * 100) | ||
| 277 | |||
| 278 | tasks_complete_percentage = 0 | ||
| 279 | if build_obj.outcome in (Build.SUCCEEDED, Build.FAILED): | ||
| 280 | tasks_complete_percentage = 100 | ||
| 281 | elif build_obj.outcome == Build.IN_PROGRESS: | ||
| 282 | tasks_complete_percentage = build_obj.completeper() | ||
| 283 | build['tasks_complete_percentage'] = tasks_complete_percentage | ||
| 284 | |||
| 285 | build['state'] = build_obj.get_state() | ||
| 286 | |||
| 287 | build['errors'] = build_obj.errors.count() | ||
| 288 | build['dashboard_errors_url'] = dashboard_url + '#errors' | ||
| 289 | |||
| 290 | build['warnings'] = build_obj.warnings.count() | ||
| 291 | build['dashboard_warnings_url'] = dashboard_url + '#warnings' | ||
| 292 | |||
| 293 | build['buildtime'] = sectohms(build_obj.timespent_seconds) | ||
| 294 | build['buildtime_url'] = buildtime_url | ||
| 295 | |||
| 296 | build['rebuild_url'] = rebuild_url | ||
| 297 | build['cancel_url'] = cancel_url | ||
| 298 | |||
| 299 | build['is_default_project_build'] = build_obj.project.is_default | ||
| 300 | |||
| 301 | build['build_targets_json'] = \ | ||
| 302 | json(get_tasks(build_obj.target_set.all())) | ||
| 303 | |||
| 304 | # convert completed_on time to user's timezone | ||
| 305 | completed_on = timezone.localtime(build_obj.completed_on) | ||
| 306 | |||
| 307 | completed_on_template = '%H:%M' | ||
| 308 | if self._was_yesterday_or_earlier(completed_on): | ||
| 309 | completed_on_template = '%d/%m/%Y ' + completed_on_template | ||
| 310 | build['completed_on'] = completed_on.strftime( | ||
| 311 | completed_on_template) | ||
| 312 | |||
| 313 | targets = [] | ||
| 314 | target_objs = build_obj.get_sorted_target_list() | ||
| 315 | for target_obj in target_objs: | ||
| 316 | if target_obj.task: | ||
| 317 | targets.append(target_obj.target + ':' + target_obj.task) | ||
| 318 | else: | ||
| 319 | targets.append(target_obj.target) | ||
| 320 | build['targets'] = ' '.join(targets) | ||
| 321 | |||
| 322 | # abbreviated form of the full target list | ||
| 323 | abbreviated_targets = '' | ||
| 324 | num_targets = len(targets) | ||
| 325 | if num_targets > 0: | ||
| 326 | abbreviated_targets = targets[0] | ||
| 327 | if num_targets > 1: | ||
| 328 | abbreviated_targets += (' +%s' % (num_targets - 1)) | ||
| 329 | build['targets_abbreviated'] = abbreviated_targets | ||
| 330 | |||
| 331 | recent_builds.append(build) | ||
| 332 | |||
| 333 | return JsonResponse(recent_builds, safe=False) | ||
| 334 | |||
| 335 | |||
| 336 | class XhrCustomRecipe(View): | 228 | class XhrCustomRecipe(View): |
| 337 | """ Create a custom image recipe """ | 229 | """ Create a custom image recipe """ |
| 338 | 230 | ||
