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 "Python.h"
00008 #ifdef __LCLINT__
00009 #undef  PyObject_HEAD
00010 #define PyObject_HEAD   int _PyObjectHead;
00011 #endif
00012 
00013 #include <rpmlib.h>
00014 #include <rpmdb.h>
00015 
00016 #include "rpmmi-py.h"
00017 #include "header-py.h"
00018 
00019 #include "debug.h"
00020 
00074 
00077 static PyObject *
00078 rpmmi_iter(rpmmiObject * s)
00079         /*@*/
00080 {
00081     Py_INCREF(s);
00082     return (PyObject *)s;
00083 }
00084 
00087 static PyObject *
00088 rpmmi_iternext(rpmmiObject * s)
00089         /*@globals rpmGlobalMacroContext @*/
00090         /*@modifies s, rpmGlobalMacroContext @*/
00091 {
00092     Header h;
00093     
00094     if (s->mi == NULL || (h = rpmdbNextIterator(s->mi)) == NULL) {
00095         s->mi = rpmdbFreeIterator(s->mi);
00096         return NULL;
00097     }
00098     return (PyObject *) hdr_Wrap(h);
00099 }
00100 
00103 static PyObject *
00104 rpmmi_Next(rpmmiObject * s, PyObject *args)
00105         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00106         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00107 {
00108     PyObject * result;
00109     
00110     if (!PyArg_ParseTuple(args, ":Next"))
00111         return NULL;
00112 
00113     result = rpmmi_iternext(s);
00114 
00115     if (result == NULL) {
00116         Py_INCREF(Py_None);
00117         return Py_None;
00118     }
00119     return result;
00120 }
00121 
00124 static PyObject *
00125 rpmmi_Instance(rpmmiObject * s, PyObject * args)
00126         /*@*/
00127 {
00128     int rc = 0;
00129 
00130     if (!PyArg_ParseTuple(args, ":Instance"))
00131         return NULL;
00132 
00133     if (s->mi)
00134         rc = rpmdbGetIteratorOffset(s->mi);
00135 
00136     return Py_BuildValue("i", rc);
00137 }
00138 
00141 static PyObject *
00142 rpmmi_Count(rpmmiObject * s, PyObject * args)
00143         /*@*/
00144 {
00145     int rc = 0;
00146 
00147     if (!PyArg_ParseTuple(args, ":Instance"))
00148         return NULL;
00149 
00150     if (s->mi)
00151         rc = rpmdbGetIteratorCount(s->mi);
00152 
00153     return Py_BuildValue("i", rc);
00154 }
00155 
00158 static PyObject *
00159 rpmmi_Pattern(rpmmiObject * s, PyObject * args)
00160         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00161         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00162 {
00163     PyObject *TagN = NULL;
00164     int type;
00165     char * pattern;
00166     rpmTag tag;
00167     
00168     if (!PyArg_ParseTuple(args, "Ois:Pattern", &TagN, &type, &pattern))
00169         return NULL;
00170 
00171     if ((tag = tagNumFromPyObject (TagN)) == -1) {
00172         PyErr_SetString(PyExc_TypeError, "unknown tag type");
00173         return NULL;
00174     }
00175 
00176     rpmdbSetIteratorRE(s->mi, tag, type, pattern);
00177 
00178     Py_INCREF (Py_None);
00179     return Py_None;
00180     
00181 }
00182 
00185 /*@-fullinitblock@*/
00186 /*@unchecked@*/ /*@observer@*/
00187 static struct PyMethodDef rpmmi_methods[] = {
00188     {"next",        (PyCFunction) rpmmi_Next,           METH_VARARGS,
00189 "mi.next() -> hdr\n\
00190 - Retrieve next header that matches. Iterate directly in python if possible.\n" },
00191     {"instance",    (PyCFunction) rpmmi_Instance,       METH_VARARGS,
00192         NULL },
00193     {"count",       (PyCFunction) rpmmi_Count,          METH_VARARGS,
00194         NULL },
00195     {"pattern",     (PyCFunction) rpmmi_Pattern,        METH_VARARGS,
00196 "mi.pattern(TagN, mire_type, pattern)\n\
00197 - Set a secondary match pattern on tags from retrieved header.\n" },
00198     {NULL,              NULL}           /* sentinel */
00199 };
00200 /*@=fullinitblock@*/
00201 
00204 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
00205         /*@globals rpmGlobalMacroContext @*/
00206         /*@modifies s, rpmGlobalMacroContext @*/
00207 {
00208     if (s) {
00209         s->mi = rpmdbFreeIterator(s->mi);
00210         PyObject_Del(s);
00211     }
00212 }
00213 
00216 static PyObject * rpmmi_getattr (rpmmiObject *s, char *name)
00217         /*@*/
00218 {
00219     return Py_FindMethod (rpmmi_methods, (PyObject *) s, name);
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) rpmmi_getattr,    /* 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         0,                              /* tp_getattro */
00250         0,                              /* 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 }
00289 

Generated on Sun Oct 26 13:02:02 2003 for rpm by doxygen1.2.18