Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id D22BAE00C21; Tue, 8 Dec 2015 13:18:04 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.220.46 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id B23AAE00B02 for ; Tue, 8 Dec 2015 13:17:50 -0800 (PST) Received: by pacwq6 with SMTP id wq6so17742918pac.1 for ; Tue, 08 Dec 2015 13:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i5lg9AUG/gYRm1EzuiOmOni9LfCBPilZP9FUII5SZro=; b=fXAOxCwJiVRKJuvOWCGnqCA3Nj89BiZO9uG7faSHnrw0IQhQOXKnRlOZ7GnOqfzsRw s71vuFa7hYlRE0O9R9PL+5aIZR2Cp7qOCwBM4ND+o4Kqc/u6OnK9rsflPfI/2ruKHRNs I+GWL/cZEAyxOyCuQOf2xiFGlnZXQ1we9AMqvWz5YMEJFC0BQzftm5McSd5W8cxq/krN X1mbJFnIGu+B84y+vCZlNbGlf+zXU+mPciSQN8t8wkFBMK70PpfFHnkDna7ih3rb/GIh tI6nGKscHtsbxGi2K0xLjYsdtsb4RM8CXS/ztfKBGqtv0EAdbt3tu21CJlJzZj/TcKMM xvAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i5lg9AUG/gYRm1EzuiOmOni9LfCBPilZP9FUII5SZro=; b=JtltgOLYYtduJQG/LTbJvAvw3nhcvNrKq5HUHPKCn0EtchWRqrOQqrWbF/nOSD/+i9 9GohbEXVcgUAPmfjB1ZCLk7wlSZfDD5bw9Df14k6ar2vYgjQtphdsh0JiIR8+iYhigid xqLAYW8Y4x4157G3OM0TKQ6Z6P3/2xHKTcfDl8ayxOR69CMmRFc2ofWE9lzimtoOWM3E /CojOD6Fi63kwV8CXprKXNj+0irRsLh3plRg4/zuWvsWaiWRUuRGrDHIlNQrVvBAn80P l7uX5SxW6zcBMF9DIAANd73uLNJxPVDfT4gHJsq65FN65VMClVAHsEt/THMUD3LkrAEA nVfQ== X-Gm-Message-State: ALoCoQkrFHlOvSDze1jqfO2JCeviX4RJMhpcfzcx/iVPUv2j1ZEBUohKlCb94EdmXkkFDmM32utFw4rTp+je6/D18QluGWWMVQ== X-Received: by 10.66.192.193 with SMTP id hi1mr2986820pac.110.1449609470029; Tue, 08 Dec 2015 13:17:50 -0800 (PST) Received: from draco.ger.corp.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id v64sm6675766pfi.50.2015.12.08.13.17.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Dec 2015 13:17:49 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Tue, 8 Dec 2015 21:16:14 +0000 Message-Id: <1449609380-11073-29-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1449609380-11073-1-git-send-email-michael.g.wood@intel.com> References: <1449609380-11073-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 28/34] toaster: API allow CustomImageRecipe to be updated after creation X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2015 21:18:04 -0000 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 --- bitbake/lib/toaster/toastergui/views.py | 56 ++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index d569ffe..270229f 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2650,20 +2650,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'], @@ -2671,14 +2678,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} @@ -2732,7 +2746,7 @@ if True: {"error": } """ 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} -- 2.1.4