All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Wood <michael.g.wood@intel.com>
To: toaster@yoctoproject.org
Subject: [PATCH 20/21] toaster: buildinfohelper Create a copy of the built layer and recipe
Date: Fri, 25 Sep 2015 19:07:31 +0100	[thread overview]
Message-ID: <1443204452-32244-21-git-send-email-michael.g.wood@intel.com> (raw)
In-Reply-To: <1443204452-32244-1-git-send-email-michael.g.wood@intel.com>

Create a copy of the built layer and the recipes associated with it.
This is so that the user can view the historical information about a
build. i.e. a snapshot of the layer version and artifacts produced at
that build.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
---
 bitbake/lib/bb/ui/buildinfohelper.py | 54 +++++++++++++++++++++++++++---------
 bitbake/lib/toaster/orm/models.py    |  2 +-
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index d0efaa9..e036ef6 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -66,6 +66,7 @@ class ORMWrapper(object):
 
     def __init__(self):
         self.layer_version_objects = []
+        self.layer_version_built = []
         self.task_objects = {}
         self.recipe_objects = {}
 
@@ -254,32 +255,59 @@ class ORMWrapper(object):
 
         assert not recipe_information['file_path'].startswith("/")      # we should have layer-relative paths at all times
 
-        recipe_object, created = self._cached_get_or_create(Recipe, layer_version=recipe_information['layer_version'],
+
+        def update_recipe_obj(recipe_object):
+            object_changed = False
+            for v in vars(recipe_object):
+                if v in recipe_information.keys():
+                    object_changed = True
+                    vars(recipe_object)[v] = recipe_information[v]
+
+            if object_changed:
+                recipe_object.save()
+
+        recipe, created = self._cached_get_or_create(Recipe, layer_version=recipe_information['layer_version'],
                                      file_path=recipe_information['file_path'], pathflags = recipe_information['pathflags'])
-        if created and must_exist:
-            raise NotExisting("Recipe object created when expected to exist", recipe_information)
 
-        object_changed = False
-        for v in vars(recipe_object):
-            if v in recipe_information.keys():
-                object_changed = True
-                vars(recipe_object)[v] = recipe_information[v]
+        update_recipe_obj(recipe)
 
-        if object_changed:
-            recipe_object.save()
+        # Create a copy of the recipe for historical puposes and update it
+        for built_layer in self.layer_version_built:
+            if built_layer.layer == recipe_information['layer_version'].layer:
+                built_recipe, c = self._cached_get_or_create(Recipe,
+                        layer_version=built_layer,
+                        file_path=recipe_information['file_path'],
+                        pathflags = recipe_information['pathflags'])
+                update_recipe_obj(built_recipe)
+                break
 
-        return recipe_object
+
+
+        if created and must_exist:
+            raise NotExisting("Recipe object created when expected to exist", recipe_information)
+
+        return recipe
 
     def get_update_layer_version_object(self, build_obj, layer_obj, layer_version_information):
         if isinstance(layer_obj, Layer_Version):
             # We already found our layer version for this build so just
             # update it with the new build information
             logger.debug("We found our layer from toaster")
-            layer_obj.build = build_obj
             layer_obj.local_path = layer_version_information['local_path']
-            layer_obj.commit = layer_version_information['commit']
             layer_obj.save()
             self.layer_version_objects.append(layer_obj)
+
+            # create a new copy of this layer version as a snapshot for
+            # historical purposes
+            layer_copy, c = Layer_Version.objects.get_or_create(build=build_obj,
+                            layer=layer_obj.layer,
+                            commit=layer_version_information['commit'],
+                            local_path = layer_version_information['local_path'],
+                            )
+            logger.warning("created new historical layer version %d", layer_copy.pk)
+
+            self.layer_version_built.append(layer_copy)
+
             return layer_obj
 
         assert isinstance(build_obj, Build)
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index e0b31a9..9a052bf 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -194,7 +194,7 @@ class Project(models.Model):
         if release == None:
             release = self.release
         # layers on the same branch or layers specifically set for this project
-        queryset = Layer_Version.objects.filter((Q(up_branch__name = release.branch_name) & Q(project = None)) | Q(project = self) | Q(build__project = self))
+        queryset = Layer_Version.objects.filter(((Q(up_branch__name = release.branch_name) & Q(project = None)) | Q(project = self)) & Q(build__isnull=True))
 
         if layer_name is not None:
             # we select only a layer name
-- 
2.1.4



  parent reply	other threads:[~2015-09-25 18:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 18:07 [PATCH 00/21] michaelw/toaster/ic-5.0 Michael Wood
2015-09-25 18:07 ` [PATCH 01/21] toaster: make a workaround for old style index Michael Wood
2015-09-25 18:07 ` [PATCH 02/21] toaster: tables Move the title and name into the widget Michael Wood
2015-09-25 18:07 ` [PATCH 03/21] toaster: create custom layer and recipes for Image customisation Michael Wood
2015-09-25 18:07 ` [PATCH 04/21] toaster: widgets ToasterTable add logger to notify when cache hit Michael Wood
2015-09-25 18:07 ` [PATCH 05/21] toaster: widgets ToasterTable Add more info to search field exception Michael Wood
2015-09-25 18:07 ` [PATCH 06/21] toaster: add nocache option to the ToasterTable widget Michael Wood
2015-09-25 18:07 ` [PATCH 07/21] toaster: ToasterTable remove unused class definition Michael Wood
2015-09-25 18:07 ` [PATCH 08/21] toaster: Add CustomImageRecipe model Michael Wood
2015-09-25 18:07 ` [PATCH 09/21] toaster: add toggle for enabling image customisation feeature Michael Wood
2015-09-25 18:07 ` [PATCH 10/21] toaster: implement decorator for REST responses Michael Wood
2015-09-25 18:07 ` [PATCH 11/21] toaster: Fix indentation of jsunittests view Michael Wood
2015-09-25 18:07 ` [PATCH 12/21] toaster: Add new ReST API for Image Customisation feature Michael Wood
2015-09-25 18:07 ` [PATCH 13/21] toaster: Add ToasterTables for Image customisation feature Michael Wood
2015-09-25 18:07 ` [PATCH 14/21] toaster: Add Image customisation frontend feature Michael Wood
2015-09-25 18:07 ` [PATCH 15/21] toaster: Add test cases for new Image customisation features Michael Wood
2015-09-25 18:07 ` [PATCH 16/21] toaster: Special case the openembedded-core layer to avoid duplicates Michael Wood
2015-09-25 18:07 ` [PATCH 17/21] toaster: Create a relationship between build information and toaster layers Michael Wood
2015-09-25 18:07 ` [PATCH 18/21] toaster: Prioroitise the layer more generic vcs reference over the sha Michael Wood
2015-09-25 18:07 ` [PATCH 19/21] toaster: tables show all recipes in the layerdetails even duplicates Michael Wood
2015-09-25 18:07 ` Michael Wood [this message]
2015-09-25 18:07 ` [PATCH 21/21] Revert "bitbake: toaster: don't re-create Target objects" Michael Wood
2015-09-28 16:07   ` Additional patch Michael Wood
2015-09-28 16:07     ` [PATCH] toaster: orm remove the complicated querying on the ORM Michael Wood
2015-09-29  4:43     ` Additional patch Brian Avery

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443204452-32244-21-git-send-email-michael.g.wood@intel.com \
    --to=michael.g.wood@intel.com \
    --cc=toaster@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.