aboutsummaryrefslogtreecommitdiffstats
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)
downloadopenembedded-core-contrib-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):
"""
Get list of file name extensions for images produced by this build
"""
- targets = Target.objects.filter(build_id = self.id)
extensions = []
- # pattern to match against file path for building extension string
- pattern = re.compile('\.([^\.]+?)$')
-
+ targets = Target.objects.filter(build_id = self.id)
for target in targets:
if (not target.is_image):
continue
- target_image_files = Target_Image_File.objects.filter(target_id = target.id)
+ target_image_files = Target_Image_File.objects.filter(
+ target_id=target.id)
for target_image_file in target_image_files:
- file_name = os.path.basename(target_image_file.file_name)
- suffix = ''
-
- continue_matching = True
-
- # incrementally extract the suffix from the file path,
- # checking it against the list of valid suffixes at each
- # step; if the path is stripped of all potential suffix
- # parts without matching a valid suffix, this returns all
- # characters after the first '.' in the file name
- while continue_matching:
- matches = pattern.search(file_name)
-
- if None == matches:
- continue_matching = False
- suffix = re.sub('^\.', '', suffix)
- continue
- else:
- suffix = matches.group(1) + suffix
-
- if suffix in Target_Image_File.SUFFIXES:
- continue_matching = False
- continue
- else:
- # reduce the file name and try to find the next
- # segment from the path which might be part
- # of the suffix
- file_name = re.sub('.' + matches.group(1), '', file_name)
- suffix = '.' + suffix
-
- if not suffix in extensions:
- extensions.append(suffix)
+ extensions.append(target_image_file.suffix)
+
+ extensions = list(set(extensions))
+ extensions.sort()
return ', '.join(extensions)
@@ -658,6 +628,10 @@ class Target_Image_File(models.Model):
@property
def suffix(self):
+ for suffix in Target_Image_File.SUFFIXES:
+ if self.file_name.endswith(suffix):
+ return suffix
+
filename, suffix = os.path.splitext(self.file_name)
suffix = suffix.lstrip('.')
return suffix