From af55d929088e25204b4626486c4e19070f9cefdd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 3 Oct 2016 18:43:20 +0100 Subject: Add methods for getting dependencies and masks --- gentoobrowse-api/api/portage.ice | 4 ++ gentoobrowse-api/domain/converters.cpp | 2 + gentoobrowse-api/domain/extended-models.ice | 11 ++++++ gentoobrowse-api/domain/portage-models.ice | 13 +++++++ gentoobrowse-api/service/portageimpl.cpp | 28 ++++++++++++++ gentoobrowse-api/service/portageimpl.h | 4 ++ .../service/sql/portage/getPackageDependencies.sql | 6 +++ .../service/sql/portage/getPackageMasks.sql | 7 ++++ .../sql/portage/getPackageRuntimeDependencies.sql | 7 ++++ .../service/sql/portage/getPackagesDepending.sql | 11 ++++++ gentoobrowse-api/unittests/fixtures/masksets.dat | 2 +- gentoobrowse-api/unittests/testPortage.cpp | 45 ++++++++++++++++++++++ 12 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 gentoobrowse-api/service/sql/portage/getPackageDependencies.sql create mode 100644 gentoobrowse-api/service/sql/portage/getPackageMasks.sql create mode 100644 gentoobrowse-api/service/sql/portage/getPackageRuntimeDependencies.sql create mode 100644 gentoobrowse-api/service/sql/portage/getPackagesDepending.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index aed2293..98b39fe 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -24,6 +24,10 @@ module Gentoo { idempotent Packages getPackagesWithRecentAdditions(int syncs); idempotent Categories getCategoriesWithRecentAdditions(int syncs); idempotent Packages getTopTrackedPackages(int n); + idempotent PackageDependencyPackages getPackageDependencies(int id); + idempotent PackageDependencyPackages getPackageRuntimeDependencies(int id); + idempotent PackageDependencyPackages getPackagesDepending(int id); + idempotent PackageMasks getPackageMasks(int id); idempotent Bug getBug(int id) throws Slicer::NoRowsReturned; idempotent Bugs getPackageBugs(int packageId); diff --git a/gentoobrowse-api/domain/converters.cpp b/gentoobrowse-api/domain/converters.cpp index 6cedbcd..33a479f 100644 --- a/gentoobrowse-api/domain/converters.cpp +++ b/gentoobrowse-api/domain/converters.cpp @@ -64,6 +64,8 @@ namespace Slicer { s->get("{" + boost::algorithm::join(l2, ",") + "}"); } + template class PqArray; + ::Gentoo::StringList unpackPqTextArray(const std::string & s) { diff --git a/gentoobrowse-api/domain/extended-models.ice b/gentoobrowse-api/domain/extended-models.ice index fabf0f3..de9e514 100644 --- a/gentoobrowse-api/domain/extended-models.ice +++ b/gentoobrowse-api/domain/extended-models.ice @@ -23,11 +23,22 @@ module Gentoo { StringList archs; }; + class PackageDependencyPackage extends Package { + IntList ebuildids; + bool block; + }; + + class PackageMask extends Mask { + IntList ebuildids; + }; + sequence SearchResultPackages; sequence SearchResultBugs; sequence OverviewCategories; sequence EbuildDetails; dictionary OverviewCategoriesBySuper; + sequence PackageDependencyPackages; + sequence PackageMasks; }; #endif diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index 28083e8..42eb0c0 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -7,6 +7,8 @@ module Gentoo { sequence Image; [ "slicer:custommodelpart:PqArray" ] sequence StringList; + [ "slicer:custommodelpart:PqArray" ] + sequence IntList; class Category { ["slicer:db:pkey"] @@ -89,6 +91,16 @@ module Gentoo { StringList use; }; + class Mask { + int setno; + optional(0) string person; + string email; + [ "slicer:conversion:boost.posix_time.ptime:posixTimeToShortDate:shortDateToPosixTime" ] + string dateadded; + string message; + StringList atomspec; + }; + struct Sync { [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] string timestamp; @@ -102,6 +114,7 @@ module Gentoo { sequence ChangeLog; sequence News; sequence Syncs; + sequence Masks; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index 9854230..689b173 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -17,6 +17,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -152,6 +156,30 @@ Portage::getCategoriesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) return fetchCache(sql::portage::getCategoriesWithRecentAdditions, 30, syncs); } +Gentoo::PackageDependencyPackages +Portage::getPackageDependencies(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackageDependencies, 30, id); +} + +Gentoo::PackageDependencyPackages +Portage::getPackageRuntimeDependencies(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackageRuntimeDependencies, 30, id); +} + +Gentoo::PackageDependencyPackages +Portage::getPackagesDepending(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackagesDepending, 30, id); +} + +Gentoo::PackageMasks +Portage::getPackageMasks(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackageMasks, 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 86608d5..8810068 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -31,6 +31,10 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Gentoo::Packages getPackagesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) override; Gentoo::Categories getCategoriesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) override; Gentoo::Packages getTopTrackedPackages(Ice::Int n, const Ice::Current &) override; + Gentoo::PackageDependencyPackages getPackageDependencies(Ice::Int id, const Ice::Current &) override; + 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::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/getPackageDependencies.sql b/gentoobrowse-api/service/sql/portage/getPackageDependencies.sql new file mode 100644 index 0000000..5a6b6c9 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackageDependencies.sql @@ -0,0 +1,6 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd, array_agg(e.ebuildid order by e.ebuildid) ebuildids, position('!' in d.op) > 0 block +FROM gentoobrowse.packages p, gentoobrowse.ebuilds e, gentoobrowse.ebuild_deps d +WHERE e.packageid = ? +AND e.ebuildid = d.ebuildid +AND p.packageid = d.packageid +GROUP BY p.packageid, block diff --git a/gentoobrowse-api/service/sql/portage/getPackageMasks.sql b/gentoobrowse-api/service/sql/portage/getPackageMasks.sql new file mode 100644 index 0000000..bc05f4b --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackageMasks.sql @@ -0,0 +1,7 @@ +SELECT ms.setno, ms.person, ms.email, ms.dateadded, ms.message, ms.atomspec, ms.n, ARRAY_AGG(e.ebuildid ORDER BY e.ebuildid) ebuildids +FROM gentoobrowse.ebuild_masks em, gentoobrowse.masksets ms, gentoobrowse.ebuilds e +WHERE em.setno = ms.setno +AND em.ebuildid = e.ebuildid +AND e.packageid = ? +GROUP BY ms.setno +ORDER BY dateadded diff --git a/gentoobrowse-api/service/sql/portage/getPackageRuntimeDependencies.sql b/gentoobrowse-api/service/sql/portage/getPackageRuntimeDependencies.sql new file mode 100644 index 0000000..e74d0d0 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackageRuntimeDependencies.sql @@ -0,0 +1,7 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd, array_agg(e.ebuildid order by e.ebuildid) ebuildids, position('!' in d.op) > 0 block +FROM gentoobrowse.packages p, gentoobrowse.ebuilds e, gentoobrowse.ebuild_rdeps d +WHERE e.packageid = ? +AND e.ebuildid = d.ebuildid +AND p.packageid = d.packageid +GROUP BY p.packageid, block + diff --git a/gentoobrowse-api/service/sql/portage/getPackagesDepending.sql b/gentoobrowse-api/service/sql/portage/getPackagesDepending.sql new file mode 100644 index 0000000..c86d1f9 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackagesDepending.sql @@ -0,0 +1,11 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd, array_agg(e.ebuildid order by e.ebuildid) ebuildids, position('!' in d.op) > 0 block +FROM gentoobrowse.packages p, gentoobrowse.ebuilds e, ( + SELECT d.ebuildid, d.packageid, d.op + FROM gentoobrowse.ebuild_rdeps d + UNION ALL + SELECT d.ebuildid, d.packageid, d.op + FROM gentoobrowse.ebuild_deps d) d +WHERE d.packageid = ? +AND e.ebuildid = d.ebuildid +AND p.packageid = e.packageid +GROUP BY p.packageid, block diff --git a/gentoobrowse-api/unittests/fixtures/masksets.dat b/gentoobrowse-api/unittests/fixtures/masksets.dat index d73443e..c523a3a 100644 --- a/gentoobrowse-api/unittests/fixtures/masksets.dat +++ b/gentoobrowse-api/unittests/fixtures/masksets.dat @@ -1,4 +1,4 @@ -3 Robin H. Johnson robbat2@gentoo.org 2006-02-11 zlib interaction is badly broken. See bug #124733. 1 {} +3 Robin H. Johnson robbat2@gentoo.org 2006-02-11 zlib interaction is badly broken. See bug #124733. 1 {license); } +BOOST_AUTO_TEST_CASE( getPackageDependencies ) +{ + auto d = p->getPackageDependencies(54144); + BOOST_REQUIRE_EQUAL(2, d.size()); + BOOST_REQUIRE_EQUAL("gnupg", d.front()->name); + // This is right... git-9999 requires a version of itself + BOOST_REQUIRE_EQUAL("git", d.back()->name); + BOOST_REQUIRE_EQUAL(4, d.back()->ebuildids.size()); + BOOST_REQUIRE_EQUAL(628953, d.back()->ebuildids.front()); + BOOST_REQUIRE_EQUAL(629007, d.back()->ebuildids.back()); +} + +BOOST_AUTO_TEST_CASE( getPackageRuntimeDependencies ) +{ + auto d = p->getPackageRuntimeDependencies(54144); + BOOST_REQUIRE_EQUAL(3, d.size()); + BOOST_REQUIRE_EQUAL("gnupg", d[0]->name); + BOOST_REQUIRE_EQUAL("cvsps", d[1]->name); + BOOST_REQUIRE_EQUAL("subversion", d[2]->name); +} + +BOOST_AUTO_TEST_CASE( getPackagesDepending ) +{ + auto d = p->getPackagesDepending(55923); + BOOST_REQUIRE_EQUAL(6, d.size()); + BOOST_REQUIRE_EQUAL("statcvs", d.front()->name); + BOOST_REQUIRE_EQUAL("tkcvs", d.back()->name); +} + +BOOST_AUTO_TEST_CASE( getPackageMasks ) +{ + auto ms = p->getPackageMasks(55923); + BOOST_REQUIRE_EQUAL(1, ms.size()); + BOOST_REQUIRE_EQUAL(3, ms.front()->setno); + BOOST_REQUIRE_EQUAL("robbat2@gentoo.org", ms.front()->email); + BOOST_REQUIRE_EQUAL("Robin H. Johnson", ms.front()->person); + BOOST_REQUIRE_EQUAL("2006-02-11", ms.front()->dateadded); + BOOST_REQUIRE_EQUAL("zlib interaction is badly broken. See bug #124733.", ms.front()->message); + BOOST_REQUIRE_EQUAL(1, ms.front()->atomspec.size()); + BOOST_REQUIRE_EQUAL("atomspec.front()); + BOOST_REQUIRE_EQUAL(5, ms.front()->ebuildids.size()); + BOOST_REQUIRE_EQUAL(628951, ms.front()->ebuildids.front()); + BOOST_REQUIRE_EQUAL(629114, ms.front()->ebuildids.back()); +} + BOOST_AUTO_TEST_CASE( getBugMissing ) { BOOST_REQUIRE_THROW(p->getBug(10), Slicer::NoRowsReturned); -- cgit v1.2.3