From 95b8163483aac1fb336f32edfdb3b1bce3fea0ac Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 4 Oct 2016 03:10:33 +0100 Subject: Add method for getting package use flag options --- gentoobrowse-api/api/portage.ice | 1 + gentoobrowse-api/domain/extended-models.ice | 10 ++++++++++ gentoobrowse-api/service/portageimpl.cpp | 7 +++++++ gentoobrowse-api/service/portageimpl.h | 1 + .../service/sql/portage/getPackageUses.sql | 19 +++++++++++++++++++ gentoobrowse-api/unittests/testPortage.cpp | 15 +++++++++++++++ 6 files changed, 53 insertions(+) create mode 100644 gentoobrowse-api/service/sql/portage/getPackageUses.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 1f211fd..fee89f4 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -28,6 +28,7 @@ module Gentoo { idempotent PackageDependencyPackages getPackageRuntimeDependencies(int id); idempotent PackageDependencyPackages getPackagesDepending(int id); idempotent PackageMasks getPackageMasks(int id); + idempotent PackageUses getPackageUses(int id); idempotent Bug getBug(int id) throws Slicer::NoRowsReturned; idempotent Bugs getPackageBugs(int packageId); diff --git a/gentoobrowse-api/domain/extended-models.ice b/gentoobrowse-api/domain/extended-models.ice index aee4af1..1d37342 100644 --- a/gentoobrowse-api/domain/extended-models.ice +++ b/gentoobrowse-api/domain/extended-models.ice @@ -32,6 +32,14 @@ module Gentoo { IntList ebuildids; }; + class PackageUse { + string use; + bool islocal; + optional(0) string group; + string name; + string description; + }; + [ "slicer:element:package" ] sequence SearchResultPackages; [ "slicer:element:bug" ] @@ -46,6 +54,8 @@ module Gentoo { sequence PackageDependencyPackages; [ "slicer:element:mask" ] sequence PackageMasks; + [ "slicer:element:use" ] + sequence PackageUses; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index a12c8d7..198a893 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,12 @@ Portage::getPackageMasks(Ice::Int id, const Ice::Current &) return fetchCache(sql::portage::getPackageMasks, 30, id); } +Gentoo::PackageUses +Portage::getPackageUses(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackageUses, 30, id); +} + Gentoo::BugPtr Portage::getBug(Ice::Int id, const Ice::Current &) { diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 42d57e4..ea6ad5f 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -35,6 +35,7 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Gentoo::PackageDependencyPackages getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) override; Gentoo::PackageDependencyPackages getPackagesDepending(Ice::Int id, const Ice::Current &) override; Gentoo::PackageMasks getPackageMasks(Ice::Int id, const Ice::Current &) override; + Gentoo::PackageUses getPackageUses(Ice::Int id, const Ice::Current &) override; Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; diff --git a/gentoobrowse-api/service/sql/portage/getPackageUses.sql b/gentoobrowse-api/service/sql/portage/getPackageUses.sql new file mode 100644 index 0000000..50d6c0a --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackageUses.sql @@ -0,0 +1,19 @@ +SELECT eu.use, ul.use IS NOT NULL islocal, ugg.name AS group, LTRIM(COALESCE(ugg.use, eu.use), '+') AS name, + COALESCE(ul.description, ugg.description, ug.description) description +FROM gentoobrowse.ebuilds e + JOIN gentoobrowse.ebuild_uses eu + ON e.ebuildid = eu.ebuildid + LEFT OUTER JOIN gentoobrowse.use_global ug + ON LTRIM(eu.use, '+') = ug.use + LEFT OUTER JOIN gentoobrowse.use_local ul + ON LTRIM(eu.use, '+') = ul.use + AND ul.packageid = e.packageid + LEFT OUTER JOIN ( + SELECT ugs.usegroupid, ugs.name, ugg.use, ugg.description + FROM gentoobrowse.use_group ugg, gentoobrowse.use_groups ugs + WHERE ugs.usegroupid = ugg.usegroupid) ugg + ON REVERSE(SPLIT_PART(REVERSE(eu.use), '_', 1)) = ugg.use + AND LEFT(eu.use, LENGTH(eu.use) - LENGTH(SPLIT_PART(REVERSE(eu.use), '_', 1)) - 1) = ugg.name +WHERE e.packageid = ? +GROUP BY eu.use, ul.use, ul.packageid, ug.use, ugg.name, ugg.usegroupid, ugg.use, ugg.description +ORDER BY ugg.name nulls first, eu.use diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index c408a83..ab0f466 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -298,6 +298,21 @@ BOOST_AUTO_TEST_CASE( getPackageMasks ) BOOST_REQUIRE_EQUAL(629114, ms.front()->ebuildids.back()); } +BOOST_AUTO_TEST_CASE( getPackageUses ) +{ + auto us = p->getPackageUses(46436); + BOOST_REQUIRE_EQUAL(19, us.size()); + BOOST_REQUIRE_EQUAL("+keyutils", us.front()->use); + BOOST_REQUIRE_EQUAL("keyutils", us.front()->name); + BOOST_REQUIRE_EQUAL(true, us.front()->islocal); + BOOST_REQUIRE(!us[0]->group); + BOOST_REQUIRE(us[9]->group); + BOOST_REQUIRE_EQUAL("abi_mips", *us[9]->group); + BOOST_REQUIRE_EQUAL("Enable for the keyring ccache using keyutils.", us[0]->description); + BOOST_REQUIRE_EQUAL("selinux", us[6]->use); + BOOST_REQUIRE_EQUAL(false, us[2]->islocal); +} + BOOST_AUTO_TEST_CASE( getBugMissing ) { BOOST_REQUIRE_THROW(p->getBug(10), Slicer::NoRowsReturned); -- cgit v1.2.3