2 * \file python/rpmds-py.c
10 #define PyObject_HEAD int _PyObjectHead;
15 #include "header-py.h"
23 rpmds_Debug(/*@unused@*/ rpmdsObject * s, PyObject * args)
24 /*@globals _Py_NoneStruct @*/
25 /*@modifies _Py_NoneStruct @*/
27 if (!PyArg_ParseTuple(args, "i", &_rpmds_debug)) return NULL;
33 rpmds_Count(rpmdsObject * s, PyObject * args)
36 if (!PyArg_ParseTuple(args, ":Count")) return NULL;
37 return Py_BuildValue("i", rpmdsCount(s->ds));
41 rpmds_Ix(rpmdsObject * s, PyObject * args)
44 if (!PyArg_ParseTuple(args, ":Ix")) return NULL;
45 return Py_BuildValue("i", rpmdsIx(s->ds));
49 rpmds_DNEVR(rpmdsObject * s, PyObject * args)
52 if (!PyArg_ParseTuple(args, ":DNEVR")) return NULL;
53 return Py_BuildValue("s", rpmdsDNEVR(s->ds));
57 rpmds_N(rpmdsObject * s, PyObject * args)
60 if (!PyArg_ParseTuple(args, ":N")) return NULL;
61 return Py_BuildValue("s", rpmdsN(s->ds));
65 rpmds_EVR(rpmdsObject * s, PyObject * args)
68 if (!PyArg_ParseTuple(args, ":EVR")) return NULL;
69 return Py_BuildValue("s", rpmdsEVR(s->ds));
73 rpmds_Flags(rpmdsObject * s, PyObject * args)
76 if (!PyArg_ParseTuple(args, ":Flags")) return NULL;
77 return Py_BuildValue("i", rpmdsFlags(s->ds));
81 rpmds_TagN(rpmdsObject * s, PyObject * args)
84 if (!PyArg_ParseTuple(args, ":TagN")) return NULL;
85 return Py_BuildValue("i", rpmdsTagN(s->ds));
89 rpmds_Color(rpmdsObject * s, PyObject * args)
92 if (!PyArg_ParseTuple(args, ":Color")) return NULL;
93 return Py_BuildValue("i", rpmdsColor(s->ds));
97 rpmds_Refs(rpmdsObject * s, PyObject * args)
100 if (!PyArg_ParseTuple(args, ":Refs")) return NULL;
101 return Py_BuildValue("i", rpmdsRefs(s->ds));
105 rpmds_compare(rpmdsObject * a, rpmdsObject * b)
108 return rpmdsCompare(a->ds, b->ds);
112 rpmds_iter(rpmdsObject * s)
116 return (PyObject *)s;
120 rpmds_iternext(rpmdsObject * s)
121 /*@globals _Py_NoneStruct @*/
122 /*@modifies s, _Py_NoneStruct @*/
124 PyObject * result = NULL;
126 /* Reset loop indices on 1st entry. */
132 /* If more to do, return a (N, EVR, Flags) tuple. */
133 if (rpmdsNext(s->ds) >= 0) {
134 const char * N = rpmdsN(s->ds);
135 const char * EVR = rpmdsEVR(s->ds);
136 int Flags = rpmdsFlags(s->ds);
138 result = PyTuple_New(3);
139 PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", N));
142 PyTuple_SET_ITEM(result, 1, Py_None);
144 PyTuple_SET_ITEM(result, 2, Py_None);
146 PyTuple_SET_ITEM(result, 1, Py_BuildValue("s", EVR));
147 PyTuple_SET_ITEM(result, 2, PyInt_FromLong(Flags));
157 rpmds_Next(rpmdsObject * s, PyObject *args)
158 /*@globals _Py_NoneStruct @*/
159 /*@modifies s, _Py_NoneStruct @*/
163 if (!PyArg_ParseTuple(args, ":Next"))
166 result = rpmds_iternext(s);
168 if (result == NULL) {
176 rpmds_SetNoPromote(rpmdsObject * s, PyObject * args)
181 if (!PyArg_ParseTuple(args, "i:SetNoPromote", &nopromote))
183 return Py_BuildValue("i", rpmdsSetNoPromote(s->ds, nopromote));
187 rpmds_Notify(rpmdsObject * s, PyObject * args)
188 /*@globals _Py_NoneStruct @*/
189 /*@modifies _Py_NoneStruct @*/
194 if (!PyArg_ParseTuple(args, "si:Notify", &where, &rc))
196 rpmdsNotify(s->ds, where, rc);
203 rpmds_Problem(rpmdsObject * s, PyObject * args)
206 if (!PyArg_ParseTuple(args, ":Problem"))
214 /*@unchecked@*/ /*@observer@*/
215 static struct PyMethodDef rpmds_methods[] = {
216 {"Debug", (PyCFunction)rpmds_Debug, METH_VARARGS,
218 {"Count", (PyCFunction)rpmds_Count, METH_VARARGS,
219 "ds.Count -> Count - Return no. of elements.\n" },
220 {"Ix", (PyCFunction)rpmds_Ix, METH_VARARGS,
221 "ds.Ix -> Ix - Return current element index.\n" },
222 {"DNEVR", (PyCFunction)rpmds_DNEVR, METH_VARARGS,
223 "ds.DNEVR -> DNEVR - Return current DNEVR.\n" },
224 {"N", (PyCFunction)rpmds_N, METH_VARARGS,
225 "ds.N -> N - Return current N.\n" },
226 {"EVR", (PyCFunction)rpmds_EVR, METH_VARARGS,
227 "ds.EVR -> EVR - Return current EVR.\n" },
228 {"Flags", (PyCFunction)rpmds_Flags, METH_VARARGS,
229 "ds.Flags -> Flags - Return current Flags.\n" },
230 {"TagN", (PyCFunction)rpmds_TagN, METH_VARARGS,
231 "ds.TagN -> TagN - Return current TagN.\n" },
232 {"Color", (PyCFunction)rpmds_Color, METH_VARARGS,
233 "ds.Color -> Color - Return current Color.\n" },
234 {"Refs", (PyCFunction)rpmds_Refs, METH_VARARGS,
235 "ds.Refs -> Refs - Return current Refs.\n" },
236 {"next", (PyCFunction)rpmds_Next, METH_VARARGS,
237 "ds.next() -> (N, EVR, Flags)\n\
238 - Retrieve next dependency triple.\n" },
239 {"SetNoPromote",(PyCFunction)rpmds_SetNoPromote, METH_VARARGS,
241 {"Notify", (PyCFunction)rpmds_Notify, METH_VARARGS,
244 {"Problem", (PyCFunction)rpmds_Problem, METH_VARARGS,
247 {NULL, NULL} /* sentinel */
254 rpmds_dealloc(rpmdsObject * s)
258 s->ds = rpmdsFree(s->ds);
264 rpmds_print(rpmdsObject * s, FILE * fp, /*@unused@*/ int flags)
265 /*@globals fileSystem @*/
266 /*@modifies s, fp, fileSystem @*/
272 while (rpmdsNext(s->ds) >= 0)
273 fprintf(fp, "%s\n", rpmdsDNEVR(s->ds));
278 rpmds_getattr(rpmdsObject * s, char * name)
281 return Py_FindMethod(rpmds_methods, (PyObject *)s, name);
285 rpmds_length(rpmdsObject * s)
288 return rpmdsCount(s->ds);
292 rpmds_subscript(rpmdsObject * s, PyObject * key)
297 if (!PyInt_Check(key)) {
298 PyErr_SetString(PyExc_TypeError, "integer expected");
302 ix = (int) PyInt_AsLong(key);
303 /* XXX make sure that DNEVR exists. */
304 rpmdsSetIx(s->ds, ix-1);
305 (void) rpmdsNext(s->ds);
306 return Py_BuildValue("s", rpmdsDNEVR(s->ds));
309 static PyMappingMethods rpmds_as_mapping = {
310 (inquiry) rpmds_length, /* mp_length */
311 (binaryfunc) rpmds_subscript, /* mp_subscript */
312 (objobjargproc)0, /* mp_ass_subscript */
317 /*@unchecked@*/ /*@observer@*/
318 static char rpmds_doc[] =
322 PyTypeObject rpmds_Type = {
323 PyObject_HEAD_INIT(&PyType_Type)
325 "rpm.ds", /* tp_name */
326 sizeof(rpmdsObject), /* tp_basicsize */
329 (destructor) rpmds_dealloc, /* tp_dealloc */
330 (printfunc) rpmds_print, /* tp_print */
331 (getattrfunc) rpmds_getattr, /* tp_getattr */
332 (setattrfunc) 0, /* tp_setattr */
333 (cmpfunc) rpmds_compare, /* tp_compare */
334 (reprfunc) 0, /* tp_repr */
335 0, /* tp_as_number */
336 0, /* tp_as_sequence */
337 &rpmds_as_mapping, /* tp_as_mapping */
338 (hashfunc) 0, /* tp_hash */
339 (ternaryfunc) 0, /* tp_call */
340 (reprfunc) 0, /* tp_str */
343 0, /* tp_as_buffer */
344 Py_TPFLAGS_DEFAULT, /* tp_flags */
345 rpmds_doc, /* tp_doc */
346 #if Py_TPFLAGS_HAVE_ITER
349 0, /* tp_richcompare */
350 0, /* tp_weaklistoffset */
351 (getiterfunc) rpmds_iter, /* tp_iter */
352 (iternextfunc) rpmds_iternext, /* tp_iternext */
353 rpmds_methods, /* tp_methods */
358 0, /* tp_descr_get */
359 0, /* tp_descr_set */
360 0, /* tp_dictoffset */
372 rpmds dsFromDs(rpmdsObject * s)
380 rpmdsObject * s = PyObject_New(rpmdsObject, &rpmds_Type);
390 rpmds_Single(/*@unused@*/ PyObject * s, PyObject * args)
392 PyObject * to = NULL;
393 int tagN = RPMTAG_PROVIDENAME;
395 const char * EVR = NULL;
398 if (!PyArg_ParseTuple(args, "Os|si:Single", &to, &N, &EVR, &Flags))
401 tagN = tagNumFromPyObject(to);
403 PyErr_SetString(PyExc_KeyError, "unknown header tag");
407 return rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
411 hdr_dsFromHeader(PyObject * s, PyObject * args)
413 hdrObject * ho = (hdrObject *)s;
414 PyObject * to = NULL;
415 rpmTag tagN = RPMTAG_REQUIRENAME;
418 if (!PyArg_ParseTuple(args, "|O:dsFromHeader", &to))
421 tagN = tagNumFromPyObject(to);
423 PyErr_SetString(PyExc_KeyError, "unknown header tag");
427 return rpmds_Wrap( rpmdsNew(hdrGetHeader(ho), tagN, scareMem) );
431 hdr_dsOfHeader(PyObject * s, PyObject * args)
433 hdrObject * ho = (hdrObject *)s;
434 int tagN = RPMTAG_PROVIDENAME;
435 int Flags = RPMSENSE_EQUAL;
437 if (!PyArg_ParseTuple(args, ":dsOfHeader"))
439 return rpmds_Wrap( rpmdsThis(hdrGetHeader(ho), tagN, Flags) );