2 * \file python/rpmps-py.c
9 #include "rpmdebug-py.c"
17 rpmps_Debug(rpmpsObject * s, PyObject * args, PyObject * kwds)
19 char * kwlist[] = {"debugLevel", NULL};
21 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmps_debug))
29 rpmps_append(rpmpsObject * s, PyObject * value)
31 char *pkgNEVR, *altNEVR, *str1;
37 if (!PyArg_ParseTuple(value, "ssOiisN:rpmps value tuple",
38 &pkgNEVR, &altNEVR, &key,
39 &type, &ignoreProblem, &str1,
44 rpmpsAppend(s->ps, type, pkgNEVR, key, str1, NULL, altNEVR, ulong1);
49 rpmps_iter(rpmpsObject * s)
52 fprintf(stderr, "*** rpmps_iter(%p)\n", s);
53 s->psi = rpmpsInitIterator(s->ps);
59 rpmps_iternext(rpmpsObject * s)
61 PyObject * result = NULL;
64 fprintf(stderr, "*** rpmps_iternext(%p) ps %p psi %p\n", s, s->ps, s->psi);
66 /* Reset loop indices on 1st entry. */
68 s->psi = rpmpsInitIterator(s->ps);
71 /* If more to do, return a problem set string. */
72 if (rpmpsNextIterator(s->psi) >= 0) {
73 result = Py_BuildValue("s", rpmProblemString(rpmpsGetProblem(s->psi)));
75 s->psi = rpmpsFreeIterator(s->psi);
81 static struct PyMethodDef rpmps_methods[] = {
82 {"Debug", (PyCFunction)rpmps_Debug, METH_VARARGS|METH_KEYWORDS,
84 {"append", (PyCFunction)rpmps_append, METH_VARARGS, NULL},
85 {NULL, NULL} /* sentinel */
91 rpmps_dealloc(rpmpsObject * s)
94 fprintf(stderr, "*** rpmps_dealloc(%p)\n", s);
96 s->ps = rpmpsFree(s->ps);
102 rpmps_print(rpmpsObject * s, FILE * fp, int flags)
104 if (_rpmps_debug < 0)
105 fprintf(stderr, "*** rpmps_print(%p,%p,%x)\n", s, (void *)fp, flags);
107 rpmpsPrint(fp, s->ps);
111 static PyObject * rpmps_getattro(PyObject * o, PyObject * n)
113 if (_rpmps_debug < 0)
114 fprintf(stderr, "*** rpmps_getattro(%p,%p)\n", o, n);
115 return PyObject_GenericGetAttr(o, n);
118 static int rpmps_setattro(PyObject * o, PyObject * n, PyObject * v)
120 if (_rpmps_debug < 0)
121 fprintf(stderr, "*** rpmps_setattro(%p,%p,%p)\n", o, n, v);
122 return PyObject_GenericSetAttr(o, n, v);
126 rpmps_length(rpmpsObject * s)
129 rc = rpmpsNumProblems(s->ps);
130 if (_rpmps_debug < 0)
131 fprintf(stderr, "*** rpmps_length(%p) rc %d\n", s, rc);
136 rpmps_subscript(rpmpsObject * s, PyObject * key)
138 PyObject * result = NULL;
142 if (!PyInt_Check(key)) {
143 if (_rpmps_debug < 0)
144 fprintf(stderr, "*** rpmps_subscript(%p[%s],%p[%s])\n", s, lbl(s), key, lbl(key));
145 PyErr_SetString(PyExc_TypeError, "integer expected");
149 ix = (int) PyInt_AsLong(key);
150 /* XXX range check */
152 psi = rpmpsInitIterator(s->ps);
153 while ((i = rpmpsNextIterator(psi)) >= 0) {
155 result = Py_BuildValue("s", rpmProblemString(rpmpsGetProblem(psi)));
159 psi = rpmpsFreeIterator(psi);
161 if (_rpmps_debug < 0)
162 fprintf(stderr, "*** rpmps_subscript(%p,%p) %s\n", s, key, PyString_AsString(result));
167 static PyMappingMethods rpmps_as_mapping = {
168 (lenfunc) rpmps_length, /* mp_length */
169 (binaryfunc) rpmps_subscript, /* mp_subscript */
174 static int rpmps_init(rpmpsObject * s, PyObject *args, PyObject *kwds)
176 char * kwlist[] = {NULL};
178 if (_rpmps_debug < 0)
179 fprintf(stderr, "*** rpmps_init(%p,%p,%p)\n", s, args, kwds);
181 if (!PyArg_ParseTupleAndKeywords(args, kwds, ":rpmps_init", kwlist))
184 s->ps = rpmpsCreate();
192 static void rpmps_free(rpmpsObject * s)
195 fprintf(stderr, "%p -- ps %p\n", s, s->ps);
196 s->ps = rpmpsFree(s->ps);
198 PyObject_Del((PyObject *)s);
203 static PyObject * rpmps_alloc(PyTypeObject * subtype, int nitems)
205 PyObject * s = PyType_GenericAlloc(subtype, nitems);
207 if (_rpmps_debug < 0)
208 fprintf(stderr, "*** rpmps_alloc(%p,%d) ret %p\n", subtype, nitems, s);
214 static PyObject * rpmps_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
216 rpmpsObject * s = (void *) PyObject_New(rpmpsObject, subtype);
218 /* Perform additional initialization. */
219 if (rpmps_init(s, args, kwds) < 0) {
225 fprintf(stderr, "%p ++ ps %p\n", s, s->ps);
227 return (PyObject *)s;
232 static char rpmps_doc[] =
235 PyTypeObject rpmps_Type = {
236 PyObject_HEAD_INIT(&PyType_Type)
238 "rpm.ps", /* tp_name */
239 sizeof(rpmpsObject), /* tp_basicsize */
242 (destructor) rpmps_dealloc, /* tp_dealloc */
243 (printfunc) rpmps_print, /* tp_print */
244 (getattrfunc)0, /* tp_getattr */
245 (setattrfunc)0, /* tp_setattr */
246 (cmpfunc)0, /* tp_compare */
247 (reprfunc)0, /* tp_repr */
248 0, /* tp_as_number */
249 0, /* tp_as_sequence */
250 &rpmps_as_mapping, /* tp_as_mapping */
251 (hashfunc)0, /* tp_hash */
252 (ternaryfunc)0, /* tp_call */
253 (reprfunc)0, /* tp_str */
254 (getattrofunc) rpmps_getattro, /* tp_getattro */
255 (setattrofunc) rpmps_setattro, /* tp_setattro */
256 0, /* tp_as_buffer */
257 Py_TPFLAGS_DEFAULT, /* tp_flags */
258 rpmps_doc, /* tp_doc */
259 #if Py_TPFLAGS_HAVE_ITER
262 (richcmpfunc)0, /* tp_richcompare */
263 0, /* tp_weaklistoffset */
264 (getiterfunc) rpmps_iter, /* tp_iter */
265 (iternextfunc) rpmps_iternext, /* tp_iternext */
266 rpmps_methods, /* tp_methods */
271 0, /* tp_descr_get */
272 0, /* tp_descr_set */
273 0, /* tp_dictoffset */
274 (initproc) rpmps_init, /* tp_init */
275 (allocfunc) rpmps_alloc, /* tp_alloc */
276 (newfunc) rpmps_new, /* tp_new */
277 (freefunc) rpmps_free, /* tp_free */
284 rpmps psFromPs(rpmpsObject * s)
292 rpmpsObject * s = PyObject_New(rpmpsObject, &rpmps_Type);