From 170c310e75aa0bc417cb67f6e560fdaab482d72e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Jan 2006 23:27:33 +0000 Subject: * added support for pkgIndexFile --- debian/changelog | 3 +- doc/examples/indexfile.py | 20 +++++++++++++ python/apt_pkgmodule.h | 4 +++ python/indexfile.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++ python/makefile | 3 +- python/sourcelist.cc | 22 ++++++++++++-- 6 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 doc/examples/indexfile.py create mode 100644 python/indexfile.cc diff --git a/debian/changelog b/debian/changelog index 6c9d56ec..2635581d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ python-apt (0.6.16) unstable; urgency=low * apt/ API change: apt.Package.candidateOrigin returns a list of origins now instead of a single one * apt_pkg.Cdrom.Add() returns a boolean now, CdromProgress has totalSteps + * added support for pkgIndexFile and added SourcesList.FindIndex() - -- Michael Vogt Thu, 22 Dec 2005 10:21:51 +0100 + -- python-apt (0.6.15) unstable; urgency=low diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py new file mode 100644 index 00000000..e7f81e61 --- /dev/null +++ b/doc/examples/indexfile.py @@ -0,0 +1,20 @@ + +import apt_pkg + +apt_pkg.init() + +sources = apt_pkg.GetPkgSourceList() +sources.ReadMainList() + +cache = apt_pkg.GetCache() +depcache = apt_pkg.GetDepCache(cache) +pkg = cache["bzr"] +cand = depcache.GetCandidateVer(pkg) +for (f,i) in cand.FileList: + index = sources.FindIndex(f) + print index + if index: + print index.Size + print index.IsTrusted + print index.Exists + print index.HasPackages diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 84b0069f..fe7dfe88 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -91,4 +91,8 @@ PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args); extern PyTypeObject PkgSourceListType; PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args); +// pkgSourceList +extern PyTypeObject PackageIndexFileType; + + #endif diff --git a/python/indexfile.cc b/python/indexfile.cc new file mode 100644 index 00000000..4e106e25 --- /dev/null +++ b/python/indexfile.cc @@ -0,0 +1,76 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: indexfile.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ +/* ###################################################################### + + pkgIndexFile - Wrapper for the pkgIndexFilefunctions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include + +#include + + + +static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) +{ + pkgIndexFile *File = GetCpp(Self); + if (strcmp("Label",Name) == 0) + return Safe_FromString(File->GetType()->Label); + else if (strcmp("Describe",Name) == 0) + return Safe_FromString(File->Describe().c_str()); + else if (strcmp("Exists",Name) == 0) + return Py_BuildValue("i",(File->Exists())); + else if (strcmp("HasPackages",Name) == 0) + return Py_BuildValue("i",(File->HasPackages())); + else if (strcmp("Size",Name) == 0) + return Py_BuildValue("i",(File->Size())); + else if (strcmp("IsTrusted",Name) == 0) + return Py_BuildValue("i",(File->IsTrusted())); + + PyErr_SetString(PyExc_AttributeError,Name); + return 0; +} + +static PyObject *PackageIndexFileRepr(PyObject *Self) +{ + pkgIndexFile *File = GetCpp(Self); + + char S[300]; + snprintf(S,sizeof(S),"", + File->GetType()->Label, File->Describe().c_str(), File->Exists(), + File->HasPackages(), File->Size(), + File->IsTrusted(), File->ArchiveURI("").c_str()); + return PyString_FromString(S); +} +PyTypeObject PackageIndexFileType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgIndexFile", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + PackageIndexFileAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + PackageIndexFileRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + + + + diff --git a/python/makefile b/python/makefile index 7fb1d756..24ef3238 100644 --- a/python/makefile +++ b/python/makefile @@ -11,7 +11,8 @@ SLIBS = -lapt-pkg 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 + depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc \ + indexfile.cc SOURCE := $(APT_PKG_SRC) include $(PYTHON_H) progress.h diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 497731c0..16e51368 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -3,7 +3,7 @@ // $Id: sourcelist.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ /* ###################################################################### - Package Records - Wrapper for the package records functions + SourcesList - Wrapper for the SourcesList functions ##################################################################### */ /*}}}*/ @@ -16,6 +16,7 @@ #include /*}}}*/ + // PkgsourceList Class /*{{{*/ // --------------------------------------------------------------------- @@ -24,7 +25,24 @@ static char *doc_PkgSourceListFindIndex = "xxx"; static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { pkgSourceList *list = GetCpp(Self); - return Py_BuildValue("i", 1); + PyObject *pyPkgFileIter; + PyObject *pyPkgIndexFile; + + if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0) + return 0; + + pkgCache::PkgFileIterator &i = GetCpp(pyPkgFileIter); + pkgIndexFile *index; + if(list->FindIndex(i, index)) + { + pyPkgIndexFile = CppOwnedPyObject_NEW(pyPkgFileIter,&PackageIndexFileType,index); + return pyPkgIndexFile; + } + + //&PackageIndexFileType,&pyPkgIndexFile) + + Py_INCREF(Py_None); + return Py_None; } static char *doc_PkgSourceListReadMainList = "xxx"; -- cgit v1.2.3