diff options
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
| -rw-r--r-- | bitbake/lib/toaster/orm/models.py | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 7e0cf9676a..b7975ef865 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
| @@ -29,6 +29,9 @@ from django.core import validators | |||
| 29 | from django.conf import settings | 29 | from django.conf import settings |
| 30 | import django.db.models.signals | 30 | import django.db.models.signals |
| 31 | 31 | ||
| 32 | import os.path | ||
| 33 | import re | ||
| 34 | |||
| 32 | import logging | 35 | import logging |
| 33 | logger = logging.getLogger("toaster") | 36 | logger = logging.getLogger("toaster") |
| 34 | 37 | ||
| @@ -234,6 +237,14 @@ class Project(models.Model): | |||
| 234 | except (Build.DoesNotExist,IndexError): | 237 | except (Build.DoesNotExist,IndexError): |
| 235 | return( "not_found" ) | 238 | return( "not_found" ) |
| 236 | 239 | ||
| 240 | def get_last_build_extensions(self): | ||
| 241 | """ | ||
| 242 | Get list of file name extensions for images produced by the most | ||
| 243 | recent build | ||
| 244 | """ | ||
| 245 | last_build = Build.objects.get(pk = self.get_last_build_id()) | ||
| 246 | return last_build.get_image_file_extensions() | ||
| 247 | |||
| 237 | def get_last_imgfiles(self): | 248 | def get_last_imgfiles(self): |
| 238 | build_id = self.get_last_build_id | 249 | build_id = self.get_last_build_id |
| 239 | if (-1 == build_id): | 250 | if (-1 == build_id): |
| @@ -376,6 +387,57 @@ class Build(models.Model): | |||
| 376 | eta += ((eta - self.started_on)*(100-completeper))/completeper | 387 | eta += ((eta - self.started_on)*(100-completeper))/completeper |
| 377 | return eta | 388 | return eta |
| 378 | 389 | ||
| 390 | def get_image_file_extensions(self): | ||
| 391 | """ | ||
| 392 | Get list of file name extensions for images produced by this build | ||
| 393 | """ | ||
| 394 | targets = Target.objects.filter(build_id = self.id) | ||
| 395 | extensions = [] | ||
| 396 | |||
| 397 | # pattern to match against file path for building extension string | ||
| 398 | pattern = re.compile('\.([^\.]+?)$') | ||
| 399 | |||
| 400 | for target in targets: | ||
| 401 | if (not target.is_image): | ||
| 402 | continue | ||
| 403 | |||
| 404 | target_image_files = Target_Image_File.objects.filter(target_id = target.id) | ||
| 405 | |||
| 406 | for target_image_file in target_image_files: | ||
| 407 | file_name = os.path.basename(target_image_file.file_name) | ||
| 408 | suffix = '' | ||
| 409 | |||
| 410 | continue_matching = True | ||
| 411 | |||
| 412 | # incrementally extract the suffix from the file path, | ||
| 413 | # checking it against the list of valid suffixes at each | ||
| 414 | # step; if the path is stripped of all potential suffix | ||
| 415 | # parts without matching a valid suffix, this returns all | ||
| 416 | # characters after the first '.' in the file name | ||
| 417 | while continue_matching: | ||
| 418 | matches = pattern.search(file_name) | ||
| 419 | |||
| 420 | if None == matches: | ||
| 421 | continue_matching = False | ||
| 422 | suffix = re.sub('^\.', '', suffix) | ||
| 423 | continue | ||
| 424 | else: | ||
| 425 | suffix = matches.group(1) + suffix | ||
| 426 | |||
| 427 | if suffix in Target_Image_File.SUFFIXES: | ||
| 428 | continue_matching = False | ||
| 429 | continue | ||
| 430 | else: | ||
| 431 | # reduce the file name and try to find the next | ||
| 432 | # segment from the path which might be part | ||
| 433 | # of the suffix | ||
| 434 | file_name = re.sub('.' + matches.group(1), '', file_name) | ||
| 435 | suffix = '.' + suffix | ||
| 436 | |||
| 437 | if not suffix in extensions: | ||
| 438 | extensions.append(suffix) | ||
| 439 | |||
| 440 | return ', '.join(extensions) | ||
| 379 | 441 | ||
| 380 | def get_sorted_target_list(self): | 442 | def get_sorted_target_list(self): |
| 381 | tgts = Target.objects.filter(build_id = self.id).order_by( 'target' ); | 443 | tgts = Target.objects.filter(build_id = self.id).order_by( 'target' ); |
| @@ -418,7 +480,7 @@ class Build(models.Model): | |||
| 418 | return self.get_outcome_text() | 480 | return self.get_outcome_text() |
| 419 | 481 | ||
| 420 | def __str__(self): | 482 | def __str__(self): |
| 421 | return "%s %s %s" % (self.id, self.project, ",".join([t.target for t in self.target_set.all()])) | 483 | return "%d %s %s" % (self.id, self.project, ",".join([t.target for t in self.target_set.all()])) |
| 422 | 484 | ||
| 423 | 485 | ||
| 424 | # an Artifact is anything that results from a Build, and may be of interest to the user, and is not stored elsewhere | 486 | # an Artifact is anything that results from a Build, and may be of interest to the user, and is not stored elsewhere |
| @@ -609,7 +671,7 @@ class Task(models.Model): | |||
| 609 | sstate_text = property(get_sstate_text) | 671 | sstate_text = property(get_sstate_text) |
| 610 | 672 | ||
| 611 | def __unicode__(self): | 673 | def __unicode__(self): |
| 612 | return "%s(%s) %s:%s" % (self.pk, self.build.pk, self.recipe.name, self.task_name) | 674 | return "%d(%d) %s:%s" % (self.pk, self.build.pk, self.recipe.name, self.task_name) |
| 613 | 675 | ||
| 614 | class Meta: | 676 | class Meta: |
| 615 | ordering = ('order', 'recipe' ,) | 677 | ordering = ('order', 'recipe' ,) |
| @@ -1265,7 +1327,7 @@ class Layer_Version(models.Model): | |||
| 1265 | return sorted(result, key=lambda x: x.layer.name) | 1327 | return sorted(result, key=lambda x: x.layer.name) |
| 1266 | 1328 | ||
| 1267 | def __unicode__(self): | 1329 | def __unicode__(self): |
| 1268 | return "%s %s (VCS %s, Project %s)" % (self.pk, str(self.layer), self.get_vcs_reference(), self.build.project if self.build is not None else "No project") | 1330 | return "%d %s (VCS %s, Project %s)" % (self.pk, str(self.layer), self.get_vcs_reference(), self.build.project if self.build is not None else "No project") |
| 1269 | 1331 | ||
| 1270 | class Meta: | 1332 | class Meta: |
| 1271 | unique_together = ("layer_source", "up_id") | 1333 | unique_together = ("layer_source", "up_id") |
