Hello all, I've posted the first version of the Python bindings to the apt-front list, but it seems that I should have better posted it here.
I'm making some progress, although it's rather slow due to some obnoxious errors
I encounter, which I'll explain in another mail (some of them seem to be SWIG
bugs, though).
As already said, there are problems with nested classes/structs in SWIG, and as
long as those are not cared for, the affected structs and methods handling with
them have to be guarded by #ifdef symbols, which are defined when SWIG
preprocesses the headers.
There were also some syntactic peculiarities that SWIG could not handle, they
are also guarded.
In the patch for libtagcoll, I had to exchange
Expression operator and (const Expression& e);
Expression operator or (const Expression& e);
Expression operator not ();
with
Expression operator&& (const Expression& e);
Expression operator|| (const Expression& e);
Expression operator! ();
which works perfectly, since the former are only alii for the latter.
Enrico, I've attached a patch included all changes made to tagcoll.
For apt-front, it's mostly the same, only more.
* in cache/component/tags.h, I had to make facetData(...) and tagData(...)
protected, otherwise the SWIG code generator would fail.
* in cache/component/packages.h, I added the following:
typedef aptFront::cache::entity::Package value_type;
iterator begin() {
return packagesBegin();
}
iterator end() {
return packagesEnd();
}
This makes it possible to handle aptFront::cache::component::Packages like an
STL container, for which I wrote a small Python wrapper (see STLPyIterator.h in
the SWIG bindings). It would be nice if this could be adopted, but it's not a
must.
This is an excerpt from my other email to apt-front-devel:
I've created a distutils script, but the SWIG C++ support in distutils from
Python 2.4 still has some problems, so the code is generated manually as of now.
The script debtags.py tries to mimic the behaviour of the debtags binary to show
how the Python interface works. As of now, I'll try to implement the behaviour
of the actions listed at the end of debtags.py and fix the problems as the
occur. Then I'm going to look at the rest of apt-front. Please note that the old
scripts from swig/python will not work, since both the apt-front interface and
the Python interface have changed.
I'm also planning to split the Python interface into modules and hide some of
the classes the user does not instantiate directly.
===
The code for the SWIG bindings is available here:
http://diotavelli.net/files/apt-front-swig-python.tar.bz2
There are still a lot of rough edges (like the naming of instantiated
templates), but if you want to see what works already, have a look at
debtags.py.
If you want to build the Python bindings, just patch the headers of apt-front
and tagcoll. No recompilation is needed.
Bug reports, comments, suggestions welcome.
greetings
Torsten
--
Torsten Marek <[EMAIL PROTECTED]>
ID: A244C858 -- FP: 1902 0002 5DFC 856B F146 894C 7CC5 451E A244 C858
Keyserver: subkeys.pgp.net
Index: cache/component/tags.h
===================================================================
--- cache/component/tags.h (Revision 546)
+++ cache/component/tags.h (Arbeitskopie)
@@ -114,6 +114,9 @@
// making them private because I don't want Facet and Tag to access other
// Tags member, and other classes can't use these anyway as Facet::Data and
// Tag::Data are protected
+#ifdef SWIG
+ protected:
+#endif
const entity::Facet::Data& facetData(int idx) { return m_facets[idx]; }
const entity::Tag::Data& tagData(int idx) { return m_tags[idx]; }
};
Index: cache/component/records.h
===================================================================
--- cache/component/records.h (Revision 546)
+++ cache/component/records.h (Arbeitskopie)
@@ -31,15 +31,19 @@
};
Records();
virtual ~Records();
+#ifndef SWIG
const Record &record( entity::Version v );
+#endif
bool preload();
virtual void setOwnerCache( Cache *c );
/* pkgRecord conversion */
+#ifndef SWIG
Records( pkgRecords *P );
operator pkgRecords*() const {
return m_records;
}
+#endif
protected:
typedef std::map<entity::Version,Record> Map;
Index: cache/component/packages.h
===================================================================
--- cache/component/packages.h (Revision 546)
+++ cache/component/packages.h (Arbeitskopie)
@@ -69,8 +69,12 @@
std::string name;
bool valid:1;
};
+#ifndef SWIG
typedef entity::Iterator<entity::Package,
&entity::Package::nextInCache> iterator;
+#endif
+ typedef aptFront::cache::entity::Package value_type;
+
Packages( MMap *Map,bool DoMap = true );
virtual ~Packages();
@@ -91,6 +95,7 @@
return packageData( p ).name;
}
+#ifndef SWIG
const PackageData &packageData( const entity::Package &p ) {
PackageData &d = m_data[p.id()];
if (d.valid)
@@ -99,19 +104,28 @@
d.valid = true;
return d;
}
+#endif
/// output all the packages in a cache to a model of OutputIterator
template<class I> void packages(I i);
/// Get an iterator to the first package in the cache
+#ifndef SWIG
iterator packagesBegin() {
return iterator( entity::Package( PkgBegin() ) );
}
-
+ iterator begin() {
+ return packagesBegin();
+ }
+
/// Get an (invalid) iterator to the end of the cache
iterator packagesEnd() {
return iterator();
}
+ iterator end() {
+ return packagesEnd();
+ }
+#endif
/// return a package of a given name
entity::Package packageByName( const std::string& name );
Index: cache/component/state.h
===================================================================
--- cache/component/state.h (Revision 546)
+++ cache/component/state.h (Arbeitskopie)
@@ -42,7 +42,9 @@
State( cache::Cache *cache );
State( const State & ); // copy ctor - deep copying needed!
virtual ~State();
+#ifndef SWIG
entity::Package::State packageState( const entity::Package &i );
+#endif
bool isInstalled( const entity::Package &i );
// @todo add a Version variant of the above
Index: cache/entity/package.h
===================================================================
--- cache/entity/package.h (Revision 546)
+++ cache/entity/package.h (Arbeitskopie)
@@ -38,6 +38,7 @@
*/
class Package : public Implementation<Package> {
public:
+#ifndef SWIG
struct State {
enum Query {
Install = 1 << 0,
@@ -74,6 +75,7 @@
unsigned m_state;
};
+#endif
typedef actor::Actor< Package > Actor;
typedef actor::Bound< Package > BoundActor;
@@ -124,9 +126,15 @@
return p.valid() != valid();
}
+#ifdef SWIG
+protected:
+#endif
State state() const;
State state( const State & ) const throw();
+#ifdef SWIG
+public:
+#endif
inline pkgCache::Package *pkgPtr () const {
checkValid();
return m_package;
Index: sources.h
===================================================================
--- sources.h (Revision 546)
+++ sources.h (Arbeitskopie)
@@ -109,15 +109,19 @@
};
void parse();
void write();
+#ifndef SWIG
void add( const Entry &e ) {
m_entries.consume( e );
}
+#endif
void clear() { m_entries.clear(); }
+#ifndef SWIG
void disable( const Entry & );
void enable( const Entry & );
utils::Range< Entry > entries() const {
return m_entries;
}
+#endif
friend std::istream &operator >>( std::istream &i, Sources &s );
protected:
utils::VectorRange< Entry > m_entries;
Index: Expression.h
===================================================================
--- Expression.h (Revision 1392)
+++ Expression.h (Arbeitskopie)
@@ -107,9 +107,9 @@
return *this;
}
- Expression operator and (const Expression& e);
- Expression operator or (const Expression& e);
- Expression operator not ();
+ Expression operator&& (const Expression& e);
+ Expression operator|| (const Expression& e);
+ Expression operator! ();
template<typename M>
bool operator()(const OpSet<M>& tags) const { return m_impl->eval(tags); }
Index: InputMerger.h
===================================================================
--- InputMerger.h (Revision 1392)
+++ InputMerger.h (Arbeitskopie)
@@ -32,7 +32,9 @@
namespace Tagcoll
{
+#ifndef SWIG
template<typename, typename> class PatchList;
+#endif
/**
* Simple Collection.
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Debtags-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/debtags-devel

