summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-04-25 02:15:28 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-04-25 21:38:52 +0100
commit549ecb2d2d4c10b61fc6f5b41ef4e0bc5302f098 (patch)
tree61f711bcf932085f211efdf318844bcc7d937aa0
parentUpdate package description with new versions (diff)
downloadgentoobrowse-api-549ecb2d2d4c10b61fc6f5b41ef4e0bc5302f098.tar.bz2
gentoobrowse-api-549ecb2d2d4c10b61fc6f5b41ef4e0bc5302f098.tar.xz
gentoobrowse-api-549ecb2d2d4c10b61fc6f5b41ef4e0bc5302f098.zip
Refactor utils
-rw-r--r--gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp6
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp105
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h5
-rw-r--r--gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp2
-rw-r--r--gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp6
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.cpp (renamed from gentoobrowse-api/service/dbUtils.cpp)0
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.h (renamed from gentoobrowse-api/service/dbUtils.h)0
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.cpp34
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.h28
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.cpp25
-rw-r--r--gentoobrowse-api/service/utils/entityWhereFilter.h22
-rw-r--r--gentoobrowse-api/service/utils/fileUtils.cpp (renamed from gentoobrowse-api/service/fileUtils.cpp)0
-rw-r--r--gentoobrowse-api/service/utils/fileUtils.h (renamed from gentoobrowse-api/service/fileUtils.h)0
-rw-r--r--gentoobrowse-api/service/utils/splitEbuildProps.cpp29
-rw-r--r--gentoobrowse-api/service/utils/splitEbuildProps.h25
-rw-r--r--gentoobrowse-api/service/utils/xmlUtils.cpp (renamed from gentoobrowse-api/service/xmlUtils.cpp)0
-rw-r--r--gentoobrowse-api/service/utils/xmlUtils.h (renamed from gentoobrowse-api/service/xmlUtils.h)0
17 files changed, 185 insertions, 102 deletions
diff --git a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
index 781526a..31d2508 100644
--- a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
@@ -1,8 +1,8 @@
#include "categoryMetaProcessor.h"
#include <modifycommand.h>
-#include "fileUtils.h"
-#include "xmlUtils.h"
-#include "dbUtils.h"
+#include "utils/fileUtils.h"
+#include "utils/xmlUtils.h"
+#include "utils/dbUtils.h"
#include <sql/maintenance/categoryMetaUpdate.sql.h>
namespace U = Gentoo::Utils;
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
index 1bd8c6c..dbb3ea3 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
@@ -6,9 +6,11 @@
#include <boost/filesystem/operations.hpp>
#include <glibmm/regex.h>
#include <tablepatch.h>
-#include "fileUtils.h"
-#include "xmlUtils.h"
-#include "dbUtils.h"
+#include "utils/fileUtils.h"
+#include "utils/dbUtils.h"
+#include "utils/ebuildCacheParser.h"
+#include "utils/entityWhereFilter.h"
+#include "utils/splitEbuildProps.h"
#include <sql/maintenance/categoryInsert.sql.h>
#include <sql/maintenance/packageInsert.sql.h>
#include <sql/maintenance/packageDescUpdate.sql.h>
@@ -25,65 +27,6 @@ static Glib::RefPtr<Glib::Regex> packageVersion = Glib::Regex::create("^(.+)-([0
namespace Gentoo {
namespace Service {
- class EbuildCacheParser : public U::MemMap {
- public:
- typedef std::pair<const char *, const char *> Range;
- typedef std::map<std::string, const Range> KVs;
-
- EbuildCacheParser(const boost::filesystem::path & p) :
- U::MemMap(p)
- {
- const char * chardata = (const char *)this->data;
- while (const char * eq = strchr(chardata, '=')) {
- if (const char * nl = strchr(eq + 1, '\n')) {
- kvs.insert({ std::string(chardata, eq), { eq + 1, nl } });
- chardata = nl + 1;
- }
- else {
- kvs.insert({ std::string(chardata, eq), { eq + 1, (const char *)this->data + st.st_size } });
- return;
- }
- }
- }
-
- boost::optional<Glib::ustring> get(const std::string & key) const
- {
- auto kvi = kvs.find(key);
- if (kvi == kvs.end()) {
- return boost::optional<Glib::ustring>();
- }
- return Glib::ustring(kvi->second.first, kvi->second.second);
- }
-
- private:
- KVs kvs;
- };
-
- class SplitEbuildProps : public DB::SqlWriter {
- public:
- SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional<Glib::ustring> & p) :
- entityId(e),
- colEntityName(ce),
- colPropName(cp),
- props(p)
- {
- }
-
- void writeSql(AdHoc::Buffer & sql) override
- {
- sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName, colPropName);
- }
-
- void bindParams(DB::Command * c, unsigned int & offset) override
- {
- c->bindParamI(offset++, entityId);
- Utils::Database::bindOptionalsS(c, offset++, { props });
- }
-
- const int entityId;
- const std::string colEntityName, colPropName;
- const boost::optional<Glib::ustring> props;
- };
const int EbuildMetaProcessor::FILETYPEID = 1;
@@ -93,7 +36,7 @@ namespace Gentoo {
Glib::MatchInfo matches;
const Glib::ustring pv = (fn / 4).string();
if (packageVersion->match(pv, matches)) {
- EbuildCacheParser ecp(path);
+ U::EbuildCacheParser ecp(path);
const std::string repoName = (fn / 0).string();
const std::string categoryName = (fn / 3).string();
const std::string packageName = matches.fetch(1);
@@ -135,7 +78,7 @@ namespace Gentoo {
const Glib::ustring pv = (fn / 4).string();
if (packageVersion->match(pv, matches)) {
auto m = dbc->select(sql::maintenance::ebuildUpdate::sql);
- EbuildCacheParser ecp(path);
+ U::EbuildCacheParser ecp(path);
Utils::Database::bindOptionalsS(m.get(), 0, { ecp.get("SLOT") });
Utils::Database::bindOptionalsS(m.get(), 1, { ecp.get("LICENSE") });
m->bindParamT(2, boost::posix_time::from_time_t(ecp.getStat().st_mtim.tv_sec));
@@ -150,35 +93,13 @@ namespace Gentoo {
}
}
- class EntityWhereFilter : public DB::SqlWriter {
- public:
- EntityWhereFilter(const std::string & en, int64_t e) :
- entityId(e),
- entityColName(en)
- {
- }
-
- void writeSql(AdHoc::Buffer & sql) override
- {
- sql.appendbf("b.%s = ?", entityColName);
- }
-
- void bindParams(DB::Command * c, unsigned int & offset) override
- {
- c->bindParamI(offset++, entityId);
- }
-
- const int64_t entityId;
- const std::string entityColName;
- };
-
void
- EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) const
+ EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const U::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) const
{
- EntityWhereFilter ewf("ebuildId", ebuildId);
+ U::EntityWhereFilter ewf("ebuildId", ebuildId);
// IUSE
DB::TablePatch t;
- SplitEbuildProps sep_use("ebuildId", ebuildId, "use", ecp.get("IUSE"));
+ U::SplitEbuildProps sep_use("ebuildId", ebuildId, "use", ecp.get("IUSE"));
t.dest = "gentoobrowse.ebuild_uses";
t.srcExpr = &sep_use;
t.pk = { "ebuildid", "use" };
@@ -186,7 +107,7 @@ namespace Gentoo {
t.where = &ewf;
dbc->patchTable(&t);
// KEYWORDS
- SplitEbuildProps sep_keywords("ebuildId", ebuildId, "arch", ecp.get("KEYWORDS"));
+ U::SplitEbuildProps sep_keywords("ebuildId", ebuildId, "arch", ecp.get("KEYWORDS"));
t.dest = "gentoobrowse.ebuild_archs";
t.srcExpr = &sep_keywords;
t.pk = { "ebuildid", "arch" };
@@ -195,8 +116,8 @@ namespace Gentoo {
dbc->patchTable(&t);
if (newest) {
// HOMEPAGE
- EntityWhereFilter pwf("packageId", 1);
- SplitEbuildProps sep_homepage("packageId", packageId, "url", ecp.get("HOMEPAGE"));
+ U::EntityWhereFilter pwf("packageId", 1);
+ U::SplitEbuildProps sep_homepage("packageId", packageId, "url", ecp.get("HOMEPAGE"));
t.dest = "gentoobrowse.package_urls";
t.srcExpr = &sep_homepage;
t.pk = { "packageId", "url" };
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
index 42b538d..3cd6ba9 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h
@@ -2,14 +2,13 @@
#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDMETAPROC_H
#include "../maintenanceimpl.h"
+#include "utils/ebuildCacheParser.h"
#include <connection.h>
#include <modifycommand.h>
#include <boost/filesystem/path.hpp>
namespace Gentoo {
namespace Service {
- class EbuildCacheParser;
-
class EbuildMetaProcessor : public Maintenance::FileProcessor {
public:
static const int FILETYPEID;
@@ -19,7 +18,7 @@ namespace Gentoo {
void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const;
private:
- void perEbuildUpdates(DB::Connection * dbc, const EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) const;
+ void perEbuildUpdates(DB::Connection * dbc, const Utils::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) const;
};
}
}
diff --git a/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp
index a84f4a4..e22ce3b 100644
--- a/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp
@@ -1,6 +1,6 @@
#include "packageManifestProcessor.h"
#include <modifycommand.h>
-#include "fileUtils.h"
+#include "utils/fileUtils.h"
using namespace Gentoo::Utils::File;
diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
index 9dcf709..5c67774 100644
--- a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
@@ -1,8 +1,8 @@
#include "packageMetaProcessor.h"
#include <modifycommand.h>
-#include "fileUtils.h"
-#include "xmlUtils.h"
-#include "dbUtils.h"
+#include "utils/fileUtils.h"
+#include "utils/xmlUtils.h"
+#include "utils/dbUtils.h"
#include <sql/maintenance/packageMetaUpdate.sql.h>
namespace U = Gentoo::Utils;
diff --git a/gentoobrowse-api/service/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp
index f2b7f4d..f2b7f4d 100644
--- a/gentoobrowse-api/service/dbUtils.cpp
+++ b/gentoobrowse-api/service/utils/dbUtils.cpp
diff --git a/gentoobrowse-api/service/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h
index e609c2d..e609c2d 100644
--- a/gentoobrowse-api/service/dbUtils.h
+++ b/gentoobrowse-api/service/utils/dbUtils.h
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
new file mode 100644
index 0000000..ad894db
--- /dev/null
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
@@ -0,0 +1,34 @@
+#include "ebuildCacheParser.h"
+
+namespace U = Gentoo::Utils;
+
+namespace Gentoo {
+ namespace Utils {
+ EbuildCacheParser::EbuildCacheParser(const boost::filesystem::path & p) :
+ U::MemMap(p)
+ {
+ const char * chardata = (const char *)this->data;
+ while (const char * eq = strchr(chardata, '=')) {
+ if (const char * nl = strchr(eq + 1, '\n')) {
+ kvs.insert({ std::string(chardata, eq), { eq + 1, nl } });
+ chardata = nl + 1;
+ }
+ else {
+ kvs.insert({ std::string(chardata, eq), { eq + 1, (const char *)this->data + st.st_size } });
+ return;
+ }
+ }
+ }
+
+ boost::optional<Glib::ustring>
+ EbuildCacheParser::get(const std::string & key) const
+ {
+ auto kvi = kvs.find(key);
+ if (kvi == kvs.end()) {
+ return boost::optional<Glib::ustring>();
+ }
+ return Glib::ustring(kvi->second.first, kvi->second.second);
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.h b/gentoobrowse-api/service/utils/ebuildCacheParser.h
new file mode 100644
index 0000000..e9f1dfc
--- /dev/null
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.h
@@ -0,0 +1,28 @@
+#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
+#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
+
+#include "fileUtils.h"
+#include <map>
+#include <boost/optional.hpp>
+#include <boost/filesystem/path.hpp>
+#include <glibmm/ustring.h>
+
+namespace Gentoo {
+ namespace Utils {
+ class EbuildCacheParser : public Gentoo::Utils::MemMap {
+ public:
+ typedef std::pair<const char *, const char *> Range;
+ typedef std::map<std::string, const Range> KVs;
+
+ EbuildCacheParser(const boost::filesystem::path & p);
+
+ boost::optional<Glib::ustring> get(const std::string & key) const;
+
+ private:
+ KVs kvs;
+ };
+ }
+}
+
+#endif
+
diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.cpp b/gentoobrowse-api/service/utils/entityWhereFilter.cpp
new file mode 100644
index 0000000..8e29cfe
--- /dev/null
+++ b/gentoobrowse-api/service/utils/entityWhereFilter.cpp
@@ -0,0 +1,25 @@
+#include "entityWhereFilter.h"
+#include <command.h>
+
+namespace Gentoo {
+ namespace Utils {
+ EntityWhereFilter::EntityWhereFilter(const std::string & en, int64_t e) :
+ entityId(e),
+ entityColName(en)
+ {
+ }
+
+ void
+ EntityWhereFilter::writeSql(AdHoc::Buffer & sql)
+ {
+ sql.appendbf("b.%s = ?", entityColName);
+ }
+
+ void
+ EntityWhereFilter::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ c->bindParamI(offset++, entityId);
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/utils/entityWhereFilter.h b/gentoobrowse-api/service/utils/entityWhereFilter.h
new file mode 100644
index 0000000..20420c3
--- /dev/null
+++ b/gentoobrowse-api/service/utils/entityWhereFilter.h
@@ -0,0 +1,22 @@
+#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H
+#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_ENTITYWHEREFILTER_H
+
+#include <sqlWriter.h>
+
+namespace Gentoo {
+ namespace Utils {
+ class EntityWhereFilter : public DB::SqlWriter {
+ public:
+ EntityWhereFilter(const std::string & en, int64_t e);
+
+ void writeSql(AdHoc::Buffer & sql) override;
+ void bindParams(DB::Command * c, unsigned int & offset) override;
+
+ const int64_t entityId;
+ const std::string entityColName;
+ };
+ }
+}
+
+#endif
+
diff --git a/gentoobrowse-api/service/fileUtils.cpp b/gentoobrowse-api/service/utils/fileUtils.cpp
index 1446b9f..1446b9f 100644
--- a/gentoobrowse-api/service/fileUtils.cpp
+++ b/gentoobrowse-api/service/utils/fileUtils.cpp
diff --git a/gentoobrowse-api/service/fileUtils.h b/gentoobrowse-api/service/utils/fileUtils.h
index d73b1ef..d73b1ef 100644
--- a/gentoobrowse-api/service/fileUtils.h
+++ b/gentoobrowse-api/service/utils/fileUtils.h
diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.cpp b/gentoobrowse-api/service/utils/splitEbuildProps.cpp
new file mode 100644
index 0000000..8116742
--- /dev/null
+++ b/gentoobrowse-api/service/utils/splitEbuildProps.cpp
@@ -0,0 +1,29 @@
+#include "splitEbuildProps.h"
+#include <command.h>
+#include "dbUtils.h"
+
+namespace Gentoo {
+ namespace Utils {
+ SplitEbuildProps::SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional<Glib::ustring> & p) :
+ entityId(e),
+ colEntityName(ce),
+ colPropName(cp),
+ props(p)
+ {
+ }
+
+ void
+ SplitEbuildProps::writeSql(AdHoc::Buffer & sql)
+ {
+ sql.appendbf("(SELECT DISTINCT ?::int %s, trim(regexp_split_to_table(?, '\\s+'), '+') %s)", colEntityName, colPropName);
+ }
+
+ void
+ SplitEbuildProps::bindParams(DB::Command * c, unsigned int & offset)
+ {
+ c->bindParamI(offset++, entityId);
+ Gentoo::Utils::Database::bindOptionalsS(c, offset++, { props });
+ }
+ }
+}
+
diff --git a/gentoobrowse-api/service/utils/splitEbuildProps.h b/gentoobrowse-api/service/utils/splitEbuildProps.h
new file mode 100644
index 0000000..4739b7e
--- /dev/null
+++ b/gentoobrowse-api/service/utils/splitEbuildProps.h
@@ -0,0 +1,25 @@
+#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H
+#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_SPLITEBUILDPROPS_H
+
+#include <sqlWriter.h>
+#include <glibmm/ustring.h>
+#include <boost/optional.hpp>
+
+namespace Gentoo {
+ namespace Utils {
+ class SplitEbuildProps : public DB::SqlWriter {
+ public:
+ SplitEbuildProps(const std::string & ce, int e, const std::string & cp, const boost::optional<Glib::ustring> & p);
+
+ void writeSql(AdHoc::Buffer & sql) override;
+ void bindParams(DB::Command * c, unsigned int & offset) override;
+
+ const int entityId;
+ const std::string colEntityName, colPropName;
+ const boost::optional<Glib::ustring> props;
+ };
+ }
+}
+
+#endif
+
diff --git a/gentoobrowse-api/service/xmlUtils.cpp b/gentoobrowse-api/service/utils/xmlUtils.cpp
index 3fc3b44..3fc3b44 100644
--- a/gentoobrowse-api/service/xmlUtils.cpp
+++ b/gentoobrowse-api/service/utils/xmlUtils.cpp
diff --git a/gentoobrowse-api/service/xmlUtils.h b/gentoobrowse-api/service/utils/xmlUtils.h
index 158e134..158e134 100644
--- a/gentoobrowse-api/service/xmlUtils.h
+++ b/gentoobrowse-api/service/utils/xmlUtils.h