2 * \file python/rpmps-py.c
14 rpmps_Debug(rpmpsObject * s, PyObject * args, PyObject * kwds)
16 char * kwlist[] = {"debugLevel", NULL};
18 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmps_debug))
26 rpmps_append(rpmpsObject * s, PyObject * value)
28 char *pkgNEVR, *altNEVR, *str1;
34 if (!PyArg_ParseTuple(value, "ssOiisN:rpmps value tuple",
35 &pkgNEVR, &altNEVR, &key,
36 &type, &ignoreProblem, &str1,
41 rpmpsAppend(s->ps, type, pkgNEVR, key, str1, NULL, altNEVR, ulong1);
46 rpmps_iter(rpmpsObject * s)
49 fprintf(stderr, "*** rpmps_iter(%p)\n", s);
50 s->psi = rpmpsInitIterator(s->ps);
56 rpmps_iternext(rpmpsObject * s)
58 PyObject * result = NULL;
61 fprintf(stderr, "*** rpmps_iternext(%p) ps %p psi %p\n", s, s->ps, s->psi);
63 /* Reset loop indices on 1st entry. */
65 s->psi = rpmpsInitIterator(s->ps);
68 /* If more to do, return a problem set string. */
69 if (rpmpsNextIterator(s->psi) >= 0) {
70 char * ps = rpmProblemString(rpmpsGetProblem(s->psi));
71 result = Py_BuildValue("s", ps);
74 s->psi = rpmpsFreeIterator(s->psi);
80 static struct PyMethodDef rpmps_methods[] = {
81 {"Debug", (PyCFunction)rpmps_Debug, METH_VARARGS|METH_KEYWORDS,
83 {"append", (PyCFunction)rpmps_append, METH_VARARGS, NULL},
84 {NULL, NULL} /* sentinel */
90 rpmps_dealloc(rpmpsObject * s)
93 fprintf(stderr, "*** rpmps_dealloc(%p)\n", s);
95 s->ps = rpmpsFree(s->ps);
101 rpmps_print(rpmpsObject * s, FILE * fp, int flags)
103 if (_rpmps_debug < 0)
104 fprintf(stderr, "*** rpmps_print(%p,%p,%x)\n", s, (void *)fp, flags);
106 rpmpsPrint(fp, s->ps);
110 static PyObject * rpmps_getattro(PyObject * o, PyObject * n)
112 if (_rpmps_debug < 0)
113 fprintf(stderr, "*** rpmps_getattro(%p,%p)\n", o, n);
114 return PyObject_GenericGetAttr(o, n);
117 static int rpmps_setattro(PyObject * o, PyObject * n, PyObject * v)
119 if (_rpmps_debug < 0)
120 fprintf(stderr, "*** rpmps_setattro(%p,%p,%p)\n", o, n, v);
121 return PyObject_GenericSetAttr(o, n, v);
125 rpmps_length(rpmpsObject * s)
128 rc = rpmpsNumProblems(s->ps);
129 if (_rpmps_debug < 0)
130 fprintf(stderr, "*** rpmps_length(%p) rc %d\n", s, rc);
135 rpmps_subscript(rpmpsObject * s, PyObject * key)
137 PyObject * result = NULL;
141 if (!PyInt_Check(key)) {
142 PyErr_SetString(PyExc_TypeError, "integer expected");
146 ix = (int) PyInt_AsLong(key);
147 /* XXX range check */
149 psi = rpmpsInitIterator(s->ps);
150 while ((i = rpmpsNextIterator(psi)) >= 0) {
152 char * ps = rpmProblemString(rpmpsGetProblem(psi));
153 result = Py_BuildValue("s", ps);
158 psi = rpmpsFreeIterator(psi);
160 if (_rpmps_debug < 0)
161 fprintf(stderr, "*** rpmps_subscript(%p,%p) %s\n", s, key, PyString_AsString(result));
166 static PyMappingMethods rpmps_as_mapping = {
167 (lenfunc) rpmps_length, /* mp_length */
168 (binaryfunc) rpmps_subscript, /* mp_subscript */
173 static int rpmps_init(rpmpsObject * s, PyObject *args, PyObject *kwds)
175 char * kwlist[] = {NULL};
177 if (_rpmps_debug < 0)
178 fprintf(stderr, "*** rpmps_init(%p,%p,%p)\n", s, args, kwds);
180 if (!PyArg_ParseTupleAndKeywords(args, kwds, ":rpmps_init", kwlist))
183 s->ps = rpmpsCreate();
191 static void rpmps_free(rpmpsObject * s)
194 fprintf(stderr, "%p -- ps %p\n", s, s->ps);
195 s->ps = rpmpsFree(s->ps);
197 PyObject_Del((PyObject *)s);
202 static PyObject * rpmps_alloc(PyTypeObject * subtype, int nitems)
204 PyObject * s = PyType_GenericAlloc(subtype, nitems);
206 if (_rpmps_debug < 0)
207 fprintf(stderr, "*** rpmps_alloc(%p,%d) ret %p\n", subtype, nitems, s);
213 static PyObject * rpmps_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
215 rpmpsObject * s = (void *) PyObject_New(rpmpsObject, subtype);
217 /* Perform additional initialization. */
218 if (rpmps_init(s, args, kwds) < 0) {
224 fprintf(stderr, "%p ++ ps %p\n", s, s->ps);
226 return (PyObject *)s;
231 static char rpmps_doc[] =
234 PyTypeObject rpmps_Type = {
235 PyObject_HEAD_INIT(&PyType_Type)
237 "rpm.ps", /* tp_name */
238 sizeof(rpmpsObject), /* tp_basicsize */
241 (destructor) rpmps_dealloc, /* tp_dealloc */
242 (printfunc) rpmps_print, /* tp_print */
243 (getattrfunc)0, /* tp_getattr */
244 (setattrfunc)0, /* tp_setattr */
245 (cmpfunc)0, /* tp_compare */
246 (reprfunc)0, /* tp_repr */
247 0, /* tp_as_number */
248 0, /* tp_as_sequence */
249 &rpmps_as_mapping, /* tp_as_mapping */
250 (hashfunc)0, /* tp_hash */
251 (ternaryfunc)0, /* tp_call */
252 (reprfunc)0, /* tp_str */
253 (getattrofunc) rpmps_getattro, /* tp_getattro */
254 (setattrofunc) rpmps_setattro, /* tp_setattro */
255 0, /* tp_as_buffer */
256 Py_TPFLAGS_DEFAULT, /* tp_flags */
257 rpmps_doc, /* tp_doc */
258 #if Py_TPFLAGS_HAVE_ITER
261 (richcmpfunc)0, /* tp_richcompare */
262 0, /* tp_weaklistoffset */
263 (getiterfunc) rpmps_iter, /* tp_iter */
264 (iternextfunc) rpmps_iternext, /* tp_iternext */
265 rpmps_methods, /* tp_methods */
270 0, /* tp_descr_get */
271 0, /* tp_descr_set */
272 0, /* tp_dictoffset */
273 (initproc) rpmps_init, /* tp_init */
274 (allocfunc) rpmps_alloc, /* tp_alloc */
275 (newfunc) rpmps_new, /* tp_new */
276 (freefunc) rpmps_free, /* tp_free */
283 rpmps psFromPs(rpmpsObject * s)
291 rpmpsObject * s = PyObject_New(rpmpsObject, &rpmps_Type);