[Debtags-commits] [svn] r1947 - in debtags/1.6.0: . tools
Enrico Zini
enrico at costa.debian.org
Sun Sep 24 17:09:51 UTC 2006
Author: enrico
Date: Sun Sep 24 17:09:50 2006
New Revision: 1947
Modified:
debtags/1.6.0/ (props changed)
debtags/1.6.0/tools/DebtagsOptions.h
debtags/1.6.0/tools/debtags.cc
Log:
r3383 at viaza: enrico | 2006-09-24 18:09:06 +0100
Added debtags vocfilter command
Modified: debtags/1.6.0/tools/DebtagsOptions.h
==============================================================================
--- debtags/1.6.0/tools/DebtagsOptions.h (original)
+++ debtags/1.6.0/tools/DebtagsOptions.h Sun Sep 24 17:09:50 2006
@@ -42,6 +42,7 @@
BoolOption* misc_local;
IntOption* misc_distance;
+ StringOption* misc_vocfile;
BoolOption* smse_reltags;
BoolOption* smse_disctags;
@@ -68,6 +69,7 @@
Engine* stats;
Engine* todoreport;
Engine* smartsearch;
+ Engine* vocfilter;
DebtagsOptions()
: StandardParserWithMandatoryCommand("debtags", VERSION, 1, "enrico at enricozini.org")
@@ -223,6 +225,11 @@
"only print the tag names sorted by increasing relevance");
smse_disctags = smartsearch->add<BoolOption>("discriminant", 0, "discriminant",
"only print the tag names sorted by increasing discriminance");
+
+ vocfilter = addEngine("vocfilter", "tagfile",
+ "filter out the tags that are not found in the given vocabulary file");
+ misc_vocfile = vocfilter->add<StringOption>("vocabulary", 0, "vocabulary",
+ "vocabulary file to use instead of the current debtags vocabulary");
}
};
Modified: debtags/1.6.0/tools/debtags.cc
==============================================================================
--- debtags/1.6.0/tools/debtags.cc (original)
+++ debtags/1.6.0/tools/debtags.cc Sun Sep 24 17:09:50 2006
@@ -46,6 +46,7 @@
#include <ept/cache/debtags/update.h>
+#include <ept/cache/debtags/vocabularymerger.h>
//#include <apt-pkg/configuration.h>
#include <errno.h>
@@ -374,6 +375,35 @@
}
};
+template<typename VOC, typename OUT>
+class VocabularyFilter : public wibble::mixin::OutputIterator< VocabularyFilter<VOC, OUT> >
+{
+protected:
+ const VOC& voc;
+ OUT out;
+
+public:
+ VocabularyFilter(const VOC& voc, const OUT& out) : voc(voc), out(out) {}
+
+ template<typename ITEMS, typename TAGS>
+ VocabularyFilter& operator=(const std::pair<ITEMS, TAGS>& data)
+ {
+ std::set< typename TAGS::value_type > tags;
+ for (typename TAGS::const_iterator i = data.second.begin();
+ i != data.second.end(); ++i)
+ if (voc.hasTag(*i))
+ tags.insert(*i);
+ *out = make_pair(data.first, tags);
+ ++out;
+ return *this;
+ }
+};
+template<typename VOC, typename OUT>
+VocabularyFilter<VOC, OUT> vocabularyFilter(const VOC& voc, const OUT& out)
+{
+ return VocabularyFilter<VOC, OUT>(voc, out);
+}
+
static void printShortVocabularyItem(const Facet& facet)
{
cout << facet.name() << " (facet) - " << facet.shortDescription() << endl;
@@ -1594,6 +1624,25 @@
//mode_t prev_umask = umask(022);
//umask(prev_umask);
}
+ else if (opts.foundCommand() == opts.vocfilter)
+ {
+ auto_ptr<Ept> ept = debtagsInit();
+
+ if (!opts.hasNext())
+ throw wibble::exception::BadOption("you should specify the file with the collection to check");
+
+ string file = opts.next();
+
+ if (opts.misc_vocfile->boolValue())
+ {
+ ept::t::cache::debtags::VocabularyMerger vm;
+ input::Stdio input(opts.misc_vocfile->stringValue());
+ vm.read(input);
+ ept->readCollectionRaw(file, vocabularyFilter(vm, textformat::OstreamWriter(cout)));
+ }
+ else
+ ept->readCollectionRaw(file, vocabularyFilter(ept->vocabulary(), textformat::OstreamWriter(cout)));
+ }
#if 0
// todoreport
// Print a report of packages needing work
More information about the Debtags-commits
mailing list