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 _Py_NoneStruct @*/
00090         /*@modifies s, _Py_NoneStruct @*/
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 _Py_NoneStruct @*/
00106         /*@modifies s, _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         /*@globals _Py_NoneStruct @*/
00127         /*@modifies s, _Py_NoneStruct @*/
00128 {
00129     int rc = 0;
00130 
00131     if (!PyArg_ParseTuple(args, ":Instance"))
00132         return NULL;
00133 
00134     if (s->mi)
00135         rc = rpmdbGetIteratorOffset(s->mi);
00136 
00137     return Py_BuildValue("i", rc);
00138 }
00139 
00142 static PyObject *
00143 rpmmi_Count(rpmmiObject * s, PyObject * args)
00144         /*@globals _Py_NoneStruct @*/
00145         /*@modifies s, _Py_NoneStruct @*/
00146 {
00147     int rc = 0;
00148 
00149     if (!PyArg_ParseTuple(args, ":Instance"))
00150         return NULL;
00151 
00152     if (s->mi)
00153         rc = rpmdbGetIteratorCount(s->mi);
00154 
00155     return Py_BuildValue("i", rc);
00156 }
00157 
00160 static PyObject *
00161 rpmmi_Pattern(rpmmiObject * s, PyObject * args)
00162         /*@globals _Py_NoneStruct @*/
00163         /*@modifies s, _Py_NoneStruct @*/
00164 {
00165     PyObject *TagN = NULL;
00166     int type;
00167     char * pattern;
00168     rpmTag tag;
00169     
00170     if (!PyArg_ParseTuple(args, "Ois:Pattern", &TagN, &type, &pattern))
00171         return NULL;
00172 
00173     if ((tag = tagNumFromPyObject (TagN)) == -1) {
00174         PyErr_SetString(PyExc_TypeError, "unknown tag type");
00175         return NULL;
00176     }
00177 
00178     rpmdbSetIteratorRE(s->mi, tag, type, pattern);
00179 
00180     Py_INCREF (Py_None);
00181     return Py_None;
00182     
00183 }
00184 
00187 /*@-fullinitblock@*/
00188 /*@unchecked@*/ /*@observer@*/
00189 static struct PyMethodDef rpmmi_methods[] = {
00190     {"next",        (PyCFunction) rpmmi_Next,           METH_VARARGS,
00191 "mi.next() -> hdr\n\
00192 - Retrieve next header that matches. Iterate directly in python if possible.\n" },
00193     {"instance",    (PyCFunction) rpmmi_Instance,       METH_VARARGS,
00194         NULL },
00195     {"count",       (PyCFunction) rpmmi_Count,          METH_VARARGS,
00196         NULL },
00197     {"pattern",     (PyCFunction) rpmmi_Pattern,        METH_VARARGS,
00198 "mi.pattern(TagN, mire_type, pattern)\n\
00199 - Set a secondary match pattern on tags from retrieved header.\n" },
00200     {NULL,              NULL}           /* sentinel */
00201 };
00202 /*@=fullinitblock@*/
00203 
00206 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
00207         /*@modifies s @*/
00208 {
00209     if (s) {
00210         if (s->mi) s->mi = rpmdbFreeIterator(s->mi);
00211         PyMem_DEL(s);
00212     }
00213 }
00214 
00217 static PyObject * rpmmi_getattr (rpmmiObject *s, char *name)
00218         /*@*/
00219 {
00220     return Py_FindMethod (rpmmi_methods, (PyObject *) s, name);
00221 }
00222 
00225 /*@unchecked@*/ /*@observer@*/
00226 static char rpmmi_doc[] =
00227 "";
00228 
00231 /*@-fullinitblock@*/
00232 PyTypeObject rpmmi_Type = {
00233         PyObject_HEAD_INIT(NULL)
00234         0,                              /* ob_size */
00235         "rpm.mi",                       /* tp_name */
00236         sizeof(rpmmiObject),            /* tp_size */
00237         0,                              /* tp_itemsize */
00238         (destructor) rpmmi_dealloc,     /* tp_dealloc */
00239         0,                              /* tp_print */
00240         (getattrfunc) rpmmi_getattr,    /* tp_getattr */
00241         0,                              /* tp_setattr */
00242         0,                              /* tp_compare */
00243         0,                              /* tp_repr */
00244         0,                              /* tp_as_number */
00245         0,                              /* tp_as_sequence */
00246         0,                              /* tp_as_mapping */
00247         0,                              /* tp_hash */
00248         0,                              /* tp_call */
00249         0,                              /* tp_str */
00250         0,                              /* tp_getattro */
00251         0,                              /* tp_setattro */
00252         0,                              /* tp_as_buffer */
00253         Py_TPFLAGS_DEFAULT,             /* tp_flags */
00254         rpmmi_doc,                      /* tp_doc */
00255 #if Py_TPFLAGS_HAVE_ITER
00256         0,                              /* tp_traverse */
00257         0,                              /* tp_clear */
00258         0,                              /* tp_richcompare */
00259         0,                              /* tp_weaklistoffset */
00260         (getiterfunc) rpmmi_iter,       /* tp_iter */
00261         (iternextfunc) rpmmi_iternext,  /* tp_iternext */
00262         rpmmi_methods,                  /* tp_methods */
00263         0,                              /* tp_members */
00264         0,                              /* tp_getset */
00265         0,                              /* tp_base */
00266         0,                              /* tp_dict */
00267         0,                              /* tp_descr_get */
00268         0,                              /* tp_descr_set */
00269         0,                              /* tp_dictoffset */
00270         0,                              /* tp_init */
00271         0,                              /* tp_alloc */
00272         0,                              /* tp_new */
00273         0,                              /* tp_free */
00274         0,                              /* tp_is_gc */
00275 #endif
00276 };
00277 /*@=fullinitblock@*/
00278 
00279 rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
00280 {
00281     rpmmiObject * mio = (rpmmiObject *) PyObject_NEW(rpmmiObject, &rpmmi_Type);
00282 
00283     if (mio == NULL) {
00284         PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
00285         return NULL;
00286     }
00287     mio->mi = mi;
00288     return mio;
00289 }
00290 

Generated on Tue Sep 17 15:56:43 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002