rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpmmi-py.c
Go to the documentation of this file.
1
5 #include "system.h"
6
7 #include <rpmio.h>
8 #include <rpmcb.h> /* XXX fnpyKey */
9 #include <rpmtypes.h>
10 #include <rpmtag.h>
11 #include <rpmdb.h>
12
13 #include "rpmmi-py.h"
14 #include "header-py.h"
15
16 #include "debug.h"
17
69 static PyObject *
70 rpmmi_iter(rpmmiObject * s)
71 /*@*/
72 {
73 Py_INCREF(s);
74 return (PyObject *)s;
75 }
76
79 /*@null@*/
80 static PyObject *
81 rpmmi_iternext(rpmmiObject * s)
82 /*@globals rpmGlobalMacroContext @*/
83 /*@modifies s, rpmGlobalMacroContext @*/
84 {
85 Header h;
86
87 if (s->mi == NULL || (h = rpmmiNext(s->mi)) == NULL) {
88 s->mi = rpmmiFree(s->mi);
89 return NULL;
90 }
91 return (PyObject *) hdr_Wrap(h);
92 }
93
96 /*@null@*/
97 static PyObject *
98 rpmmi_Next(rpmmiObject * s)
99 /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
100 /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
101 {
102 PyObject * result;
103
104 result = rpmmi_iternext(s);
105
106 if (result == NULL) {
107 Py_INCREF(Py_None);
108 return Py_None;
109 }
110 return result;
111 }
112
117
120 /*@null@*/
121 static PyObject *
122 rpmmi_Instance(rpmmiObject * s)
123 /*@*/
124 {
125 int rc = 0;
126
127 if (s->mi != NULL)
128 rc = rpmmiInstance(s->mi);
129
130 return Py_BuildValue("i", rc);
131 }
132
135 /*@null@*/
136 static PyObject *
137 rpmmi_Count(rpmmiObject * s)
138 /*@*/
139 {
140 int rc = 0;
141
142 if (s->mi != NULL)
143 rc = rpmmiCount(s->mi);
144
145 return Py_BuildValue("i", rc);
146 }
147
150 /*@null@*/
151 static PyObject *
152 rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
153 /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
154 /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
155 {
156 PyObject *TagN = NULL;
157 int type;
158 char * pattern;
159 rpmTag tag;
160 char * kwlist[] = {"tag", "type", "pattern", NULL};
161
162 if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
163 &TagN, &type, &pattern))
164 return NULL;
165
166 if ((tag = tagNumFromPyObject (TagN)) == (rpmTag)-1) {
167 PyErr_SetString(PyExc_TypeError, "unknown tag type");
168 return NULL;
169 }
170
171 rpmmiAddPattern(s->mi, tag, type, pattern);
172
173 Py_INCREF (Py_None);
174 return Py_None;
175
176 }
177
182 /*@-fullinitblock@*/
183 /*@unchecked@*/ /*@observer@*/
184 static struct PyMethodDef rpmmi_methods[] = {
185 {"next", (PyCFunction) rpmmi_Next, METH_NOARGS,
186 "mi.next() -> hdr\n\
187 - Retrieve next header that matches. Iterate directly in python if possible.\n" },
188 {"instance", (PyCFunction) rpmmi_Instance, METH_NOARGS,
189 NULL },
190 {"count", (PyCFunction) rpmmi_Count, METH_NOARGS,
191 NULL },
192 {"pattern", (PyCFunction) rpmmi_Pattern, METH_VARARGS|METH_KEYWORDS,
193 "mi.pattern(TagN, mire_type, pattern)\n\
194 - Set a secondary match pattern on tags from retrieved header.\n" },
195 {NULL, NULL} /* sentinel */
196 };
197 /*@=fullinitblock@*/
198
201 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
202 /*@globals rpmGlobalMacroContext @*/
203 /*@modifies s, rpmGlobalMacroContext @*/
204 {
205 if (s) {
206 s->mi = rpmmiFree(s->mi);
207 PyObject_Del(s);
208 }
209 }
210
211 static PyObject * rpmmi_getattro(PyObject * o, PyObject * n)
212 /*@*/
213 {
214 return PyObject_GenericGetAttr(o, n);
215 }
216
217 static int rpmmi_setattro(PyObject * o, PyObject * n, PyObject * v)
218 /*@*/
219 {
220 return PyObject_GenericSetAttr(o, n, v);
221 }
222
225 /*@unchecked@*/ /*@observer@*/
226 static char rpmmi_doc[] =
227 "";
228
231 /*@-fullinitblock@*/
232 PyTypeObject rpmmi_Type = {
233 PyObject_HEAD_INIT(&PyType_Type)
234 0, /* ob_size */
235 "rpm.mi", /* tp_name */
236 sizeof(rpmmiObject), /* tp_size */
237 0, /* tp_itemsize */
238 (destructor) rpmmi_dealloc, /* tp_dealloc */
239 0, /* tp_print */
240 (getattrfunc)0, /* tp_getattr */
241 0, /* tp_setattr */
242 0, /* tp_compare */
243 0, /* tp_repr */
244 0, /* tp_as_number */
245 0, /* tp_as_sequence */
246 0, /* tp_as_mapping */
247 0, /* tp_hash */
248 0, /* tp_call */
249 0, /* tp_str */
250 (getattrofunc) rpmmi_getattro, /* tp_getattro */
251 (setattrofunc) rpmmi_setattro, /* tp_setattro */
252 0, /* tp_as_buffer */
253 Py_TPFLAGS_DEFAULT, /* tp_flags */
254 rpmmi_doc, /* tp_doc */
255 #if Py_TPFLAGS_HAVE_ITER
256 0, /* tp_traverse */
257 0, /* tp_clear */
258 0, /* tp_richcompare */
259 0, /* tp_weaklistoffset */
260 (getiterfunc) rpmmi_iter, /* tp_iter */
261 (iternextfunc) rpmmi_iternext, /* tp_iternext */
262 rpmmi_methods, /* tp_methods */
263 0, /* tp_members */
264 0, /* tp_getset */
265 0, /* tp_base */
266 0, /* tp_dict */
267 0, /* tp_descr_get */
268 0, /* tp_descr_set */
269 0, /* tp_dictoffset */
270 0, /* tp_init */
271 0, /* tp_alloc */
272 0, /* tp_new */
273 0, /* tp_free */
274 0, /* tp_is_gc */
275 #endif
276 };
277 /*@=fullinitblock@*/
278
279 rpmmiObject * rpmmi_Wrap(rpmmi mi)
280 {
281 rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
282
283 if (mio == NULL) {
284 PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
285 return NULL;
286 }
287 mio->mi = mi;
288 return mio;
289 }