rpm
5.2.1
|
00001 00005 #include "system.h" 00006 00007 #include <rpmio.h> 00008 #include <rpmcb.h> /* XXX fnpyKey */ 00009 #include <rpmtypes.h> 00010 #include <rpmtag.h> 00011 #include <rpmdb.h> 00012 00013 #include "rpmmi-py.h" 00014 #include "header-py.h" 00015 00016 #include "debug.h" 00017 00069 static PyObject * 00070 rpmmi_iter(rpmmiObject * s) 00071 /*@*/ 00072 { 00073 Py_INCREF(s); 00074 return (PyObject *)s; 00075 } 00076 00079 /*@null@*/ 00080 static PyObject * 00081 rpmmi_iternext(rpmmiObject * s) 00082 /*@globals rpmGlobalMacroContext @*/ 00083 /*@modifies s, rpmGlobalMacroContext @*/ 00084 { 00085 Header h; 00086 00087 if (s->mi == NULL || (h = rpmmiNext(s->mi)) == NULL) { 00088 s->mi = rpmmiFree(s->mi); 00089 return NULL; 00090 } 00091 return (PyObject *) hdr_Wrap(h); 00092 } 00093 00096 /*@null@*/ 00097 static PyObject * 00098 rpmmi_Next(rpmmiObject * s) 00099 /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/ 00100 /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/ 00101 { 00102 PyObject * result; 00103 00104 result = rpmmi_iternext(s); 00105 00106 if (result == NULL) { 00107 Py_INCREF(Py_None); 00108 return Py_None; 00109 } 00110 return result; 00111 } 00112 00117 00120 /*@null@*/ 00121 static PyObject * 00122 rpmmi_Instance(rpmmiObject * s) 00123 /*@*/ 00124 { 00125 int rc = 0; 00126 00127 if (s->mi != NULL) 00128 rc = rpmmiInstance(s->mi); 00129 00130 return Py_BuildValue("i", rc); 00131 } 00132 00135 /*@null@*/ 00136 static PyObject * 00137 rpmmi_Count(rpmmiObject * s) 00138 /*@*/ 00139 { 00140 int rc = 0; 00141 00142 if (s->mi != NULL) 00143 rc = rpmmiCount(s->mi); 00144 00145 return Py_BuildValue("i", rc); 00146 } 00147 00150 /*@null@*/ 00151 static PyObject * 00152 rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds) 00153 /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/ 00154 /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/ 00155 { 00156 PyObject *TagN = NULL; 00157 int type; 00158 char * pattern; 00159 rpmTag tag; 00160 char * kwlist[] = {"tag", "type", "pattern", NULL}; 00161 00162 if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist, 00163 &TagN, &type, &pattern)) 00164 return NULL; 00165 00166 if ((tag = tagNumFromPyObject (TagN)) == (rpmTag)-1) { 00167 PyErr_SetString(PyExc_TypeError, "unknown tag type"); 00168 return NULL; 00169 } 00170 00171 rpmmiAddPattern(s->mi, tag, type, pattern); 00172 00173 Py_INCREF (Py_None); 00174 return Py_None; 00175 00176 } 00177 00182 /*@-fullinitblock@*/ 00183 /*@unchecked@*/ /*@observer@*/ 00184 static struct PyMethodDef rpmmi_methods[] = { 00185 {"next", (PyCFunction) rpmmi_Next, METH_NOARGS, 00186 "mi.next() -> hdr\n\ 00187 - Retrieve next header that matches. Iterate directly in python if possible.\n" }, 00188 {"instance", (PyCFunction) rpmmi_Instance, METH_NOARGS, 00189 NULL }, 00190 {"count", (PyCFunction) rpmmi_Count, METH_NOARGS, 00191 NULL }, 00192 {"pattern", (PyCFunction) rpmmi_Pattern, METH_VARARGS|METH_KEYWORDS, 00193 "mi.pattern(TagN, mire_type, pattern)\n\ 00194 - Set a secondary match pattern on tags from retrieved header.\n" }, 00195 {NULL, NULL} /* sentinel */ 00196 }; 00197 /*@=fullinitblock@*/ 00198 00201 static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s) 00202 /*@globals rpmGlobalMacroContext @*/ 00203 /*@modifies s, rpmGlobalMacroContext @*/ 00204 { 00205 if (s) { 00206 s->mi = rpmmiFree(s->mi); 00207 PyObject_Del(s); 00208 } 00209 } 00210 00211 static PyObject * rpmmi_getattro(PyObject * o, PyObject * n) 00212 /*@*/ 00213 { 00214 return PyObject_GenericGetAttr(o, n); 00215 } 00216 00217 static int rpmmi_setattro(PyObject * o, PyObject * n, PyObject * v) 00218 /*@*/ 00219 { 00220 return PyObject_GenericSetAttr(o, n, v); 00221 } 00222 00225 /*@unchecked@*/ /*@observer@*/ 00226 static char rpmmi_doc[] = 00227 ""; 00228 00231 /*@-fullinitblock@*/ 00232 PyTypeObject rpmmi_Type = { 00233 PyObject_HEAD_INIT(&PyType_Type) 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)0, /* 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 (getattrofunc) rpmmi_getattro, /* tp_getattro */ 00251 (setattrofunc) rpmmi_setattro, /* 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(rpmmi 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 }