[Debtags-commits] [svn] r2203 - in daemon: . src

Enrico Zini enrico at alioth.debian.org
Sun Dec 3 20:11:21 CET 2006


Author: enrico
Date: Sun Dec  3 20:11:21 2006
New Revision: 2203

Modified:
   daemon/   (props changed)
   daemon/src/debtagsd.cpp
Log:
 r3808 at viaza:  enrico | 2006-12-03 18:05:29 +0000
 Fixed handling of special::not-yet-tagged*


Modified: daemon/src/debtagsd.cpp
==============================================================================
--- daemon/src/debtagsd.cpp	(original)
+++ daemon/src/debtagsd.cpp	Sun Dec  3 20:11:21 2006
@@ -14,6 +14,7 @@
 #include <tagcoll/input/stdio.h>
 #include <tagcoll/input/zlib.h>
 #include <tagcoll/input/string.h>
+#include <tagcoll/expression.h>
 #include <tagcoll/TextFormat.h>
 
 #include <iostream>
@@ -109,153 +110,153 @@
 	Connection(int fd) : fd(fd), m_eof(false) {}
 	~Connection() { close(fd); }
 
-bool eof() const { return m_eof; }
+	bool eof() const { return m_eof; }
 
-// Read a line
-std::string readline()
-{
-	// TODO: use a timeout
-	std::string line;
-	char c;
-	while (true)
+	// Read a line
+	std::string readline()
 	{
-		int res = read(fd, &c, 1);
-		if (res == 0)
+		// TODO: use a timeout
+		std::string line;
+		char c;
+		while (true)
 		{
-			m_eof = true;
-			break;
+			int res = read(fd, &c, 1);
+			if (res == 0)
+			{
+				m_eof = true;
+				break;
+			}
+			if (res < 0)
+				throw wibble::exception::System("reading data");
+			if (c == '\n')
+				break;
+			line += c;
 		}
-		if (res < 0)
-			throw wibble::exception::System("reading data");
-		if (c == '\n')
-			break;
-		line += c;
+		return line;
 	}
-	return line;
-}
 
-// Consume all the input
-void discardRemainingInput()
-{
-	char buf[1024];
-	while (true)
+	// Consume all the input
+	void discardRemainingInput()
 	{
-		int res = read(fd, buf, 1024);
-		if (res == 0)
+		char buf[1024];
+		while (true)
 		{
-			m_eof = true;
-			break;
+			int res = read(fd, buf, 1024);
+			if (res == 0)
+			{
+				m_eof = true;
+				break;
+			}
+			if (res < 0)
+				throw wibble::exception::System("reading data");
 		}
-		if (res < 0)
-			throw wibble::exception::System("reading data");
 	}
-}
 
