[Debtags-commits] [svn] r705 - in libdebtags/trunk: . debtags swig swig/perl tests

Enrico Zini debtags-commits@lists.alioth.debian.org
Sat, 07 May 2005 20:27:35 +0000


Author: enrico
Date: Sat May  7 20:27:35 2005
New Revision: 705

Added:
   libdebtags/trunk/tests/ex-showpkgs.cc
Modified:
   libdebtags/trunk/   (props changed)
   libdebtags/trunk/debtags/Debtags.cc
   libdebtags/trunk/debtags/Debtags.h
   libdebtags/trunk/swig/libdebtags.i
   libdebtags/trunk/swig/perl/test.pl
   libdebtags/trunk/swig/test.py
   libdebtags/trunk/tests/Makefile.am
Log:
 r2881@viaza:  enrico | 2005-05-06 11:14:46 +0200
 Improved simplified interface
 Almost functionally complete bindings
 Added example for the new simplified interface


Modified: libdebtags/trunk/debtags/Debtags.cc
==============================================================================
--- libdebtags/trunk/debtags/Debtags.cc	(original)
+++ libdebtags/trunk/debtags/Debtags.cc	Sat May  7 20:27:35 2005
@@ -4,16 +4,37 @@
 
 #include <debtags/Debtags.h>
 #include <debtags/Paths.h>
+#include <debtags/TagSet.h>
+#include <debtags/PackageSet.h>
 
 namespace Debtags {
 
-Debtags::Debtags(bool editable) :
+DebtagsSimple::DebtagsSimple(bool editable) :
 		_vocab(Paths::path_vocabulary, Paths::path_vocabulary_index),
 		_serializer(_vocab, _packagedb),
 		_tagDB(_serializer, editable)
 {
 }
 
+TagSet DebtagsSimple::getTags(const std::string& package) const
+{
+	Package pkg = _packagedb.getPackage(package);
+	return _tagDB.getTags(pkg);
+}
+
+PackageSet DebtagsSimple::getPackages(const Tag& tag) const
+{
+	TagSet tags;
+	tags += tag;
+	return _tagDB.getItems(tags);
+}
+
+PackageSet DebtagsSimple::getPackages(const TagSet& tags) const
+{
+	return _tagDB.getItems(tags);
+}
+
+
 };
 
 #if 0

