summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-11-18 10:41:26 +0200
committerPanu Matilainen <pmatilai@redhat.com>2009-11-18 10:41:26 +0200
commit66dd52d94c34b51eba9f0ef48bbe4df0e1b174ad (patch)
tree7c827c4af06d9255c0dbf0e871b9251776edb18c /python
parenta237f1eee0b495691c2a9565ad2b0f5140c00298 (diff)
downloadlibrpm-tizen-66dd52d94c34b51eba9f0ef48bbe4df0e1b174ad.tar.gz
librpm-tizen-66dd52d94c34b51eba9f0ef48bbe4df0e1b174ad.tar.bz2
librpm-tizen-66dd52d94c34b51eba9f0ef48bbe4df0e1b174ad.zip
Make python ts.problems() return a python list, not rpm.ps object
- rpm.ps object only supports iteration and subscript (with wonderfully wacko semantics), returning a regular list serves us better - rip the now useless rpm.ps object type
Diffstat (limited to 'python')
-rw-r--r--python/rpmmodule.c4
-rw-r--r--python/rpmps-py.c139
-rw-r--r--python/rpmps-py.h5
-rw-r--r--python/rpmts-py.c11
4 files changed, 12 insertions, 147 deletions
diff --git a/python/rpmmodule.c b/python/rpmmodule.c
index f448efd0a..128eb5486 100644
--- a/python/rpmmodule.c
+++ b/python/rpmmodule.c
@@ -214,7 +214,6 @@ static int prepareInitModule(void)
if (PyType_Ready(&rpmKeyring_Type) < 0) return 0;
if (PyType_Ready(&rpmmi_Type) < 0) return 0;
if (PyType_Ready(&rpmProblem_Type) < 0) return 0;
- if (PyType_Ready(&rpmps_Type) < 0) return 0;
if (PyType_Ready(&rpmPubkey_Type) < 0) return 0;
if (PyType_Ready(&rpmtd_Type) < 0) return 0;
if (PyType_Ready(&rpmte_Type) < 0) return 0;
@@ -314,9 +313,6 @@ static int initModule(PyObject *m)
Py_INCREF(&rpmProblem_Type);
PyModule_AddObject(m, "prob", (PyObject *) &rpmProblem_Type);
- Py_INCREF(&rpmps_Type);
- PyModule_AddObject(m, "ps", (PyObject *) &rpmps_Type);
-
Py_INCREF(&rpmPubkey_Type);
PyModule_AddObject(m, "pubkey", (PyObject *) &rpmPubkey_Type);
diff --git a/python/rpmps-py.c b/python/rpmps-py.c
index b6dcf3fee..ee47619e2 100644
--- a/python/rpmps-py.c
+++ b/python/rpmps-py.c
@@ -10,13 +10,6 @@ struct rpmProblemObject_s {
rpmProblem prob;
};
-struct rpmpsObject_s {
- PyObject_HEAD
- PyObject *md_dict; /*!< to look like PyModuleObject */
- rpmps ps;
- rpmpsi psi;
-};
-
static char rpmprob_doc[] =
"";
@@ -117,7 +110,7 @@ PyTypeObject rpmProblem_Type = {
0, /* tp_is_gc */
};
-static PyObject *rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob)
+PyObject *rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob)
{
rpmProblemObject * s = (rpmProblemObject *)subtype->tp_alloc(subtype, 0);
if (s == NULL) return NULL;
@@ -126,133 +119,3 @@ static PyObject *rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob)
return (PyObject *) s;
}
-static PyObject *
-rpmps_iternext(rpmpsObject * s)
-{
- PyObject * result = NULL;
-
- /* Reset loop indices on 1st entry. */
- if (s->psi == NULL) {
- s->psi = rpmpsInitIterator(s->ps);
- }
-
- if (rpmpsNextIterator(s->psi) >= 0) {
- result = rpmprob_Wrap(&rpmProblem_Type, rpmpsGetProblem(s->psi));
- } else {
- s->psi = rpmpsFreeIterator(s->psi);
- }
-
- return result;
-}
-
-static void
-rpmps_dealloc(rpmpsObject * s)
-{
- s->ps = rpmpsFree(s->ps);
- Py_TYPE(s)->tp_free((PyObject *)s);
-}
-
-static int
-rpmps_length(rpmpsObject * s)
-{
- int rc;
- rc = rpmpsNumProblems(s->ps);
- return rc;
-}
-
-static PyObject *
-rpmps_subscript(rpmpsObject * s, PyObject * key)
-{
- PyObject * result = NULL;
- rpmpsi psi;
- int ix, i;
-
- if (!PyInt_Check(key)) {
- PyErr_SetString(PyExc_TypeError, "integer expected");
- return NULL;
- }
-
- ix = (int) PyInt_AsLong(key);
- /* XXX range check */
-
- psi = rpmpsInitIterator(s->ps);
- while ((i = rpmpsNextIterator(psi)) >= 0) {
- if (i == ix) {
- char * ps = rpmProblemString(rpmpsGetProblem(psi));
- result = Py_BuildValue("s", ps);
- free(ps);
- break;
- }
- }
- psi = rpmpsFreeIterator(psi);
-
- return result;
-}
-
-static PyMappingMethods rpmps_as_mapping = {
- (lenfunc) rpmps_length, /* mp_length */
- (binaryfunc) rpmps_subscript, /* mp_subscript */
-};
-
-static PyObject * rpmps_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
-{
- rpmps ps = rpmpsCreate();
- return rpmps_Wrap(subtype, ps);
-}
-
-static char rpmps_doc[] =
-"";
-
-PyTypeObject rpmps_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "rpm.ps", /* tp_name */
- sizeof(rpmpsObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor) rpmps_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &rpmps_as_mapping, /* tp_as_mapping */
- (hashfunc)0, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- PyObject_GenericGetAttr, /* tp_getattro */
- PyObject_GenericSetAttr, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
- rpmps_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- PyObject_SelfIter, /* tp_iter */
- (iternextfunc) rpmps_iternext, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc) rpmps_new, /* tp_new */
- 0, /* tp_free */
- 0, /* tp_is_gc */
-};
-
-PyObject * rpmps_Wrap(PyTypeObject *subtype, rpmps ps)
-{
- rpmpsObject * s = (rpmpsObject *)subtype->tp_alloc(subtype, 0);
- if (s == NULL) return NULL;
-
- s->ps = ps; /* XXX refcounts? */
- s->psi = NULL;
- return (PyObject *) s;
-}
diff --git a/python/rpmps-py.h b/python/rpmps-py.h
index 86183a9d6..8cebb77e1 100644
--- a/python/rpmps-py.h
+++ b/python/rpmps-py.h
@@ -4,14 +4,11 @@
#include <rpm/rpmps.h>
typedef struct rpmProblemObject_s rpmProblemObject;
-typedef struct rpmpsObject_s rpmpsObject;
extern PyTypeObject rpmProblem_Type;
-extern PyTypeObject rpmps_Type;
#define rpmProblemObject_Check(v) ((v)->ob_type == &rpmProblem_Type)
-#define rpmpsObject_Check(v) ((v)->ob_type == &rpmps_Type)
-PyObject * rpmps_Wrap(PyTypeObject *subtype, rpmps ps);
+PyObject * rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob);
#endif
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index b2ac0cd47..f7748186a 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -512,7 +512,16 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
static PyObject *
rpmts_Problems(rpmtsObject * s)
{
- return rpmps_Wrap(&rpmps_Type, rpmtsProblems(s->ts));
+ 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);
+ }
+ rpmpsFreeIterator(psi);
+ rpmpsFree(ps);
+ return problems;
}
static PyObject *