rpm  5.4.15
rpmmi-py.c
Go to the documentation of this file.
1 
5 #include "system-py.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 *
71  /*@*/
72 {
73  Py_INCREF(s);
74  return (PyObject *)s;
75 }
76 
79 /*@null@*/
80 static PyObject *
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 *
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_RETURN_NONE;
108  }
109  return result;
110 }
111 
116 
119 /*@null@*/
120 static PyObject *
122  /*@*/
123 {
124  uint32_t hdrNum = (s->mi != NULL) ? rpmmiInstance(s->mi) : 0;
125  return Py_BuildValue("i", hdrNum);
126 }
127 
130 /*@null@*/
131 static PyObject *
133  /*@*/
134 {
135  int rc = 0;
136 
137  DEPRECATED_METHOD("use len(mi) instead");
138  if (s->mi != NULL)
139  rc = rpmmiCount(s->mi);
140 
141  return Py_BuildValue("i", rc);
142 }
143 
146 /*@null@*/
147 static PyObject *
148 rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
149  /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
150  /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
151 {
152  PyObject *TagN = NULL;
153  int type;
154  char * pattern;
155  rpmTag tag;
156  char * kwlist[] = {"tag", "type", "pattern", NULL};
157 
158  if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
159  &TagN, &type, &pattern))
160  return NULL;
161 
162  if ((tag = tagNumFromPyObject (TagN)) == (rpmTag)-1) {
163  PyErr_SetString(PyExc_TypeError, "unknown tag type");
164  return NULL;
165  }
166 
167  rpmmiAddPattern(s->mi, tag, type, pattern);
168 
169  Py_RETURN_NONE;
170 }
171 
176 /*@-fullinitblock@*/
177 /*@unchecked@*/ /*@observer@*/
178 static struct PyMethodDef rpmmi_methods[] = {
179  {"next", (PyCFunction) rpmmi_Next, METH_NOARGS,
180 "mi.next() -> hdr\n\
181 - Retrieve next header that matches. Iterate directly in python if possible.\n" },
182  {"instance", (PyCFunction) rpmmi_Instance, METH_NOARGS,
183  NULL },
184  {"count", (PyCFunction) rpmmi_Count, METH_NOARGS,
185  NULL },
186  {"pattern", (PyCFunction) rpmmi_Pattern, METH_VARARGS|METH_KEYWORDS,
187 "mi.pattern(TagN, mire_type, pattern)\n\
188 - Set a secondary match pattern on tags from retrieved header.\n" },
189  {NULL, NULL} /* sentinel */
190 };
191 /*@=fullinitblock@*/
192 
195 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
196  /*@globals rpmGlobalMacroContext @*/
197  /*@modifies s, rpmGlobalMacroContext @*/
198 {
199  if (s) {
200  s->mi = rpmmiFree(s->mi);
201  PyObject_Del(s);
202  }
203 }
204 
207 /*@unchecked@*/ /*@observer@*/
208 static char rpmmi_doc[] =
209 "";
210 
213 /*@-fullinitblock@*/
214 PyTypeObject rpmmi_Type = {
215  PyVarObject_HEAD_INIT(&PyType_Type, 0)
216  "rpm.mi", /* tp_name */
217  sizeof(rpmmiObject), /* tp_size */
218  0, /* tp_itemsize */
219  (destructor) rpmmi_dealloc, /* tp_dealloc */
220  0, /* tp_print */
221  (getattrfunc)0, /* tp_getattr */
222  0, /* tp_setattr */
223  0, /* tp_compare */
224  0, /* tp_repr */
225  0, /* tp_as_number */
226  0, /* tp_as_sequence */
227  0, /* tp_as_mapping */
228  0, /* tp_hash */
229  0, /* tp_call */
230  0, /* tp_str */
231  PyObject_GenericGetAttr, /* tp_getattro */
232  PyObject_GenericSetAttr, /* tp_setattro */
233  0, /* tp_as_buffer */
234  Py_TPFLAGS_DEFAULT, /* tp_flags */
235  rpmmi_doc, /* tp_doc */
236 #if Py_TPFLAGS_HAVE_ITER
237  0, /* tp_traverse */
238  0, /* tp_clear */
239  0, /* tp_richcompare */
240  0, /* tp_weaklistoffset */
241  (getiterfunc) rpmmi_iter, /* tp_iter */
242  (iternextfunc) rpmmi_iternext, /* tp_iternext */
243  rpmmi_methods, /* tp_methods */
244  0, /* tp_members */
245  0, /* tp_getset */
246  0, /* tp_base */
247  0, /* tp_dict */
248  0, /* tp_descr_get */
249  0, /* tp_descr_set */
250  0, /* tp_dictoffset */
251  0, /* tp_init */
252  0, /* tp_alloc */
253  0, /* tp_new */
254  0, /* tp_free */
255  0, /* tp_is_gc */
256 #endif
257 };
258 /*@=fullinitblock@*/
259 
261 {
262  rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
263 
264  if (mio == NULL) {
265  PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
266  return NULL;
267  }
268  mio->mi = mi;
269  return mio;
270 }
rpmTag tagNumFromPyObject(PyObject *item)
Definition: header-py.c:362
rpmmi mi
Definition: rpmmi-py.h:20
hdrObject * hdr_Wrap(Header h)
Definition: header-py.c:678
static PyObject * rpmmi_Pattern(rpmmiObject *s, PyObject *args, PyObject *kwds)
Definition: rpmmi-py.c:148
uint32_t rpmmiInstance(rpmmi mi)
Return header instance for current position of rpmdb iterator.
Definition: rpmdb.c:1747
static PyObject * rpmmi_iternext(rpmmiObject *s)
Definition: rpmmi-py.c:81
The Header data structure.
Definition: rpmdb.c:436
rpmmiObject * rpmmi_Wrap(rpmmi mi)
Definition: rpmmi-py.c:260
struct rpmmiObject_s rpmmiObject
Definition: rpmmi-py.h:13
static char rpmmi_doc[]
Definition: rpmmi-py.c:208
rpmmi rpmmiFree(rpmmi mi)
Destroy rpm database iterator.
static PyObject * rpmmi_Instance(rpmmiObject *s)
Definition: rpmmi-py.c:121
PyTypeObject rpmmi_Type
Definition: rpmmi-py.c:214
int rpmmiAddPattern(rpmmi mi, rpmTag tag, rpmMireMode mode, const char *pattern)
Add pattern to iterator selector.
Definition: rpmdb.c:1910
static void rpmmi_dealloc(rpmmiObject *s)
Definition: rpmmi-py.c:195
static struct PyMethodDef rpmmi_methods[]
Definition: rpmmi-py.c:178
Header rpmmiNext(rpmmi mi)
Return next package header from iteration.
Definition: rpmdb.c:2252
PyObject * pyrpmError
Definition: rpmmodule.c:51
const char char type
Definition: bson.h:908
const char const char * pattern
Definition: bson.h:971
Access RPM indices using Berkeley DB interface(s).
enum rpmTag_e rpmTag
Definition: rpmtag.h:470
unsigned int rpmmiCount(rpmmi mi)
Return number of elements in rpm database iterator.
Definition: rpmdb.c:1763
static PyObject * rpmmi_Next(rpmmiObject *s)
Definition: rpmmi-py.c:98
static PyObject * rpmmi_iter(rpmmiObject *s)
Definition: rpmmi-py.c:70
static PyObject * rpmmi_Count(rpmmiObject *s)
Definition: rpmmi-py.c:132