[Debtags-commits] [svn] r1396 - debtags/trunk/tools

Enrico Zini enrico at costa.debian.org
Fri Oct 21 18:52:55 UTC 2005


Author: enrico
Date: Fri Oct 21 18:52:54 2005
New Revision: 1396

Modified:
   debtags/trunk/tools/Printer.h
   debtags/trunk/tools/debtags.cc
Log:
Implemented INSTALL using a printer

Modified: debtags/trunk/tools/Printer.h
==============================================================================
--- debtags/trunk/tools/Printer.h	(original)
+++ debtags/trunk/tools/Printer.h	Fri Oct 21 18:52:54 2005
@@ -1,11 +1,42 @@
+/*
+ * debtags - Implement package tags support for Debian
+ *
+ * Copyright (C) 2003,2004,2005  Enrico Zini <enrico at debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 #ifndef PRINTER_H
 #define PRINTER_H
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#define APPNAME PACKAGE_NAME
+#else
+#warning No config.h found: using fallback values
+#define APPNAME __FILE__
+#define PACKAGE_VERSION "unknown"
+#endif
+
 #include <apt-front/cache/entity/tag.h>
 #include <apt-front/cache/entity/package.h>
 #include <tagcoll/TextFormat.h>
 #include <tagcoll/ItemGrouper.h>
 
+#include <errno.h>
+
 
 template<typename ITEM, typename TAG>
 class Printer : public Tagcoll::Consumer<ITEM, TAG>
@@ -115,6 +146,14 @@
 	{
 		grouper.consume(pkg, tags);
 	}
+	virtual void consumeItemsUntagged(const Tagcoll::OpSet<Package>& pkgs)
+	{
+		grouper.consume(pkgs);
+	}
+	virtual void consumeItems(const Tagcoll::OpSet<Package>& pkgs, const Tagcoll::OpSet<Tag>& tags)
+	{
+		grouper.consume(pkgs, tags);
+	}
 
 public:
 	GroupedTagcollPrinter() : writer(fromitem, fromtag, stdout) {}
@@ -125,5 +164,46 @@
 	}
 };
 
+class Installer : public Printer<aptFront::cache::entity::Package, aptFront::cache::entity::Tag>
+{
+protected:
+	typedef aptFront::cache::entity::Package Package;
+	typedef aptFront::cache::entity::Tag Tag;
+
+	Tagcoll::OpSet<Package> selection;
+
+	virtual void consumeItemUntagged(const Package& pkg)
+	{
+		selection += pkg;
+	}
+	virtual void consumeItem(const Package& pkg, const Tagcoll::OpSet<Tag>& tags)
+	{
+		selection += pkg;
+	}
+	virtual void consumeItemsUntagged(const Tagcoll::OpSet<Package>& pkgs)
+	{
+		selection += pkgs;
+	}
+	virtual void consumeItems(const Tagcoll::OpSet<Package>& pkgs, const Tagcoll::OpSet<Tag>& tags)
+	{
+		selection += pkgs;
+	}
+
+public:
+	virtual void flush()
+	{
+		const char* parms[selection.size() + 1];
+		int i = 0;
+		parms[i++] = APTGET;
+		parms[i++] = "install";
+		for (Tagcoll::OpSet<Package>::iterator j = selection.begin();
+				j != selection.end(); j++)
+			parms[i++] = j->name().c_str();
+		parms[i] = 0;
+		execv(APTGET, (char* const*)parms);
+		throw Tagcoll::SystemException(errno, "Running apt-get");
+	}
+};
+
 // vim:set ts=4 sw=4:
 #endif

Modified: debtags/trunk/tools/debtags.cc
==============================================================================
--- debtags/trunk/tools/debtags.cc	(original)
+++ debtags/trunk/tools/debtags.cc	Fri Oct 21 18:52:54 2005
@@ -363,32 +363,6 @@
 
 };
 
-/**
- * Adaptor class to save all items in a stream of tagged items into an OpSet
- */
-template<typename ITEM, typename TAG>
-class ItemAdder : public Tagcoll::Consumer<ITEM, TAG>
-{
-protected:
-	OpSet<ITEM>& target;
-
-	// Process an untagged item
-	virtual void consumeItemUntagged(const ITEM& item) { target += item; }
-
-	// Process a tagged item, with its tags
-	virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags) { target += item; }
-
-	// Process a set of items, all with no tags
-	virtual void consumeItemsUntagged(const OpSet<ITEM>& items) { target += items; }
-
-	// Process a set of items identically tagged, with their tags
-	virtual void consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags) { target += items; } 
-
-public:
-	ItemAdder(OpSet<ITEM>& target) : target(target) {}
-	virtual ~ItemAdder() {}
-};
-
 template<class ITEM>
 class FacetcollPrinter : public Tagcoll::Consumer<ITEM, Facet>
 {
@@ -462,20 +436,6 @@
 	}
 };
 
-template<class ITEM, class TAG>
-int outputGrepped(component::PackageTags& debtags, const string& expression, bool invertMatch, Tagcoll::Consumer<ITEM, TAG>& cons)
-{
-	// Build the grep filter chain
-	FilterItemsByExpression<ITEM, TAG> filter(cons, expression);
-	if (invertMatch)
-		filter.setMatchType(FilterItemsByExpression<ITEM, TAG>::INVERTED);
-
-	debtags.outputPatched(filter);
-
-	return filter.countMatched();
-}
-
-
 
 /*
 class ItemPrinter : public Tagcoll::Tagcoll::Consumer<string, string>
@@ -1221,23 +1181,14 @@
 			{
 				component::PackageTags& debtags = debtagsInit();
 				wantTagDatabase();
+				Installer installer;
 
+				Searcher searcher(debtags, &installer);
 				string expression = args.next();
-				OpSet<entity::Package> selection;
-				ItemAdder<entity::Package, Tag> adder(selection);
-				if (!outputGrepped(debtags, expression, opts.get("invert-match").defined(), adder))
-					return 1;
 
-				const char* parms[selection.size() + 1];
-				int i = 0;
-				parms[i++] = APTGET;
-				parms[i++] = "install";
-				for (OpSet<entity::Package>::iterator j = selection.begin();
-						j != selection.end(); j++)
-					parms[i++] = j->name().c_str();
-				parms[i] = 0;
-				execv(APTGET, (char* const*)parms);
-				throw SystemException(errno, "Running apt-get");
+				searcher.output(expression, opts.get("invert-match").defined());
+
+				return 1;
 			}
 
 			// tagcat



More information about the Debtags-commits mailing list