summaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-12-08 11:36:17 +0000
committerMichael Wood <michael.g.wood@intel.com>2016-02-08 17:35:46 +0000
commit0fe2c72ab82c6de2825a390fbb460b892a7a9cfc (patch)
tree2a5b52438486909c3a76e45c3848a155d31d7d17 /lib/toaster/toastergui
parent4b4b7e28d602ac5283659f806d695cc0451d292e (diff)
downloadbitbake-0fe2c72ab82c6de2825a390fbb460b892a7a9cfc.tar.gz
toaster: API allow CustomImageRecipe to be updated after creation
When we create a CustomImageRecipe we create a Layer_Version and Recipe for that Recipe to be in, we only need one Layer_Version for our Recipes so if that Layer_Version is updated by building it we need a slightly more custom version of get_or_create to take into account the fields which we expect can change but still mean that the object we want is valid and doesn't need to be created. In the Recipe case this is when we're updating an existing CustomImageRecipe as we allow people to create a recipe even when the based on recipe hasn't been built so we need to update it once a build has happened. Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: brian avery <avery.brian@gmail.com>
Diffstat (limited to 'lib/toaster/toastergui')
-rwxr-xr-xlib/toaster/toastergui/views.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 49918089d..b8f0c23de 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -2363,20 +2363,27 @@ if True:
# create custom recipe
try:
# create layer 'Custom layer' and verion if needed
- layer = Layer.objects.get_or_create(name="toaster-custom-images",
- summary="Layer for custom recipes",
- vcs_url="file:///toaster_created_layer"
- )[0]
-
- lver = Layer_Version.objects.get_or_create(
- project=params['project'],
- layer=layer,
- dirpath='toaster_created_layer',
- build=None)[0]
+ layer = Layer.objects.get_or_create(
+ name="toaster-custom-images",
+ summary="Layer for custom recipes",
+ vcs_url="file:///toaster_created_layer")[0]
+
+ # Check if we have a layer version already
+ # We don't use get_or_create here because the dirpath will change
+ # and is a required field
+ lver = Layer_Version.objects.filter(Q(project=params['project']) &
+ Q(layer=layer) &
+ Q(build=None)).last()
+ if lver == None:
+ lver, created = Layer_Version.objects.get_or_create(
+ project=params['project'],
+ layer=layer,
+ dirpath="toaster_created_layer")
# Add a dependency on our layer to the base recipe's layer
- LayerVersionDependency.objects.get_or_create(layer_version=lver,
- depends_on=params["base"].layer_version)
+ LayerVersionDependency.objects.get_or_create(
+ layer_version=lver,
+ depends_on=params["base"].layer_version)
# Add it to our current project if needed
ProjectLayer.objects.get_or_create(project=params['project'],
@@ -2384,14 +2391,21 @@ if True:
optional=False)
# Create the actual recipe
- recipe = CustomImageRecipe.objects.create(
- name=request.POST["name"],
- base_recipe=params["base"],
- project=params["project"],
- file_path=request.POST["name"],
- license="MIT",
- version="0.1",
- layer_version=lver)
+ recipe, created = CustomImageRecipe.objects.get_or_create(
+ name=request.POST["name"],
+ base_recipe=params["base"],
+ project=params["project"],
+ layer_version=lver,
+ is_image=True)
+
+ # If we created the object then setup these fields. They may get
+ # overwritten later on and cause the get_or_create to create a
+ # duplicate if they've changed.
+ if created:
+ recipe.file_path = request.POST["name"]
+ recipe.license = "MIT"
+ recipe.version = "0.1"
+ recipe.save()
except Error as err:
return {"error": "Can't create custom recipe: %s" % err}
@@ -2445,7 +2459,7 @@ if True:
{"error": <error message>}
"""
try:
- custom_recipe = CustomImageRecipe.objects.get(id=recipe_id)
+ custom_recipe = CustomImageRecipe.objects.get(id=recipe_id)
except CustomImageRecipe.DoesNotExist:
return {"error": "Custom recipe with id=%s "
"not found" % recipe_id}