diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-12-08 11:36:17 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-10 13:29:19 +0000 |
commit | 439314c1b29f1bd835f91133fa3cda1305e70b70 (patch) | |
tree | 8253bbb85d26fab65191b90a4a110b0a95cb8d8b | |
parent | 9ea4de6d801d57a35e46cb6e433b3fbcc71d378f (diff) | |
download | poky-439314c1b29f1bd835f91133fa3cda1305e70b70.tar.gz |
bitbake: 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.
(Bitbake rev: 0fe2c72ab82c6de2825a390fbb460b892a7a9cfc)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 49918089d2..b8f0c23de8 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -2363,20 +2363,27 @@ if True: | |||
2363 | # create custom recipe | 2363 | # create custom recipe |
2364 | try: | 2364 | try: |
2365 | # create layer 'Custom layer' and verion if needed | 2365 | # create layer 'Custom layer' and verion if needed |
2366 | layer = Layer.objects.get_or_create(name="toaster-custom-images", | 2366 | layer = Layer.objects.get_or_create( |
2367 | summary="Layer for custom recipes", | 2367 | name="toaster-custom-images", |
2368 | vcs_url="file:///toaster_created_layer" | 2368 | summary="Layer for custom recipes", |
2369 | )[0] | 2369 | vcs_url="file:///toaster_created_layer")[0] |
2370 | 2370 | ||
2371 | lver = Layer_Version.objects.get_or_create( | 2371 | # Check if we have a layer version already |
2372 | project=params['project'], | 2372 | # We don't use get_or_create here because the dirpath will change |
2373 | layer=layer, | 2373 | # and is a required field |
2374 | dirpath='toaster_created_layer', | 2374 | lver = Layer_Version.objects.filter(Q(project=params['project']) & |
2375 | build=None)[0] | 2375 | Q(layer=layer) & |
2376 | Q(build=None)).last() | ||
2377 | if lver == None: | ||
2378 | lver, created = Layer_Version.objects.get_or_create( | ||
2379 | project=params['project'], | ||
2380 | layer=layer, | ||
2381 | dirpath="toaster_created_layer") | ||
2376 | 2382 | ||
2377 | # Add a dependency on our layer to the base recipe's layer | 2383 | # Add a dependency on our layer to the base recipe's layer |
2378 | LayerVersionDependency.objects.get_or_create(layer_version=lver, | 2384 | LayerVersionDependency.objects.get_or_create( |
2379 | depends_on=params["base"].layer_version) | 2385 | layer_version=lver, |
2386 | depends_on=params["base"].layer_version) | ||
2380 | 2387 | ||
2381 | # Add it to our current project if needed | 2388 | # Add it to our current project if needed |
2382 | ProjectLayer.objects.get_or_create(project=params['project'], | 2389 | ProjectLayer.objects.get_or_create(project=params['project'], |
@@ -2384,14 +2391,21 @@ if True: | |||
2384 | optional=False) | 2391 | optional=False) |
2385 | 2392 | ||
2386 | # Create the actual recipe | 2393 | # Create the actual recipe |
2387 | recipe = CustomImageRecipe.objects.create( | 2394 | recipe, created = CustomImageRecipe.objects.get_or_create( |
2388 | name=request.POST["name"], | 2395 | name=request.POST["name"], |
2389 | base_recipe=params["base"], | 2396 | base_recipe=params["base"], |
2390 | project=params["project"], | 2397 | project=params["project"], |
2391 | file_path=request.POST["name"], | 2398 | layer_version=lver, |
2392 | license="MIT", | 2399 | is_image=True) |
2393 | version="0.1", | 2400 | |
2394 | layer_version=lver) | 2401 | # If we created the object then setup these fields. They may get |
2402 | # overwritten later on and cause the get_or_create to create a | ||
2403 | # duplicate if they've changed. | ||
2404 | if created: | ||
2405 | recipe.file_path = request.POST["name"] | ||
2406 | recipe.license = "MIT" | ||
2407 | recipe.version = "0.1" | ||
2408 | recipe.save() | ||
2395 | 2409 | ||
2396 | except Error as err: | 2410 | except Error as err: |
2397 | return {"error": "Can't create custom recipe: %s" % err} | 2411 | return {"error": "Can't create custom recipe: %s" % err} |
@@ -2445,7 +2459,7 @@ if True: | |||
2445 | {"error": <error message>} | 2459 | {"error": <error message>} |
2446 | """ | 2460 | """ |
2447 | try: | 2461 | try: |
2448 | custom_recipe = CustomImageRecipe.objects.get(id=recipe_id) | 2462 | custom_recipe = CustomImageRecipe.objects.get(id=recipe_id) |
2449 | except CustomImageRecipe.DoesNotExist: | 2463 | except CustomImageRecipe.DoesNotExist: |
2450 | return {"error": "Custom recipe with id=%s " | 2464 | return {"error": "Custom recipe with id=%s " |
2451 | "not found" % recipe_id} | 2465 | "not found" % recipe_id} |