Add a helper function for turning rpm problem set into python list

This commit is contained in:
Panu Matilainen 2010-03-13 12:28:26 +02:00
parent d910603736
commit c4b4944e8f
3 changed files with 15 additions and 8 deletions

View File

@ -125,3 +125,15 @@ PyObject *rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob)
return (PyObject *) s;
}
PyObject *rpmps_AsList(rpmps ps)
{
PyObject *problems = PyList_New(0);
rpmpsi psi = rpmpsInitIterator(ps);
while (rpmpsNextIterator(psi) >= 0) {
PyObject *prob = rpmprob_Wrap(&rpmProblem_Type, rpmpsGetProblem(psi));
PyList_Append(problems, prob);
Py_DECREF(prob);
}
rpmpsFreeIterator(psi);
return problems;
}

View File

@ -11,4 +11,6 @@ extern PyTypeObject rpmProblem_Type;
PyObject * rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob);
PyObject *rpmps_AsList(rpmps ps);
#endif

View File

@ -517,15 +517,8 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
static PyObject *
rpmts_Problems(rpmtsObject * s)
{
PyObject *problems = PyList_New(0);
rpmps ps = rpmtsProblems(s->ts);
rpmpsi psi = rpmpsInitIterator(ps);
while (rpmpsNextIterator(psi) >= 0) {
PyObject *prob = rpmprob_Wrap(&rpmProblem_Type, rpmpsGetProblem(psi));
PyList_Append(problems, prob);
Py_DECREF(prob);
}
rpmpsFreeIterator(psi);
PyObject *problems = rpmps_AsList(ps);
rpmpsFree(ps);
return problems;
}