-// Write a string
-void write(const std::string& str)
-{
-	size_t res = ::write(fd, str.data(), str.size());
-	if (res != str.size())
-		throw wibble::exception::System("writing data");
-}
-
-void credentials(uid_t& uid, gid_t& gid)
-{
-	struct ucred cr;
-	socklen_t cl = sizeof(cr);
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == -1)
-		throw wibble::exception::System("reading socket peer credentials");
-	uid = cr.uid;
-	gid = cr.gid;
-}
+	// Write a string
+	void write(const std::string& str)
+	{
+		size_t res = ::write(fd, str.data(), str.size());
+		if (res != str.size())
+			throw wibble::exception::System("writing data");
+	}
+
+	void credentials(uid_t& uid, gid_t& gid)
+	{
+		struct ucred cr;
+		socklen_t cl = sizeof(cr);
+		if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == -1)
+			throw wibble::exception::System("reading socket peer credentials");
+		uid = cr.uid;
+		gid = cr.gid;
+	}
 };
 
 /// Deserialize a sequence of keywords
 std::vector<std::string> parseKeys(const std::string& str)
 {
-std::vector<std::string> res;
-wibble::Tokenizer tok(str, "[[:alnum:]_-]+", REG_EXTENDED);
-for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
-	res.push_back(*i);
-return res;
+	std::vector<std::string> res;
+	wibble::Tokenizer tok(str, "[[:alnum:]_-]+", REG_EXTENDED);
+	for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
+		res.push_back(*i);
+	return res;
 }
 
 /// Deserialize a sequence of tags
 std::set<std::string> parseTagset(const std::string& str)
 {
-std::set<std::string> res;
-wibble::Tokenizer tok(str, "[[:alnum:]:_-]+", REG_EXTENDED);
-for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
-	res.insert(*i);
-return res;
+	std::set<std::string> res;
+	wibble::Tokenizer tok(str, "[[:alnum:]:_-]+", REG_EXTENDED);
+	for (wibble::Tokenizer::const_iterator i = tok.begin(); i != tok.end(); ++i)
+		res.insert(*i);
+	return res;
 }
 
 class Tags : public std::set<std::string>
 {
 public:
-Tags(Config& cfg)
-{
-	tagcoll::input::Stdio in(cfg.vocabulary);
-	DebDBParser parser(in);
-	DebDBParser::Record rec;
-	while (parser.nextRecord(rec))
+	Tags(Config& cfg)
 	{
-		DebDBParser::Record::const_iterator i = rec.find("Tag");
-		if (i != rec.end()) insert(i->second);
+		tagcoll::input::Stdio in(cfg.vocabulary);
+		DebDBParser parser(in);
+		DebDBParser::Record rec;
+		while (parser.nextRecord(rec))
+		{
+			DebDBParser::Record::const_iterator i = rec.find("Tag");
+			if (i != rec.end()) insert(i->second);
+		}
 	}
-}
 
-bool has(const std::string& tag)
-{
-	return find(tag) != end();
-}
+	bool has(const std::string& tag)
+	{
+		return find(tag) != end();
+	}
 };
 
 /// Quick access to the short descriptions of every package
 class Descs : public std::map<std::string, std::pair<std::string, std::string> >
 {
-std::pair<std::string, std::string> none;
+	std::pair<std::string, std::string> none;
 public:
-Descs(Config& cfg)
-{
-	tagcoll::input::Stdio in(cfg.pkgdb);
-	DebDBParser parser(in);
-	DebDBParser::Record rec;
-	while (parser.nextRecord(rec))
-	{
-		size_t sd = rec["Description"].find("\n");
-		if (sd == string::npos)
-			insert(make_pair(rec["Package"],
-						make_pair(rec["Description"], string())));
-		else
-			insert(make_pair(rec["Package"],
-						make_pair(
-							rec["Description"].substr(0, sd),
-							rec["Description"].substr(sd+1))));
+	Descs(Config& cfg)
+	{
+		tagcoll::input::Stdio in(cfg.pkgdb);
+		DebDBParser parser(in);
+		DebDBParser::Record rec;
+		while (parser.nextRecord(rec))
+		{
+			size_t sd = rec["Description"].find("\n");
+			if (sd == string::npos)
+				insert(make_pair(rec["Package"],
+							make_pair(rec["Description"], string())));
+			else
+				insert(make_pair(rec["Package"],
+							make_pair(
+								rec["Description"].substr(0, sd),
+								rec["Description"].substr(sd+1))));
+		}
 	}
-}
 
-bool has(const std::string& pkg) const
-{
-	return find(pkg) != end();
-}
+	bool has(const std::string& pkg) const
+	{
+		return find(pkg) != end();
+	}
 
-const std::pair<std::string, std::string>& get(const std::string& pkg) const
-{
-	const_iterator i = find(pkg);
-	if (i == end())
-		return none;
-	else
-		return i->second;
-}
+	const std::pair<std::string, std::string>& get(const std::string& pkg) const
+	{
+		const_iterator i = find(pkg);
+		if (i == end())
+			return none;
+		else
+			return i->second;
+	}
 
-std::set<std::string> allNames() const
-{
-	std::set<std::string> res;
-	for (const_iterator i = begin(); i != end(); ++i)
-		res.insert(i->first);
-	return res;
-}
+	std::set<std::string> allNames() const
+	{
+		std::set<std::string> res;
+		for (const_iterator i = begin(); i != end(); ++i)
+			res.insert(i->first);
+		return res;
+	}
 };
 
 // Quick access to popcon votes
@@ -406,18 +407,39 @@
 			{
 				// Read the maximum number of tags allowed per package (default to 0)
 				size_t count = 0;
-				if (!line.empty() && isdigit(line[0]))
+				if (line.empty() || isdigit(line[0]))
+				{
 					count = strtoul(line.c_str(), NULL, 10);
 
-				// Send the top 500 untagged items, by popcon ordering
-				int sent = 0;
-				for (vector<string>::const_iterator i = popcon.ranked.begin();
-						i != popcon.ranked.end(); ++i)
-				{
-					// Only consider the packages that are in our package database
-					if (!desc.has(*i)) continue;
-					if (coll.getTagsOfItem(*i).size() <= count)
+					// Send the top 150 untagged items, by popcon ordering
+					int sent = 0;
+					for (vector<string>::const_iterator i = popcon.ranked.begin();
+							i != popcon.ranked.end(); ++i)
 					{
+						// Only consider the packages that are in our package database
+						if (!desc.has(*i)) continue;
+						set<string> tags = coll.getTagsOfItem(*i);
+						// Skip non-untagged items
+						if (tags.find("special::not-yet-tagged") == tags.end()) continue;
+						if (tags.size() - 2 == count)
+						{
+							if (++sent > 150) break;
+							outputPackage(*i, conn);
+						}
+					}
+				} else {
+					tagcoll::Expression expr(line);
+
+					// Send the top 150 untagged items, by popcon ordering
+					int sent = 0;
+					for (vector<string>::const_iterator i = popcon.ranked.begin();
+							i != popcon.ranked.end(); ++i)
+					{
+						// Only consider the packages that are in our package database
+						if (!desc.has(*i)) continue;
+						set<string> tags = coll.getTagsOfItem(*i);
+						// Skip items that do not match the expression
+						if (!expr(tags)) continue;
 						if (++sent > 150) break;
 						outputPackage(*i, conn);
 					}
@@ -531,7 +553,7 @@
 			{
 				stringstream str;
 				str << "Total: " << desc.size() << endl;
-				str << "Tagged: " << coll.itemCount() << endl;
+				str << "Tagged: " << (desc.size() - coll.getCardinality("special::not-yet-tagged")) << endl;
 				conn.write(str.str());
 			}
 			else if (cmd == "PATCH")
@@ -640,6 +662,17 @@
 	{
 		tagcoll::input::Stdio input(cfg.tagdb);
 		tagcoll::textformat::parse(input, tagcoll::coll::inserter(coll));
+		// Generate special::not-yet-tagged for the items without tags
+		for (Descs::const_iterator i = desc.begin(); i != desc.end(); ++i)
+			if (!coll.hasItem(i->first))
+			{
+				set<string> tags;
+				tags.insert("special::not-yet-tagged");
+				tags.insert(string("special::not-yet-tagged::") + i->first[0]);
+				coll.insert(wibble::singleton(i->first), tags);
+			}
+		// Alternative: strip special::not-yet-tagged
+		//tagcoll::textformat::parse(input, tagcoll::stream::filterTagsByExpression("!special::not-yet-tagged*", tagcoll::coll::inserter(coll)));
 		// TODO: read in all the saved patches, sorted by filename
 	}
 



More information about the Debtags-commits mailing list