summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-04-30 16:07:19 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-04-30 16:07:19 +0100
commit4d9721e7a7102c538a42ead30f61f50270581549 (patch)
tree2c0ccaf0d80ca07538e9eea7e87d95cf59b783d9
parentAdd atomspec column to DB and test data (diff)
downloadgentoobrowse-api-4d9721e7a7102c538a42ead30f61f50270581549.tar.bz2
gentoobrowse-api-4d9721e7a7102c538a42ead30f61f50270581549.tar.xz
gentoobrowse-api-4d9721e7a7102c538a42ead30f61f50270581549.zip
Process masks
-rw-r--r--gentoobrowse-api/service/maintenance/masksProcessor.cpp110
-rw-r--r--gentoobrowse-api/service/maintenance/masksProcessor.h23
-rw-r--r--gentoobrowse-api/service/maintenanceimpl.cpp4
-rw-r--r--gentoobrowse-api/service/sql/maintenance/masksEbuilds.sql4
-rw-r--r--gentoobrowse-api/service/sql/maintenance/masksSets.sql5
-rw-r--r--gentoobrowse-api/unittests/testMaintenance.cpp4
6 files changed, 149 insertions, 1 deletions
diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.cpp b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
new file mode 100644
index 0000000..58f56de
--- /dev/null
+++ b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
@@ -0,0 +1,110 @@
+#include "masksProcessor.h"
+#include <boost/algorithm/string/trim.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <modifycommand.h>
+#include <sqlWriter.h>
+#include <tablepatch.h>
+#include "utils/fileUtils.h"
+#include "utils/dbUtils.h"
+#include <glibmm/regex.h>
+#include <glibmm/iochannel.h>
+#include "sql/maintenance/masksSets.sql.h"
+#include "sql/maintenance/masksEbuilds.sql.h"
+
+using namespace Gentoo::Utils::File;
+
+static Glib::RefPtr<Glib::Regex> maskHead = Glib::Regex::create(
+ "^# ([^<]+)? ?<(.+?@[^>]+)> \\((\\d+ *(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) \\d+)\\)",
+ Glib::RegexCompileFlags::REGEX_CASELESS);
+static Glib::RefPtr<Glib::Regex> maskDesc = Glib::Regex::create("^# (.*)");
+
+namespace Gentoo {
+ namespace Service {
+ const int MasksProcessor::FILETYPEID = 3;
+
+ void
+ MasksProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const
+ {
+ modified(dbc, fn, path);
+ }
+
+ void
+ MasksProcessor::modified(DB::Connection * dbc, const boost::filesystem::path &, const boost::filesystem::path & path) const
+ {
+ auto tempTable = Utils::Database::namedTemp(dbc, "tmp_masks", {
+ { "n", "int" },
+ { "dateAdded", "date" },
+ { "person", "text" },
+ { "email", "text" },
+ { "message", "text" },
+ { "atomSpec", "text[]" }
+ });
+
+ auto iochannel = Glib::IOChannel::create_from_file(path.string(), "r");
+ Glib::MatchInfo matchesHead, matchesDesc;
+ std::set<std::string> atoms;
+ std::list<std::string> message;
+ Glib::ustring line, person, email, date;
+ bool inMask = false;
+ int n = 0;
+ auto i = tempTable.second;
+ while (iochannel->read_line(line) == Glib::IO_STATUS_NORMAL) {
+ boost::algorithm::trim_right_if(line, &g_unichar_isspace);
+ if (maskHead->match(line, matchesHead) && matchesHead.get_match_count() == 4) {
+ // Mask header
+ inMask = true;
+ person = matchesHead.fetch(1);
+ email = matchesHead.fetch(2);
+ date = matchesHead.fetch(3);
+ }
+ else if (inMask && maskDesc->match(line, matchesDesc) && matchesDesc.get_match_count() == 2) {
+ // Mask message
+ message.push_back(line);
+ }
+ else if (inMask && !line.empty()) {
+ // Masked atom
+ atoms.insert(line);
+ }
+ else if (inMask && line.empty()) {
+ // End
+ inMask = false;
+ i->bindParamS(0, "{" + boost::algorithm::join(atoms, ",") + "}");
+ i->bindParamS(1, date);
+ i->bindParamS(2, email);
+ i->bindParamS(3, boost::algorithm::join(message, " "));
+ i->bindParamI(4, ++n);
+ i->bindParamS(5, person);
+ i->execute();
+ atoms.clear();
+ message.clear();
+ }
+ }
+
+ DB::TablePatch p;
+ p.dest = "gentoobrowse.masksets";
+ DB::StaticSqlWriter srcExpr(sql::maintenance::masksSets.getSql());
+ p.srcExpr = &srcExpr;
+ p.pk = { "dateAdded", "n" };
+ p.cols = { "dateAdded", "n", "person", "email", "message", "atomSpec" };
+ dbc->patchTable(&p);
+
+ DB::TablePatch e;
+ e.dest = "gentoobrowse.ebuild_masks";
+ DB::StaticSqlWriter srcExprE(sql::maintenance::masksEbuilds.getSql());
+ e.srcExpr = &srcExprE;
+
+ e.pk = { "ebuildId", "setNo" };
+ e.cols = e.pk;
+ dbc->patchTable(&e);
+
+ Utils::Database::drop(dbc, tempTable.first);
+ }
+
+ void
+ MasksProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path &) const
+ {
+ dbc->modify("DELETE FROM gentoobrowse.use_local")->execute();
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.h b/gentoobrowse-api/service/maintenance/masksProcessor.h
new file mode 100644
index 0000000..eb147e4
--- /dev/null
+++ b/gentoobrowse-api/service/maintenance/masksProcessor.h
@@ -0,0 +1,23 @@
+#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_MASKSPROC_H
+#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_MASKSPROC_H
+
+#include "../maintenanceimpl.h"
+#include <connection.h>
+#include <modifycommand.h>
+#include <boost/filesystem/path.hpp>
+
+namespace Gentoo {
+ namespace Service {
+ class MasksProcessor : 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 d9cd32d..0957dda 100644
--- a/gentoobrowse-api/service/maintenanceimpl.cpp
+++ b/gentoobrowse-api/service/maintenanceimpl.cpp
@@ -13,6 +13,7 @@
#include "maintenance/useGlobalProcessor.h"
#include "maintenance/useLocalProcessor.h"
#include "maintenance/useGroupProcessor.h"
+#include "maintenance/masksProcessor.h"
/*
10 category metadata.xml {"(2,metadata.xml)"}
@@ -21,10 +22,10 @@
5 use_global {"(1,profiles)","(2,use.desc)"}
6 use_local {"(1,profiles)","(2,use.local.desc)"}
9 use_grouped {"(1,profiles)","(2,desc)","(3,%.desc)"}
+3 masks {"(1,profiles)","(2,package.mask)"}
8 package manifests {"(3,Manifest)"}
2 changelog {"(3,ChangeLog)"}
-3 masks {"(1,profiles)","(2,package.mask)"}
7 licenses {"(1,licenses)"}
11 news {"(1,metadata)","(2,news)","(4,%.txt)"}
*/
@@ -60,6 +61,7 @@ namespace Gentoo {
fps[UseGlobalProcessor::FILETYPEID] = new UseGlobalProcessor();
fps[UseLocalProcessor::FILETYPEID] = new UseLocalProcessor();
fps[UseGroupProcessor::FILETYPEID] = new UseGroupProcessor();
+ fps[MasksProcessor::FILETYPEID] = new MasksProcessor();
}
Maintenance::~Maintenance()
diff --git a/gentoobrowse-api/service/sql/maintenance/masksEbuilds.sql b/gentoobrowse-api/service/sql/maintenance/masksEbuilds.sql
new file mode 100644
index 0000000..f34343e
--- /dev/null
+++ b/gentoobrowse-api/service/sql/maintenance/masksEbuilds.sql
@@ -0,0 +1,4 @@
+(
+ SELECT DISTINCT s.setno, ebuildfilter(UNNEST(s.atomSpec)) ebuildid
+ FROM gentoobrowse.masksets s
+)
diff --git a/gentoobrowse-api/service/sql/maintenance/masksSets.sql b/gentoobrowse-api/service/sql/maintenance/masksSets.sql
new file mode 100644
index 0000000..873d60e
--- /dev/null
+++ b/gentoobrowse-api/service/sql/maintenance/masksSets.sql
@@ -0,0 +1,5 @@
+(
+ SELECT tm.dateAdded, RANK() OVER(PARTITION BY tm.dateAdded ORDER BY n DESC) n,
+ tm.person, tm.email, tm.message, tm.atomSpec
+ FROM tmp_masks tm
+)
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index a339524..263f9ef 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -89,6 +89,8 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local1.tsv'");
db->execute("COPY gentoobrowse.use_groups TO '/tmp/use_groups1.tsv'");
db->execute("COPY gentoobrowse.use_group TO '/tmp/use_group1.tsv'");
+ db->execute("COPY gentoobrowse.masksets TO '/tmp/masksets1.tsv'");
+ db->execute("COPY gentoobrowse.ebuild_masks TO '/tmp/ebuild_masks1.tsv'");
doRefreshPackageTree(sd, db, "756569aa764177340726dd3d40b41d89b11b20c7", "gentoo",
m, 2087, 5, 1, 484, 982, 3638, 4599, 503, 393, 238, 50, 1573);
@@ -103,6 +105,8 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
db->execute("COPY gentoobrowse.use_local TO '/tmp/use_local2.tsv'");
db->execute("COPY gentoobrowse.use_groups TO '/tmp/use_groups2.tsv'");
db->execute("COPY gentoobrowse.use_group TO '/tmp/use_group2.tsv'");
+ db->execute("COPY gentoobrowse.masksets TO '/tmp/masksets2.tsv'");
+ db->execute("COPY gentoobrowse.ebuild_masks TO '/tmp/ebuild_masks2.tsv'");
doRefreshPackageTree(sd, db, "", "gentoo",
m, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);