Modified: libdebtags/trunk/debtags/Debtags.h
==============================================================================
--- libdebtags/trunk/debtags/Debtags.h	(original)
+++ libdebtags/trunk/debtags/Debtags.h	Sat May  7 20:27:35 2005
@@ -1,8 +1,8 @@
-#ifndef DEBTAGS_H
-#define DEBTAGS_H
+#ifndef DEBTAGS_SIMPLE_H
+#define DEBTAGS_SIMPLE_H
 
 /*
- * Main entry point for Debtags
+ * Simplified interface for Debtags
  *
  * Copyright (C) 2003,2004,2005  Enrico Zini <enrico@debian.org>
  *
@@ -26,9 +26,52 @@
 #include <debtags/PackageDB.h>
 #include <debtags/Vocabulary.h>
 #include <debtags/TagDB.h>
-
 #include <string>
 
+
+namespace Debtags
+{
+
+class DebtagsSimple
+{
+	// If true, save state to ~/.debtags
+	bool editable;
+
+	// State directory
+	std::string rcdir;
+
+	// APT Package database
+	PackageDB _packagedb;
+
+	// Debtags vocabulary
+	Vocabulary _vocab;
+
+	// Debtags serializer
+	DebtagsSerializer _serializer;
+	
+	// Debtags database
+	TagDB _tagDB;
+
+public:
+	DebtagsSimple(bool editable);
+	~DebtagsSimple() throw () {}
+	
+	// Check if the tag database has been created (i.e. if debtags update has been run)
+	//bool hasTagDatabase() throw ();
+
+	Vocabulary& vocabulary() throw () { return _vocab; }
+	const Vocabulary& vocabulary() const throw () { return _vocab; }
+
+	TagDB& tagDB() throw () { return _tagDB; }
+	const TagDB& tagDB() const throw () { return _tagDB; }
+
+	TagSet getTags(const std::string& package) const;
+	PackageSet getPackages(const Tag& tag) const;
+	PackageSet getPackages(const TagSet& tags) const;
+};
+
+};
+
 #if 0
 #include <debtags/Environment.h>
 #include <debtags/Paths.h>
@@ -50,6 +93,8 @@
 #include <errno.h>
 #endif
 
+#if 0
+
 namespace Debtags
 {
 class FacetSet;
@@ -61,26 +106,8 @@
 using namespace std;
 using namespace Debtags;
 
-class Debtags
+class DebtagsSimple
 {
-	// If true, save state to ~/.debtags
-	bool editable;
-
-	// State directory
-	std::string rcdir;
-
-	// APT Package database
-	PackageDB _packagedb;
-
-	// Debtags vocabulary
-	Vocabulary _vocab;
-
-	// Debtags serializer
-	DebtagsSerializer _serializer;
-	
-	// Debtags database
-	TagDB _tagDB;
-
 #if 0
 	// Packages repository
 	mutable PackageSet _packages;
@@ -95,13 +122,6 @@
 	Package sectionToPackage(pkgTagSection& section) const throw ();
 #endif
 
-public:
-	Debtags(bool editable);
-	~Debtags() throw () {}
-	
-	// Check if the tag database has been created (i.e. if debtags update has been run)
-	bool hasTagDatabase() throw ();
-
 #if 0
 	// Return the main package search class
 	const PackageSet& packages() const throw ()
@@ -171,6 +191,7 @@
 };
 
 };
+#endif
 
 // vim:set ts=4 sw=4:
 #endif

Modified: libdebtags/trunk/swig/libdebtags.i
==============================================================================
--- libdebtags/trunk/swig/libdebtags.i	(original)
+++ libdebtags/trunk/swig/libdebtags.i	Sat May  7 20:27:35 2005
@@ -14,18 +14,29 @@
 #include "debtags/Vocabulary.h"
 #include "debtags/Tag.h"
 #include "debtags/TagSet.h"
+#include "debtags/Debtags.h"
+#include "debtags/Package.h"
+#include "debtags/PackageSet.h"
+#include "debtags/Maintainer.h"
+#include "debtags/MaintainerSet.h"
+#include "debtags/BasicPackageMatcher.h"
+#include "debtags/PackageDB.h"
 
 using namespace Tagcoll;
+using namespace Debtags;
 
 %}
 
 // Instantiate the base class needed but dont wrap it
 %include "../debtags/Tag.h"
+%include "../debtags/Package.h"
 %import "/usr/include/tagcoll/OpSet.h"
+%import "/usr/include/tagcoll/TDBReadonlyDiskIndex.h"
 
 %template(vecString) std::vector<std::string>;
 %template(vecTag) std::vector<Debtags::Tag>;
 %template(vecFacet) std::vector<Debtags::Facet>;
+%template(vecPackage) std::vector<Debtags::Package>;
 
 //%template(setString) std::set<std::string>;
 //%extend std::set<std::string> {
@@ -62,6 +73,15 @@
 	}
 }
 
+%template(OpSetPackage) Tagcoll::OpSet<Debtags::Package>;
+%extend Tagcoll::OpSet<Debtags::Package> {
+	std::vector<Debtags::Package> getIterable() {
+		return std::vector<Debtags::Package>(self->begin(), self->end());
+	}
+}
+
+%template(DebtagsTDBReadOnlyDiskIndex) Tagcoll::TDBReadonlyDiskIndex<Debtags::Package, Debtags::Tag>;
+
 //%ignore SmartPointer;
 //%ignore SmartPointerItem;
 
@@ -69,18 +89,40 @@
 
 %include "../debtags/Vocabulary.h"
 %include "../debtags/TagSet.h"
+%include "../debtags/DebtagsSerializer.h"
+%include "../debtags/TagDB.h"
+%include "../debtags/Debtags.h"
+%include "../debtags/PackageSet.h"
 
-%extend TagSet {
+%extend Debtags::TagSet {
 	std::vector<Debtags::Tag> getIterable() {
 		return std::vector<Debtags::Tag>(self->begin(), self->end());
 	}
+	void insert(Debtags::Tag& tag) {
+		*self += tag;
+	}
+	void insert(Debtags::TagSet& tags) {
+		*self += tags;
+	}
+	void remove(Debtags::Tag& tag) {
+		*self -= tag;
+	}
+	void remove(Debtags::TagSet& tags) {
+		*self -= tags;
+	}
 }
-%extend FacetSet {
+%extend Debtags::FacetSet {
 	std::vector<Debtags::Facet> getIterable() {
 		return std::vector<Debtags::Facet>(self->begin(), self->end());
 	}
 }
 
+%extend Debtags::PackageSet {
+	std::vector<Debtags::Package> getIterable() {
+		return std::vector<Debtags::Package>(self->begin(), self->end());
+	}
+}
+
 //%include "Consumer.h"
 //%include "Config.h"
 //%include "MailProgram.h"

Modified: libdebtags/trunk/swig/perl/test.pl
==============================================================================
--- libdebtags/trunk/swig/perl/test.pl	(original)
+++ libdebtags/trunk/swig/perl/test.pl	Sat May  7 20:27:35 2005
@@ -4,7 +4,10 @@
 use warnings;
 use Debtags;
 
-my $voc = Debtags::Vocabulary->new("/var/lib/debtags/vocabulary", "/var/lib/debtags/vocabulary.idx");
+my $dt = Debtags::DebtagsSimple->new(0);
+my $voc = $dt->vocabulary();
+
+#my $voc = Debtags::Vocabulary->new("/var/lib/debtags/vocabulary", "/var/lib/debtags/vocabulary.idx");
 
 if ($voc->hasFacet("accessibility"))
 {
@@ -18,3 +21,23 @@
 print join(', ', map { $_->name() } @{$fac->tags()->getIterable()});
 
 print "\n";
+
+my $tdb = $dt->tagDB();
+
+#print "Has tag database" if $tdb->hasTagDatabase();
+
+print "Tags for 'debtags': ", join(', ', map { $_->fullname() } @{$dt->getTags('debtags')->getIterable()}), "\n";
+
+my $editing = $voc->getTag("use::editing");
+
+print $editing->fullname(), "\n";
+
+my $tags = Debtags::TagSet->new();
+$tags->insert($editing);
+$tags->insert($voc->getTag('media::rasterimage'));
+
+#editors = dt.getPackages(editing)
+my $editors = $dt->getPackages($tags);
+
+print "Raster image editors: ", join(', ', map { $_->name() } @{$editors->getIterable()} ), "\n";
+

Modified: libdebtags/trunk/swig/test.py
==============================================================================
--- libdebtags/trunk/swig/test.py	(original)
+++ libdebtags/trunk/swig/test.py	Sat May  7 20:27:35 2005
@@ -1,12 +1,46 @@
 import Debtags
 
-voc = Debtags.Vocabulary("/var/lib/debtags/vocabulary", "/var/lib/debtags/vocabulary.idx")
-if voc.hasFacet("accessibility"):
-	print "hasFacet ok"
+dt = Debtags.DebtagsSimple(0)
+
+voc = dt.vocabulary()
+
+#voc = Debtags.Vocabulary("/var/lib/debtags/vocabulary", "/var/lib/debtags/vocabulary.idx")
+#if voc.hasFacet("accessibility"):
+#	print "hasFacet ok"
 
 fac = voc.getFacet("accessibility");
 print "Tags in 'accessibility::':"
 for a in fac.tags().getIterable():
 	print a.name()
 
+tdb = dt.tagDB()
+
+if tdb.hasTagDatabase():
+	print "Has tag database"
+
+print "Tags for 'debtags':"
+tags1 = dt.getTags("debtags")
+for a in tags1.getIterable():
+	print a.name()
+
+editing = voc.getTag("use::editing")
+
+print editing.fullname()
+
+tags = Debtags.TagSet()
+tags.insert(editing)
+
+print "here0"
+
+#editors = dt.getPackages(editing)
+editors = dt.getPackages(tags)
+
+print "Editors:"
+for a in editors.getIterable():
+	print a.name()
+
+print "here1"
+
+#dir(editors)
+
 # Hotel NH Mendoro 

Modified: libdebtags/trunk/tests/Makefile.am
==============================================================================
--- libdebtags/trunk/tests/Makefile.am	(original)
+++ libdebtags/trunk/tests/Makefile.am	Sat May  7 20:27:35 2005
@@ -3,7 +3,7 @@
 libdebtags_test_SOURCES = tut-main.cpp test-vocabulary.cc
 libdebtags_test_LDADD = ../debtags/libdebtags1.la @LIBTAGCOLL_LIBS@ -lapt-pkg 
 
-noinst_PROGRAMS = test-update test-packages test-packagedata test-dbcat ex-showpkg
+noinst_PROGRAMS = test-update test-packages test-packagedata test-dbcat ex-showpkg ex-showpkgs
 #test-maintainers 
 
 test_update_SOURCES = \
@@ -36,4 +36,9 @@
 ex_showpkg_LDADD = @LIBTAGCOLL_LIBS@ -lapt-pkg \
 	../debtags/libdebtags1.la
 
+ex_showpkgs_SOURCES = \
+	ex-showpkgs.cc
+ex_showpkgs_LDADD = @LIBTAGCOLL_LIBS@ -lapt-pkg \
+	../debtags/libdebtags1.la
+
 INCLUDES=@LIBTAGCOLL_CFLAGS@