Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id BC0DDE00BEE; Tue, 8 Dec 2015 13:18:14 -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.192.176 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-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id A3CEDE00B5A for ; Tue, 8 Dec 2015 13:17:56 -0800 (PST) Received: by pfnn128 with SMTP id n128so17963312pfn.0 for ; Tue, 08 Dec 2015 13:17:55 -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=n1n5TDmhGZukQC5kDJkJ4CRhNOywjdRUMCOevlV/Is8=; b=n8xZmbwDxV0c4Rz9NSXOq8th+WwbX9L9toGY2GRBlWbZIrMig3WPiwB3EfEcobFdOw FIMNsjCYVFovAGhbv9jDG5HCCZc9Ecyjad29qngwJVOFH5fQ3b7FYdYgHuHhnX9HGtsC 2VcF+W8D+/3RxvqrPNY3APZY2elLbchDlvG5poguPI6yEy7GGB2E9qI2V9PQWrveIkIY OCC1Yft6O7fxvzpmbK0cAVfGB7Kqr54d5j73w+rjTFGlnn0RW5Qpu29bSMU5MPnbOehB l1KH4YobVGRYb1Ku+DankZwNwTfaIm5hxUqUM7mWyriGi40QOvs8GqDerPkT7xuPX9ym A9ig== 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=n1n5TDmhGZukQC5kDJkJ4CRhNOywjdRUMCOevlV/Is8=; b=JdPLb4IvWpnjnLWkjneH99TAjiKv7l1xhwIXvv9+PheR3wU2TVYMxvDVup5u4g1MZK 06K1so34rB2oiHdUDZuwi5XTmMy4HMv53gnS32++E/8vUvclPiV0YuR2x/fEff5kP/lF /pzgyGVhv8M7oWWYhKj5Gpx6+ddRJBkKBDito66TE64AuteoUBI8bSaYAJf1JGpCTpmf J9I2xypG7HH7cAZq4eWYY8QlABOBxl1FJ171UdsmrPeXAgnPM3V0zX6ovIsO40Xn4SxF V+KiUwLYS8in0zlKABp0kCw1t9/Es0m+z9jK9UmdTNFdQ//ddRD32003qh0FyZ3nDgXw +o1A== X-Gm-Message-State: ALoCoQmdvNKJ/tosZbo7BVfbDI/Rs6JFxIGMgo113YnTNM4v+X+83izy1B75gmbuIzAuSk95sw0nxg96R725Tv6BvbS7CDOi5w== X-Received: by 10.98.80.22 with SMTP id e22mr8058686pfb.34.1449609475866; Tue, 08 Dec 2015 13:17:55 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Dec 2015 13:17:54 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Tue, 8 Dec 2015 21:16:16 +0000 Message-Id: <1449609380-11073-31-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 30/34] toaster: xhr_customrecipe_packages add GET info for package response 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:14 -0000 Add response for GET to the xhr_customrecipe_packages ReST API /xhr_customrecipe//packages/ Thie response includes the id, name, version and dependency information for the package. Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/views.py | 141 ++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 42 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 50d5afe..37a182a 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2802,11 +2802,12 @@ if True: """ ReST API to add/remove packages to/from custom recipe. - Entry point: /xhr_customrecipe//packages/ + Entry point: /xhr_customrecipe//packages/ Methods: PUT - Add package to the recipe DELETE - Delete package from the recipe + GET - Get package information Returns: {"error": "ok"} @@ -2819,53 +2820,109 @@ if True: return {"error": "Custom recipe with id=%s " "not found" % recipe_id} - if request.method == 'GET' and not package_id: - packages = recipe.package_set.values("id", "name", "version") - - return {"error": "ok", - "packages" : list(packages), - "total" : len(packages) - } + if package_id: + try: + package = ProjectPackage.objects.get(id=package_id) + except Package.DoesNotExist: + return {"error": "Package with id=%s " + "not found" % package_id} - try: - package = Package.objects.get(id=package_id) - except Package.DoesNotExist: - return {"error": "Package with id=%s " - "not found" % package_id} + if request.method == 'GET': + if not package_id: + packages = recipe.get_all_packages().values("id", + "name", + "version") + + return {"error": "ok", + "packages" : list(packages), + "total" : len(packages) + } + else: + all_current_packages = recipe.get_all_packages() + # TODO Django 1.8 will allow us to map these to nicer keys + # using annotate(myfieldname=F(field__name + + # TODO currently we ignore packgegroups as we don't have a + # way to deal with them yet. + + # Dependencies for package which aren't satisfied by the + # current packages in the custom image recipe + deps = package.package_dependencies_source.values( + "depends_on__name", + "depends_on__pk", + "depends_on__size").exclude( + Q(depends_on__in=all_current_packages) | + Q(package__name__icontains="packagegroup") + ) + + # Reverse dependencies which are needed by packages that are + # in the image + reverse_deps = package.package_dependencies_target.values( + "package__name", + "package__pk", + "package__size").exclude( + ~Q(package__pk__in=all_current_packages) | + Q(package__name__icontains="packagegroup") + ) + + total_size_deps = 0 + total_size_reverse_deps = 0 + + for dep in deps: + dep['depends_on__size_formatted'] = \ + filtered_filesizeformat(dep['depends_on__size']) + total_size_deps += dep['depends_on__size'] + + for dep in reverse_deps: + dep['package__size_formatted'] = \ + filtered_filesizeformat(dep['package__size']) + total_size_reverse_deps += dep['package__size'] + + + return {"error": "ok", + "id": package.pk, + "name": package.name, + "version": package.version, + "unsatisfied_dependencies": list(deps), + "unsatisfied_dependencies_size": total_size_deps, + "unsatisfied_dependencies_size_formatted": + filtered_filesizeformat(total_size_deps), + "reverse_dependencies": list(reverse_deps), + "reverse_dependencies_size": total_size_reverse_deps, + "reverse_dependencies_size_formatted": + filtered_filesizeformat(total_size_reverse_deps)} + + included_packages = recipe.includes_set.values_list('pk', flat=True) if request.method == 'PUT': - # As these requests are asynchronous we need to make sure we don't - # already have the package in the image recipe - if recipe.package_set.filter(Q(name=package.name) & - Q(version=package.version)).count() > 0: - return {"error" : "Package %s already in recipe" % - package.name } - - # Make a copy of this package - dependencies = _get_package_dependencies(package.pk) - - package = _copy_packge_to_recipe(recipe, package) - recipe.package_set.add(package) - - # Filter out dependencies already in the custom image - all_in_image = recipe.package_set.all().values_list('name', - flat=True) - def in_image(pkg): - return pkg['name'] not in all_in_image - - dependencies = filter(in_image, dependencies['runtime_deps']) - return {"error": "ok", - "dependencies_needed" : dependencies, - } + # If we're adding back a package which used to be included in this + # image all we need to do is remove it from the excludes + if package.pk in included_packages: + try: + recipe.excludes_set.remove(package) + return {"error": "ok"} + except Package.DoesNotExist: + return {"error": + "Package %s not found in excludes but was in " + "included list" % package.name} + + else: + recipe.appends_set.add(package) + + return {"error": "ok"} elif request.method == 'DELETE': - if package in recipe.package_set.all(): - # note that we are infact deleting the copy of the package - package.delete() + try: + # If we're deleting a package which is included we need to + # Add it to the excludes list. + if package.pk in included_packages: + recipe.excludes_set.add(package) + else: + recipe.appends_set.remove(package) return {"error": "ok"} - else: - return {"error": "Package '%s' is not in the recipe '%s'" % \ - (package.name, recipe.name)} + except CustomImageRecipe.DoesNotExist: + return {"error": "Tried to remove package that wasn't present"} + else: return {"error": "Method %s is not supported" % request.method} -- 2.1.4