Commit 8ad58480 authored by Michael Vogt's avatar Michael Vogt

* python/metaindex.cc:

  - added support for the metaIndex objects
* python/sourceslist.cc:
  - support new "List" attribute that returns the list of
    metaIndex source entries
parent 9d88586c
......@@ -10,6 +10,11 @@ python-apt (0.7.4) UNRELEASED; urgency=low
can be found
* python/string.cc:
- fix overflow in SizeToStr()
* python/metaindex.cc:
- added support for the metaIndex objects
* python/sourceslist.cc:
- support new "List" attribute that returns the list of
metaIndex source entries
-- Michael Vogt <michael.vogt@ubuntu.com> Mon, 30 Jul 2007 22:33:59 +0200
......
import apt_pkg
apt_pkg.init()
sources = apt_pkg.GetPkgSourceList()
sources.ReadMainList()
for metaindex in sources.List:
print metaindex
print "URI: ",metaindex.URI
print "Dist: ",metaindex.Dist
print "IndexFiles: ","\n".join([str(i) for i in metaindex.IndexFiles])
print
......@@ -95,5 +95,8 @@ PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args);
// pkgSourceList
extern PyTypeObject PackageIndexFileType;
// metaIndex
extern PyTypeObject MetaIndexType;
#endif
......@@ -12,7 +12,7 @@ LIB_MAKES = apt-pkg/makefile
APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \
cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \
depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc \
indexfile.cc
indexfile.cc metaindex.cc
SOURCE := $(APT_PKG_SRC)
include $(PYTHON_H) progress.h
......
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
// $Id: metaindex.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $
/* ######################################################################
metaindex - Wrapper for the metaIndex functions
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
#include "generic.h"
#include "apt_pkgmodule.h"
#include <apt-pkg/metaindex.h>
#include <Python.h>
static PyObject *MetaIndexAttr(PyObject *Self,char *Name)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
if (strcmp("URI",Name) == 0)
return Safe_FromString(meta->GetURI().c_str());
else if (strcmp("Dist",Name) == 0)
return Safe_FromString(meta->GetDist().c_str());
else if (strcmp("IsTrusted",Name) == 0)
return Py_BuildValue("i",(meta->IsTrusted()));
else if (strcmp("IndexFiles",Name) == 0)
{
PyObject *List = PyList_New(0);
vector<pkgIndexFile *> *indexFiles = meta->GetIndexFiles();
for (vector<pkgIndexFile *>::const_iterator I = indexFiles->begin();
I != indexFiles->end(); I++)
{
PyObject *Obj;
Obj = CppPyObject_NEW<pkgIndexFile*>(&PackageIndexFileType,*I);
PyList_Append(List,Obj);
}
return List;
}
}
static PyObject *MetaIndexRepr(PyObject *Self)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
char S[1024];
snprintf(S,sizeof(S),"<metaIndex object: "
"Type='%s', URI:'%s' Dist='%s' IsTrusted='%i'>",
meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(),
meta->IsTrusted());
return PyString_FromString(S);
}
PyTypeObject MetaIndexType =
{
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"metaIndex", // tp_name
sizeof(CppOwnedPyObject<metaIndex*>), // tp_basicsize
0, // tp_itemsize
// Methods
CppOwnedDealloc<metaIndex*>, // tp_dealloc
0, // tp_print
MetaIndexAttr, // tp_getattr
0, // tp_setattr
0, // tp_compare
MetaIndexRepr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
};
......@@ -80,7 +80,21 @@ static PyMethodDef PkgSourceListMethods[] =
static PyObject *PkgSourceListAttr(PyObject *Self,char *Name)
{
return Py_FindMethod(PkgSourceListMethods,Self,Name);
pkgSourceList *list = GetCpp<pkgSourceList*>(Self);
if (strcmp("List",Name) == 0)
{
PyObject *List = PyList_New(0);
for (vector<metaIndex *>::const_iterator I = list->begin();
I != list->end(); I++)
{
PyObject *Obj;
Obj = CppPyObject_NEW<metaIndex*>(&MetaIndexType,*I);
PyList_Append(List,Obj);
}
return List;
}
return Py_FindMethod(PkgSourceListMethods,Self,Name);
}
PyTypeObject PkgSourceListType =
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment