diff options
4 files changed, 85 insertions, 5 deletions
diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp new file mode 100644 index 0000000..caa75c0 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp @@ -0,0 +1,52 @@ +#include "useGlobalProcessor.h" +#include <modifycommand.h> +#include <tablepatch.h> +#include "utils/fileUtils.h" +#include "utils/dbUtils.h" +#include <glibmm/regex.h> + +using namespace Gentoo::Utils::File; + +static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE); + +namespace Gentoo { + namespace Service { + const int UseGlobalProcessor::FILETYPEID = 5; + + void + UseGlobalProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + modified(dbc, fn, path); + } + + void + UseGlobalProcessor::modified(DB::Connection * dbc, const boost::filesystem::path &, const boost::filesystem::path & path) const + { + DB::TablePatch p; + p.dest = "gentoobrowse.use_global"; + p.src = Utils::Database::emptyClone(dbc, p.dest); + p.pk = { "use" }; + p.cols = { "use", "description" }; + + Utils::MemMap u(path); + Glib::ustring d(reinterpret_cast<const char *>(u.data), u.getStat().st_size); + Glib::MatchInfo matches; + auto i = Utils::Database::tablePatchInserter(dbc, p); + for (useDesc->match(d, matches); matches.get_match_count() == 3; matches.next()) { + i->bindParamS(0, matches.fetch(2)); + i->bindParamS(1, matches.fetch(1)); + i->execute(); + } + dbc->patchTable(&p); + + Utils::Database::drop(dbc, p.src); + } + + void + UseGlobalProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path &) const + { + dbc->modify("DELETE FROM gentoobrowse.use_global")->execute(); + } + } +} + diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.h b/gentoobrowse-api/service/maintenance/useGlobalProcessor.h new file mode 100644 index 0000000..c5e3dcb --- /dev/null +++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.h @@ -0,0 +1,23 @@ +#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_USEGLOBALPROC_H +#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_USEGLOBALPROC_H + +#include "../maintenanceimpl.h" +#include <connection.h> +#include <modifycommand.h> +#include <boost/filesystem/path.hpp> + +namespace Gentoo { + namespace Service { + class UseGlobalProcessor : public Maintenance::FileProcessor { + public: + static const int FILETYPEID; + + void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; + }; + } +} + +#endif + diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index aec1cba..7f7bb65 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -10,16 +10,17 @@ #include "maintenance/packageManifestProcessor.h" #include "maintenance/packageMetaProcessor.h" #include "maintenance/ebuildMetaProcessor.h" +#include "maintenance/useGlobalProcessor.h" /* 10 category metadata.xml {"(2,metadata.xml)"} 4 package metadata.xml {"(3,metadata.xml)"} 1 ebuild metadata {"(1,metadata)","(2,md5-cache)"} +5 use_global {"(1,profiles)","(2,use.desc)"} 8 package manifests {"(3,Manifest)"} 2 changelog {"(3,ChangeLog)"} 3 masks {"(1,profiles)","(2,package.mask)"} -5 use_global {"(1,profiles)","(2,use.desc)"} 6 use_local {"(1,profiles)","(2,use.local.desc)"} 7 licenses {"(1,licenses)"} 9 use_grouped {"(1,profiles)","(2,desc)","(3,%.desc)"} @@ -54,6 +55,7 @@ namespace Gentoo { fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); fps[PackageMetaProcessor::FILETYPEID] = new PackageMetaProcessor(); fps[EbuildMetaProcessor::FILETYPEID] = new EbuildMetaProcessor(); + fps[UseGlobalProcessor::FILETYPEID] = new UseGlobalProcessor(); } Maintenance::~Maintenance() diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index b6f50da..b8905fa 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -45,7 +45,7 @@ BOOST_FIXTURE_TEST_SUITE(tp, TestClient) void doRefreshPackageTree(SampleData & sd, DB::ConnectionPtr db, const std::string & archive, const std::string & dir, Gentoo::MaintenancePrx m, int64_t files, int64_t cats, int64_t devvcs, int64_t pkgs, int64_t ebs, int64_t ebus, - int64_t ebas, int64_t pus) + int64_t ebas, int64_t pus, int64_t ug) { if (!archive.empty()) { sd.extract(archive, dir); @@ -61,6 +61,7 @@ doRefreshPackageTree(SampleData & sd, DB::ConnectionPtr db, const std::string & SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_uses", int64_t, ebus); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.ebuild_archs", int64_t, ebas); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.package_urls", int64_t, pus); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.use_global", int64_t, ug); } BOOST_AUTO_TEST_CASE( refreshPackageTree ) @@ -73,7 +74,7 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) insRepo->execute(); doRefreshPackageTree(sd, db, "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", "gentoo", - m, 2084, 5, 1, 482, 981, 3626, 4593, 507); + m, 2084, 5, 1, 482, 981, 3626, 4593, 507, 393); db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'"); db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'"); @@ -81,9 +82,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) db->execute("COPY gentoobrowse.ebuild_uses TO '/tmp/ebuild_uses1.tsv'"); db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs1.tsv'"); db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls1.tsv'"); + db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global1.tsv'"); doRefreshPackageTree(sd, db, "756569aa764177340726dd3d40b41d89b11b20c7", "gentoo", - m, 2087, 5, 1, 484, 982, 3638, 4599, 510); + m, 2087, 5, 1, 484, 982, 3638, 4599, 510, 393); db->execute("COPY gentoobrowse.categories TO '/tmp/categories2.tsv'"); db->execute("COPY gentoobrowse.packages TO '/tmp/packages2.tsv'"); @@ -91,9 +93,10 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) db->execute("COPY gentoobrowse.ebuild_uses TO '/tmp/ebuild_uses2.tsv'"); db->execute("COPY gentoobrowse.ebuild_archs TO '/tmp/ebuild_archs2.tsv'"); db->execute("COPY gentoobrowse.package_urls TO '/tmp/package_urls2.tsv'"); + db->execute("COPY gentoobrowse.use_global TO '/tmp/use_global2.tsv'"); doRefreshPackageTree(sd, db, "", "gentoo", - m, 0, 0, 0, 0, 0, 0, 0, 0); + m, 0, 0, 0, 0, 0, 0, 0, 0, 0); m->refreshPackageTree(); } |