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

# python/rpmmi-py.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #include <rpmio.h>
    00008 #include <rpmcb.h>              /* XXX fnpyKey */
    00009 #include <rpmdb.h>
    00010 #include <rpmlib.h>
    00011
    00012 #include "rpmmi-py.h"
    00013 #include "header-py.h"
    00014
    00015 #include "debug.h"
    00016
    00068 static PyObject *
    00069 rpmmi_iter(rpmmiObject * s)
    00070         /*@*/
    00071 {
    00072     Py_INCREF(s);
    00073     return (PyObject *)s;
    00074 }
    00075
    00078 /*@null@*/
    00079 static PyObject *
    00080 rpmmi_iternext(rpmmiObject * s)
    00081         /*@globals rpmGlobalMacroContext @*/
    00082         /*@modifies s, rpmGlobalMacroContext @*/
    00083 {
    00084     Header h;
    00085
    00086     if (s->mi == NULL || (h = rpmdbNextIterator(s->mi)) == NULL) {
    00087         s->mi = rpmdbFreeIterator(s->mi);
    00088         return NULL;
    00089     }
    00090     return (PyObject *) hdr_Wrap(h);
    00091 }
    00092
    00095 /*@null@*/
    00096 static PyObject *
    00097 rpmmi_Next(rpmmiObject * s)
    00098         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
    00099         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
    00100 {
    00101     PyObject * result;
    00102
    00103     result = rpmmi_iternext(s);
    00104
    00105     if (result == NULL) {
    00106         Py_INCREF(Py_None);
    00107         return Py_None;
    00108     }
    00109     return result;
    00110 }
    00111
    00116
    00119 /*@null@*/
    00120 static PyObject *
    00121 rpmmi_Instance(rpmmiObject * s)
    00122         /*@*/
    00123 {
    00124     int rc = 0;
    00125
    00126     if (s->mi != NULL)
    00127         rc = rpmdbGetIteratorOffset(s->mi);
    00128
    00129     return Py_BuildValue("i", rc);
    00130 }
    00131
    00134 /*@null@*/
    00135 static PyObject *
    00136 rpmmi_Count(rpmmiObject * s)
    00137         /*@*/
    00138 {
    00139     int rc = 0;
    00140
    00141     if (s->mi != NULL)
    00142         rc = rpmdbGetIteratorCount(s->mi);
    00143
    00144     return Py_BuildValue("i", rc);
    00145 }
    00146
    00149 /*@null@*/
    00150 static PyObject *
    00151 rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
    00152         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
    00153         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
    00154 {
    00155     PyObject *TagN = NULL;
    00156     int type;
    00157     char * pattern;
    00158     rpmTag tag;
    00159     char * kwlist[] = {"tag", "type", "patern", NULL};
    00160
    00161     if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
    00162             &TagN, &type, &pattern))
    00163         return NULL;
    00164
    00165     if ((tag = tagNumFromPyObject (TagN)) == -1) {
    00166         PyErr_SetString(PyExc_TypeError, "unknown tag type");
    00167         return NULL;
    00168     }
    00169
    00170     rpmdbSetIteratorRE(s->mi, tag, type, pattern);
    00171
    00172     Py_INCREF (Py_None);
    00173     return Py_None;
    00174
    00175 }
    00176
    00181 /*@-fullinitblock@*/
    00182 /*@unchecked@*/ /*@observer@*/
    00183 static struct PyMethodDef rpmmi_methods[] = {
    00184     {"next",        (PyCFunction) rpmmi_Next,           METH_NOARGS,
    00185 "mi.next() -> hdr\n\
    00186 - Retrieve next header that matches. Iterate directly in python if possible.\n" },
    00187     {"instance",    (PyCFunction) rpmmi_Instance,       METH_NOARGS,
    00188         NULL },
    00189     {"count",       (PyCFunction) rpmmi_Count,          METH_NOARGS,
    00190         NULL },
    00191     {"pattern",     (PyCFunction) rpmmi_Pattern,        METH_VARARGS|METH_KEYWORDS,
    00192 "mi.pattern(TagN, mire_type, pattern)\n\
    00193 - Set a secondary match pattern on tags from retrieved header.\n" },
    00194     {NULL,              NULL}           /* sentinel */
    00195 };
    00196 /*@=fullinitblock@*/
    00197
    00200 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
    00201         /*@globals rpmGlobalMacroContext @*/
    00202         /*@modifies s, rpmGlobalMacroContext @*/
    00203 {
    00204     if (s) {
    00205         s->mi = rpmdbFreeIterator(s->mi);
    00206         PyObject_Del(s);
    00207     }
    00208 }
    00209
    00210 static PyObject * rpmmi_getattro(PyObject * o, PyObject * n)
    00211         /*@*/
    00212 {
    00213     return PyObject_GenericGetAttr(o, n);
    00214 }
    00215
    00216 static int rpmmi_setattro(PyObject * o, PyObject * n, PyObject * v)
    00217         /*@*/
    00218 {
    00219     return PyObject_GenericSetAttr(o, n, v);
    00220 }
    00221
    00224 /*@unchecked@*/ /*@observer@*/
    00225 static char rpmmi_doc[] =
    00226 "";
    00227
    00230 /*@-fullinitblock@*/
    00231 PyTypeObject rpmmi_Type = {
    00232         PyObject_HEAD_INIT(&PyType_Type)
    00233         0,                              /* ob_size */
    00234         "rpm.mi",                       /* tp_name */
    00235         sizeof(rpmmiObject),            /* tp_size */
    00236         0,                              /* tp_itemsize */
    00237         (destructor) rpmmi_dealloc,     /* tp_dealloc */
    00238         0,                              /* tp_print */
    00239         (getattrfunc)0,                 /* tp_getattr */
    00240         0,                              /* tp_setattr */
    00241         0,                              /* tp_compare */
    00242         0,                              /* tp_repr */
    00243         0,                              /* tp_as_number */
    00244         0,                              /* tp_as_sequence */
    00245         0,                              /* tp_as_mapping */
    00246         0,                              /* tp_hash */
    00247         0,                              /* tp_call */
    00248         0,                              /* tp_str */
    00249         (getattrofunc) rpmmi_getattro,  /* tp_getattro */
    00250         (setattrofunc) rpmmi_setattro,  /* tp_setattro */
    00251         0,                              /* tp_as_buffer */
    00252         Py_TPFLAGS_DEFAULT,             /* tp_flags */
    00253         rpmmi_doc,                      /* tp_doc */
    00254 #if Py_TPFLAGS_HAVE_ITER
    00255         0,                              /* tp_traverse */
    00256         0,                              /* tp_clear */
    00257         0,                              /* tp_richcompare */
    00258         0,                              /* tp_weaklistoffset */
    00259         (getiterfunc) rpmmi_iter,       /* tp_iter */
    00260         (iternextfunc) rpmmi_iternext,  /* tp_iternext */
    00261         rpmmi_methods,                  /* tp_methods */
    00262         0,                              /* tp_members */
    00263         0,                              /* tp_getset */
    00264         0,                              /* tp_base */
    00265         0,                              /* tp_dict */
    00266         0,                              /* tp_descr_get */
    00267         0,                              /* tp_descr_set */
    00268         0,                              /* tp_dictoffset */
    00269         0,                              /* tp_init */
    00270         0,                              /* tp_alloc */
    00271         0,                              /* tp_new */
    00272         0,                              /* tp_free */
    00273         0,                              /* tp_is_gc */
    00274 #endif
    00275 };
    00276 /*@=fullinitblock@*/
    00277
    00278 rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
    00279 {
    00280     rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
    00281
    00282     if (mio == NULL) {
    00283         PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
    00284         return NULL;
    00285     }
    00286     mio->mi = mi;
    00287     return mio;
    00288 }