From 543dfd085a39251894d86dcddbedb414fb9de6c3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Jun 2014 09:53:08 +0200 Subject: Add apt_pkg.SourceRecords.next() to step through all SrcRecords --- python/pkgsrcrecords.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'python') diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 6a60a9af..06602b9f 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -75,10 +75,34 @@ static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) return HandleErrors(Py_None); } +static char *doc_PkgSrcRecordsNext = + "next() -> bool\n\n" + "Go to the source package. Each call moves\n" + "the position of the records parser forward. If there are no\n" + "more records, return None. If the lookup failed this way,\n" + "access to any of the attributes will result in an AttributeError."; +static PyObject *PkgSrcRecordsNext(PyObject *Self,PyObject *Args) +{ + PkgSrcRecordsStruct &Struct = GetCpp(Self); + + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + Struct.Last = (pkgSrcRecords::Parser*)Struct.Records->Next(); + if (Struct.Last == 0) { + Struct.Records->Restart(); + Py_INCREF(Py_None); + return HandleErrors(Py_None); + } + + return PyBool_FromLong(1); +} + static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, + {"next",PkgSrcRecordsNext,METH_VARARGS,doc_PkgSrcRecordsNext}, {} }; -- cgit v1.2.3 From 887406dbb341ed684cd898f15b133baac252bc25 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 Jun 2014 17:13:51 +0200 Subject: rename apt_pkg.SourceRecords.next() to apt_pkg.SourceRecords.step() to avoid confusion with python iterators --- python/pkgsrcrecords.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'python') diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 06602b9f..308299e2 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -75,13 +75,13 @@ static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) return HandleErrors(Py_None); } -static char *doc_PkgSrcRecordsNext = - "next() -> bool\n\n" - "Go to the source package. Each call moves\n" +static char *doc_PkgSrcRecordsStep = + "step() -> bool\n\n" + "Step to the next source package. Each call moves\n" "the position of the records parser forward. If there are no\n" "more records, return None. If the lookup failed this way,\n" "access to any of the attributes will result in an AttributeError."; -static PyObject *PkgSrcRecordsNext(PyObject *Self,PyObject *Args) +static PyObject *PkgSrcRecordsStep(PyObject *Self,PyObject *Args) { PkgSrcRecordsStruct &Struct = GetCpp(Self); @@ -102,7 +102,7 @@ static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, - {"next",PkgSrcRecordsNext,METH_VARARGS,doc_PkgSrcRecordsNext}, + {"step",PkgSrcRecordsStep,METH_VARARGS,doc_PkgSrcRecordsStep}, {} }; -- cgit v1.2.3