Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

python/rpmmi-py.c

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

Generated on Wed Dec 28 07:42:54 2016 for rpm by  doxygen 1.4.4