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         PyObject_Del(s);
00205     }
00206 }
00207 
00208 static PyObject * rpmmi_getattro(PyObject * o, PyObject * n)
00209         /*@*/
00210 {
00211     return PyObject_GenericGetAttr(o, n);
00212 }
00213 
00214 static int rpmmi_setattro(PyObject * o, PyObject * n, PyObject * v)
00215         /*@*/
00216 {
00217     return PyObject_GenericSetAttr(o, n, v);
00218 }
00219 
00222 /*@unchecked@*/ /*@observer@*/
00223 static char rpmmi_doc[] =
00224 "";
00225 
00228 /*@-fullinitblock@*/
00229 PyTypeObject rpmmi_Type = {
00230         PyObject_HEAD_INIT(&PyType_Type)
00231         0,                              /* ob_size */
00232         "rpm.mi",                       /* tp_name */
00233         sizeof(rpmmiObject),            /* tp_size */
00234         0,                              /* tp_itemsize */
00235         (destructor) rpmmi_dealloc,     /* tp_dealloc */
00236         0,                              /* tp_print */
00237         (getattrfunc)0,                 /* tp_getattr */
00238         0,                              /* tp_setattr */
00239         0,                              /* tp_compare */
00240         0,                              /* tp_repr */
00241         0,                              /* tp_as_number */
00242         0,                              /* tp_as_sequence */
00243         0,                              /* tp_as_mapping */
00244         0,                              /* tp_hash */
00245         0,                              /* tp_call */
00246         0,                              /* tp_str */
00247         (getattrofunc) rpmmi_getattro,  /* tp_getattro */
00248         (setattrofunc) rpmmi_setattro,  /* tp_setattro */
00249         0,                              /* tp_as_buffer */
00250         Py_TPFLAGS_DEFAULT,             /* tp_flags */
00251         rpmmi_doc,                      /* tp_doc */
00252 #if Py_TPFLAGS_HAVE_ITER
00253         0,                              /* tp_traverse */
00254         0,                              /* tp_clear */
00255         0,                              /* tp_richcompare */
00256         0,                              /* tp_weaklistoffset */
00257         (getiterfunc) rpmmi_iter,       /* tp_iter */
00258         (iternextfunc) rpmmi_iternext,  /* tp_iternext */
00259         rpmmi_methods,                  /* tp_methods */
00260         0,                              /* tp_members */
00261         0,                              /* tp_getset */
00262         0,                              /* tp_base */
00263         0,                              /* tp_dict */
00264         0,                              /* tp_descr_get */
00265         0,                              /* tp_descr_set */
00266         0,                              /* tp_dictoffset */
00267         0,                              /* tp_init */
00268         0,                              /* tp_alloc */
00269         0,                              /* tp_new */
00270         0,                              /* tp_free */
00271         0,                              /* tp_is_gc */
00272 #endif
00273 };
00274 /*@=fullinitblock@*/
00275 
00276 rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
00277 {
00278     rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
00279 
00280     if (mio == NULL) {
00281         PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
00282         return NULL;
00283     }
00284     mio->mi = mi;
00285     return mio;
00286 }

Generated on Sat Oct 1 21:46:15 2011 for rpm by  doxygen 1.4.4