summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/orm/models.py
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-07-12 15:54:45 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-19 08:56:51 +0100
commite9808576daad137695bdedd0883ee0a35b7d870a (patch)
treebb205212fbd412d90315c5c1b45751a7b4b55125 /bitbake/lib/toaster/orm/models.py
parent5dfa120a7cf3c2cf46f165df25854e45a3b4e2f6 (diff)
downloadpoky-e9808576daad137695bdedd0883ee0a35b7d870a.tar.gz
bitbake: toaster: improve image file suffix retrieval
Refactor retrieval of suffix from image file path, making it a a method on Target_Image_File. This makes it easier to use this in the build dashboard for individual images, plus reduces the complexity of the code required to get all of the image file suffixes for a build. (Bitbake rev: 9c38de3dec74c122c2060cad37331bdafc6858ec) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: bavery <brian.avery@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
-rw-r--r--bitbake/lib/toaster/orm/models.py48
1 files changed, 11 insertions, 37 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 61737c7979..40cdb9e5c5 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -440,51 +440,21 @@ class Build(models.Model):
440 """ 440 """
441 Get list of file name extensions for images produced by this build 441 Get list of file name extensions for images produced by this build
442 """ 442 """
443 targets = Target.objects.filter(build_id = self.id)
444 extensions = [] 443 extensions = []
445 444
446 # pattern to match against file path for building extension string 445 targets = Target.objects.filter(build_id = self.id)
447 pattern = re.compile('\.([^\.]+?)$')
448
449 for target in targets: 446 for target in targets:
450 if (not target.is_image): 447 if (not target.is_image):
451 continue 448 continue
452 449
453 target_image_files = Target_Image_File.objects.filter(target_id = target.id) 450 target_image_files = Target_Image_File.objects.filter(
451 target_id=target.id)
454 452
455 for target_image_file in target_image_files: 453 for target_image_file in target_image_files:
456 file_name = os.path.basename(target_image_file.file_name) 454 extensions.append(target_image_file.suffix)
457 suffix = '' 455
458 456 extensions = list(set(extensions))
459 continue_matching = True 457 extensions.sort()
460
461 # incrementally extract the suffix from the file path,
462 # checking it against the list of valid suffixes at each
463 # step; if the path is stripped of all potential suffix
464 # parts without matching a valid suffix, this returns all
465 # characters after the first '.' in the file name
466 while continue_matching:
467 matches = pattern.search(file_name)
468
469 if None == matches:
470 continue_matching = False
471 suffix = re.sub('^\.', '', suffix)
472 continue
473 else:
474 suffix = matches.group(1) + suffix
475
476 if suffix in Target_Image_File.SUFFIXES:
477 continue_matching = False
478 continue
479 else:
480 # reduce the file name and try to find the next
481 # segment from the path which might be part
482 # of the suffix
483 file_name = re.sub('.' + matches.group(1), '', file_name)
484 suffix = '.' + suffix
485
486 if not suffix in extensions:
487 extensions.append(suffix)
488 458
489 return ', '.join(extensions) 459 return ', '.join(extensions)
490 460
@@ -658,6 +628,10 @@ class Target_Image_File(models.Model):
658 628
659 @property 629 @property
660 def suffix(self): 630 def suffix(self):
631 for suffix in Target_Image_File.SUFFIXES:
632 if self.file_name.endswith(suffix):
633 return suffix
634
661 filename, suffix = os.path.splitext(self.file_name) 635 filename, suffix = os.path.splitext(self.file_name)
662 suffix = suffix.lstrip('.') 636 suffix = suffix.lstrip('.')
663 return suffix 637 return suffix