diff options
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 75e6ea3996..0b83b991b9 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -503,33 +503,37 @@ class Build(models.Model): | |||
503 | return Recipe.objects.filter(criteria) \ | 503 | return Recipe.objects.filter(criteria) \ |
504 | .select_related('layer_version', 'layer_version__layer') | 504 | .select_related('layer_version', 'layer_version__layer') |
505 | 505 | ||
506 | def get_custom_image_recipe_names(self): | ||
507 | """ | ||
508 | Get the names of custom image recipes for this build's project | ||
509 | as a list; this is used to screen out custom image recipes from the | ||
510 | recipes for the build by name, and to distinguish image recipes from | ||
511 | custom image recipes | ||
512 | """ | ||
513 | custom_image_recipes = \ | ||
514 | CustomImageRecipe.objects.filter(project=self.project) | ||
515 | return custom_image_recipes.values_list('name', flat=True) | ||
516 | |||
517 | def get_image_recipes(self): | 506 | def get_image_recipes(self): |
518 | """ | 507 | """ |
519 | Returns a queryset of image recipes related to this build, sorted | 508 | Returns a list of image Recipes (custom and built-in) related to this |
520 | by name | 509 | build, sorted by name; note that this has to be done in two steps, as |
510 | there's no way to get all the custom image recipes and image recipes | ||
511 | in one query | ||
521 | """ | 512 | """ |
522 | criteria = Q(is_image=True) | 513 | custom_image_recipes = self.get_custom_image_recipes() |
523 | return self.get_recipes().filter(criteria).order_by('name') | 514 | custom_image_recipe_names = custom_image_recipes.values_list('name', flat=True) |
515 | |||
516 | not_custom_image_recipes = ~Q(name__in=custom_image_recipe_names) & \ | ||
517 | Q(is_image=True) | ||
518 | |||
519 | built_image_recipes = self.get_recipes().filter(not_custom_image_recipes) | ||
520 | |||
521 | # append to the custom image recipes and sort | ||
522 | customisable_image_recipes = list( | ||
523 | itertools.chain(custom_image_recipes, built_image_recipes) | ||
524 | ) | ||
525 | |||
526 | return sorted(customisable_image_recipes, key=lambda recipe: recipe.name) | ||
524 | 527 | ||
525 | def get_custom_image_recipes(self): | 528 | def get_custom_image_recipes(self): |
526 | """ | 529 | """ |
527 | Returns a queryset of custom image recipes related to this build, | 530 | Returns a queryset of CustomImageRecipes related to this build, |
528 | sorted by name | 531 | sorted by name |
529 | """ | 532 | """ |
530 | custom_image_recipe_names = self.get_custom_image_recipe_names() | 533 | built_recipe_names = self.get_recipes().values_list('name', flat=True) |
531 | criteria = Q(is_image=True) & Q(name__in=custom_image_recipe_names) | 534 | criteria = Q(name__in=built_recipe_names) & Q(project=self.project) |
532 | return self.get_recipes().filter(criteria).order_by('name') | 535 | queryset = CustomImageRecipe.objects.filter(criteria).order_by('name') |
536 | return queryset | ||
533 | 537 | ||
534 | def get_outcome_text(self): | 538 | def get_outcome_text(self): |
535 | return Build.BUILD_OUTCOME[int(self.outcome)][1] | 539 | return Build.BUILD_OUTCOME[int(self.outcome)][1] |
@@ -1380,6 +1384,9 @@ class Layer(models.Model): | |||
1380 | 1384 | ||
1381 | # LayerCommit class is synced with layerindex.LayerBranch | 1385 | # LayerCommit class is synced with layerindex.LayerBranch |
1382 | class Layer_Version(models.Model): | 1386 | class Layer_Version(models.Model): |
1387 | """ | ||
1388 | A Layer_Version either belongs to a single project or no project | ||
1389 | """ | ||
1383 | search_allowed_fields = ["layer__name", "layer__summary", "layer__description", "layer__vcs_url", "dirpath", "up_branch__name", "commit", "branch"] | 1390 | search_allowed_fields = ["layer__name", "layer__summary", "layer__description", "layer__vcs_url", "dirpath", "up_branch__name", "commit", "branch"] |
1384 | build = models.ForeignKey(Build, related_name='layer_version_build', default = None, null = True) | 1391 | build = models.ForeignKey(Build, related_name='layer_version_build', default = None, null = True) |
1385 | layer = models.ForeignKey(Layer, related_name='layer_version_layer') | 1392 | layer = models.ForeignKey(Layer, related_name='layer_version_layer') |