diff options
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
| -rw-r--r-- | bitbake/lib/toaster/orm/models.py | 29 |
1 files changed, 28 insertions, 1 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 |
