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

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

Generated on Thu Mar 9 09:02:30 2006 for rpm by  doxygen 1.3.9.1