From e5d16b671f2a625893731b4ea0bd684bbd444323 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Wed, 24 Nov 2004 10:00:36 +0000 Subject: Initial support for accessing source package data Author: mdz Date: 2003-07-23 02:20:24 GMT Initial support for accessing source package data --- python/pkgsrcrecords.cc | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 python/pkgsrcrecords.cc (limited to 'python/pkgsrcrecords.cc') diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc new file mode 100644 index 00000000..8f6dbbcf --- /dev/null +++ b/python/pkgsrcrecords.cc @@ -0,0 +1,118 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: pkgsrcrecords.cc,v 1.1 2003/07/23 02:20:24 mdz Exp $ +/* ###################################################################### + + Package Records - Wrapper for the package records functions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include + +#include + /*}}}*/ + +struct PkgSrcRecordsStruct +{ + pkgSourceList List; + pkgSrcRecords *Records; + pkgSrcRecords::Parser *Last; + + PkgSrcRecordsStruct() : Last(0) { + List.ReadMainList(); + Records = new pkgSrcRecords(List); + }; +}; + +// PkgSrcRecords Class /*{{{*/ +// --------------------------------------------------------------------- + +static char *doc_PkgSrcRecordsLookup = "xxx"; +static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) +{ + PkgSrcRecordsStruct &Struct = GetCpp(Self); + + char *Name = 0; + if (PyArg_ParseTuple(Args,"s",&Name) == 0) + return 0; + + Struct.Last = Struct.Records->Find(Name, false); + if (Struct.Last == 0) { + Struct.Records->Restart(); + return Py_None; + } + + return Py_BuildValue("i", 1); +} + +static PyMethodDef PkgSrcRecordsMethods[] = +{ + {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, + {} +}; + +static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name) +{ + PkgSrcRecordsStruct &Struct = GetCpp(Self); + + if (Struct.Last != 0) + { + if (strcmp("Package",Name) == 0) + return CppPyString(Struct.Last->Package()); + else if (strcmp("Version",Name) == 0) + return CppPyString(Struct.Last->Version()); + else if (strcmp("Maintainer",Name) == 0) + return CppPyString(Struct.Last->Maintainer()); + else if (strcmp("Section",Name) == 0) + return CppPyString(Struct.Last->Section()); + else if (strcmp("Binaries",Name) == 0) { + PyObject *List = PyList_New(0); + + for(const char **b = Struct.Last->Binaries(); + *b != 0; + ++b) + PyList_Append(List, CppPyString(*b)); + + return List; // todo + } else if (strcmp("Files",Name) == 0) + return 0; // todo + } + + return Py_FindMethod(PkgSrcRecordsMethods,Self,Name); +} +PyTypeObject PkgSrcRecordsType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgSrcRecords", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + PkgSrcRecordsAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + + /*}}}*/ + +PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) +{ + PyObject *Owner; +// if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) +// return 0; + + return HandleErrors(CppOwnedPyObject_NEW(Owner, + &PkgSrcRecordsType)); +} + -- cgit v1.2.3