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 --- python/indexfile.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 python/indexfile.cc (limited to 'python/indexfile.cc') 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 +}; + + + + -- cgit v1.2.3 From eef094d6218739bc0147910bfdd478ac10f18ec1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Mar 2006 15:07:21 +0100 Subject: * added indexFile.ArchiveURI(string) --- doc/examples/indexfile.py | 1 + python/indexfile.cc | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'python/indexfile.cc') diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py index 5eaab517..d383fd61 100644 --- a/doc/examples/indexfile.py +++ b/doc/examples/indexfile.py @@ -18,3 +18,4 @@ for (f,i) in cand.FileList: print index.IsTrusted print index.Exists print index.HasPackages + print index.ArchiveURI("some/path") diff --git a/python/indexfile.cc b/python/indexfile.cc index 4e106e25..ef6ffc8a 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -15,6 +15,22 @@ #include +static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args) +{ + pkgIndexFile *File = GetCpp(Self); + char *path; + + if (PyArg_ParseTuple(Args, "s",&path) == 0) + return 0; + + return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str())); +} + +static PyMethodDef PackageIndexFileMethods[] = +{ + {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, + {} +}; static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) @@ -33,8 +49,7 @@ static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) else if (strcmp("IsTrusted",Name) == 0) return Py_BuildValue("i",(File->IsTrusted())); - PyErr_SetString(PyExc_AttributeError,Name); - return 0; + return Py_FindMethod(PackageIndexFileMethods,Self,Name); } static PyObject *PackageIndexFileRepr(PyObject *Self) @@ -51,6 +66,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) File->IsTrusted(), File->ArchiveURI("").c_str()); return PyString_FromString(S); } + PyTypeObject PackageIndexFileType = { PyObject_HEAD_INIT(&PyType_Type) -- cgit v1.2.3