Add minimal python wrapping for rpmProblem objects
- for now, only expose the basic attributes and return problem string representation on %s - return problem objects on rpmps iteration
This commit is contained in:
parent
5b289d4491
commit
a15bfa40ad
|
@ -212,6 +212,7 @@ void init_rpm(void)
|
|||
if (PyType_Ready(&rpmds_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmfi_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmmi_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmProblem_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmps_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmtd_Type) < 0) return;
|
||||
if (PyType_Ready(&rpmte_Type) < 0) return;
|
||||
|
@ -248,6 +249,9 @@ void init_rpm(void)
|
|||
Py_INCREF(&rpmmi_Type);
|
||||
PyModule_AddObject(m, "mi", (PyObject *) &rpmmi_Type);
|
||||
|
||||
Py_INCREF(&rpmProblem_Type);
|
||||
PyModule_AddObject(m, "prob", (PyObject *) &rpmProblem_Type);
|
||||
|
||||
Py_INCREF(&rpmps_Type);
|
||||
PyModule_AddObject(m, "ps", (PyObject *) &rpmps_Type);
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
#include "debug.h"
|
||||
|
||||
struct rpmProblemObject_s {
|
||||
PyObject_HEAD
|
||||
PyObject *md_dict;
|
||||
rpmProblem prob;
|
||||
};
|
||||
|
||||
struct rpmpsObject_s {
|
||||
PyObject_HEAD
|
||||
PyObject *md_dict; /*!< to look like PyModuleObject */
|
||||
|
@ -11,6 +17,105 @@ struct rpmpsObject_s {
|
|||
rpmpsi psi;
|
||||
};
|
||||
|
||||
static char rpmprob_doc[] =
|
||||
"";
|
||||
|
||||
static PyObject *rpmprob_get_type(rpmProblemObject *s, void *closure)
|
||||
{
|
||||
return Py_BuildValue("i", rpmProblemGetType(s->prob));
|
||||
}
|
||||
|
||||
static PyObject *rpmprob_get_pkgnevr(rpmProblemObject *s, void *closure)
|
||||
{
|
||||
return Py_BuildValue("s", rpmProblemGetPkgNEVR(s->prob));
|
||||
}
|
||||
|
||||
static PyObject *rpmprob_get_altnevr(rpmProblemObject *s, void *closure)
|
||||
{
|
||||
return Py_BuildValue("s", rpmProblemGetAltNEVR(s->prob));
|
||||
}
|
||||
|
||||
static PyObject *rpmprob_get_str(rpmProblemObject *s, void *closure)
|
||||
{
|
||||
return Py_BuildValue("s", rpmProblemGetStr(s->prob));
|
||||
}
|
||||
|
||||
static PyObject *rpmprob_get_num(rpmProblemObject *s, void *closure)
|
||||
{
|
||||
return Py_BuildValue("L", rpmProblemGetDiskNeed(s->prob));
|
||||
}
|
||||
|
||||
static PyGetSetDef rpmprob_getseters[] = {
|
||||
{ "type", (getter)rpmprob_get_type, NULL, NULL },
|
||||
{ "pkgNEVR", (getter)rpmprob_get_pkgnevr, NULL, NULL },
|
||||
{ "altNEVR", (getter)rpmprob_get_altnevr, NULL, NULL },
|
||||
{ "_str", (getter)rpmprob_get_str, NULL, NULL },
|
||||
{ "_num", (getter)rpmprob_get_num, NULL, NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyObject *rpmprob_str(rpmProblemObject *s)
|
||||
{
|
||||
char *str = rpmProblemString(s->prob);
|
||||
PyObject *res = Py_BuildValue("s", str);
|
||||
free(str);
|
||||
return res;
|
||||
}
|
||||
|
||||
PyTypeObject rpmProblem_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"rpm.prob", /* tp_name */
|
||||
sizeof(rpmProblemObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)0, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)0, /* tp_getattr */
|
||||
(setattrfunc)0, /* tp_setattr */
|
||||
(cmpfunc)0, /* tp_compare */
|
||||
(reprfunc)0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
(hashfunc)0, /* tp_hash */
|
||||
(ternaryfunc)0, /* tp_call */
|
||||
(reprfunc)rpmprob_str, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
PyObject_GenericSetAttr, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
rpmprob_doc, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
(richcmpfunc)0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
rpmprob_getseters, /* 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)0, /* tp_new */
|
||||
0, /* tp_free */
|
||||
0, /* tp_is_gc */
|
||||
};
|
||||
|
||||
static PyObject *rpmprob_Wrap(PyTypeObject *subtype, rpmProblem prob)
|
||||
{
|
||||
rpmProblemObject * s = (rpmProblemObject *)subtype->tp_alloc(subtype, 0);
|
||||
if (s == NULL) return PyErr_NoMemory();
|
||||
|
||||
s->prob = prob;
|
||||
return (PyObject *) s;
|
||||
}
|
||||
|
||||
static int
|
||||
rpmps_append(rpmpsObject * s, PyObject * value)
|
||||
{
|
||||
|
@ -41,11 +146,8 @@ rpmps_iternext(rpmpsObject * s)
|
|||
s->psi = rpmpsInitIterator(s->ps);
|
||||
}
|
||||
|
||||
/* If more to do, return a problem set string. */
|
||||
if (rpmpsNextIterator(s->psi) >= 0) {
|
||||
char * ps = rpmProblemString(rpmpsGetProblem(s->psi));
|
||||
result = Py_BuildValue("s", ps);
|
||||
free(ps);
|
||||
result = rpmprob_Wrap(&rpmProblem_Type, rpmpsGetProblem(s->psi));
|
||||
} else {
|
||||
s->psi = rpmpsFreeIterator(s->psi);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
|
||||
#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)
|
||||
|
||||
rpmps psFromPs(rpmpsObject * ps);
|
||||
|
|
Loading…
Reference in New Issue