1 #include "rpmsystem-py.h"
3 #include <rpm/rpmtypes.h>
4 #include <rpm/rpmpgp.h>
11 struct rpmfiObject_s {
13 PyObject *md_dict; /*!< to look like PyModuleObject */
19 rpmfi_FC(rpmfiObject * s)
21 return Py_BuildValue("i", rpmfiFC(s->fi));
25 rpmfi_FX(rpmfiObject * s)
27 return Py_BuildValue("i", rpmfiFX(s->fi));
31 rpmfi_DC(rpmfiObject * s)
33 return Py_BuildValue("i", rpmfiDC(s->fi));
37 rpmfi_DX(rpmfiObject * s)
39 return Py_BuildValue("i", rpmfiDX(s->fi));
43 rpmfi_BN(rpmfiObject * s)
45 return Py_BuildValue("s", rpmfiBN(s->fi));
49 rpmfi_DN(rpmfiObject * s)
51 return Py_BuildValue("s", rpmfiDN(s->fi));
55 rpmfi_FN(rpmfiObject * s)
57 return Py_BuildValue("s", rpmfiFN(s->fi));
61 rpmfi_FFlags(rpmfiObject * s)
63 return Py_BuildValue("i", rpmfiFFlags(s->fi));
67 rpmfi_VFlags(rpmfiObject * s)
69 return Py_BuildValue("i", rpmfiVFlags(s->fi));
73 rpmfi_FMode(rpmfiObject * s)
75 return Py_BuildValue("i", rpmfiFMode(s->fi));
79 rpmfi_FState(rpmfiObject * s)
81 return Py_BuildValue("i", rpmfiFState(s->fi));
84 /* XXX rpmfiFDigest */
86 rpmfi_Digest(rpmfiObject * s)
88 char *digest = rpmfiFDigestHex(s->fi, NULL);
90 PyObject *dig = Py_BuildValue("s", digest);
99 rpmfi_FLink(rpmfiObject * s)
101 return Py_BuildValue("s", rpmfiFLink(s->fi));
105 rpmfi_FSize(rpmfiObject * s)
107 return Py_BuildValue("L", rpmfiFSize(s->fi));
111 rpmfi_FRdev(rpmfiObject * s)
113 return Py_BuildValue("i", rpmfiFRdev(s->fi));
117 rpmfi_FMtime(rpmfiObject * s)
119 return Py_BuildValue("i", rpmfiFMtime(s->fi));
123 rpmfi_FUser(rpmfiObject * s)
125 return Py_BuildValue("s", rpmfiFUser(s->fi));
129 rpmfi_FGroup(rpmfiObject * s)
131 return Py_BuildValue("s", rpmfiFGroup(s->fi));
135 rpmfi_FColor(rpmfiObject * s)
137 return Py_BuildValue("i", rpmfiFColor(s->fi));
141 rpmfi_FClass(rpmfiObject * s)
145 if ((FClass = rpmfiFClass(s->fi)) == NULL)
147 return Py_BuildValue("s", FClass);
151 rpmfi_iternext(rpmfiObject * s)
153 PyObject * result = NULL;
155 /* Reset loop indices on 1st entry. */
157 s->fi = rpmfiInit(s->fi, 0);
161 /* If more to do, return the file tuple. */
162 if (rpmfiNext(s->fi) >= 0) {
163 const char * FN = rpmfiFN(s->fi);
164 rpm_loff_t FSize = rpmfiFSize(s->fi);
165 int FMode = rpmfiFMode(s->fi);
166 int FMtime = rpmfiFMtime(s->fi);
167 int FFlags = rpmfiFFlags(s->fi);
168 int FRdev = rpmfiFRdev(s->fi);
169 int FInode = rpmfiFInode(s->fi);
170 int FNlink = rpmfiFNlink(s->fi);
171 int FState = rpmfiFState(s->fi);
172 int VFlags = rpmfiVFlags(s->fi);
173 const char * FUser = rpmfiFUser(s->fi);
174 const char * FGroup = rpmfiFGroup(s->fi);
176 result = PyTuple_New(13);
179 PyTuple_SET_ITEM(result, 0, Py_None);
181 PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN));
182 PyTuple_SET_ITEM(result, 1, PyLong_FromLongLong(FSize));
183 PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode));
184 PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime));
185 PyTuple_SET_ITEM(result, 4, PyInt_FromLong(FFlags));
186 PyTuple_SET_ITEM(result, 5, PyInt_FromLong(FRdev));
187 PyTuple_SET_ITEM(result, 6, PyInt_FromLong(FInode));
188 PyTuple_SET_ITEM(result, 7, PyInt_FromLong(FNlink));
189 PyTuple_SET_ITEM(result, 8, PyInt_FromLong(FState));
190 PyTuple_SET_ITEM(result, 9, PyInt_FromLong(VFlags));
193 PyTuple_SET_ITEM(result, 10, Py_None);
195 PyTuple_SET_ITEM(result, 10, Py_BuildValue("s", FUser));
196 if (FGroup == NULL) {
198 PyTuple_SET_ITEM(result, 11, Py_None);
200 PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup));
201 PyTuple_SET_ITEM(result, 12, rpmfi_Digest(s));
209 static struct PyMethodDef rpmfi_methods[] = {
210 {"FC", (PyCFunction)rpmfi_FC, METH_NOARGS,
212 {"FX", (PyCFunction)rpmfi_FX, METH_NOARGS,
214 {"DC", (PyCFunction)rpmfi_DC, METH_NOARGS,
216 {"DX", (PyCFunction)rpmfi_DX, METH_NOARGS,
218 {"BN", (PyCFunction)rpmfi_BN, METH_NOARGS,
220 {"DN", (PyCFunction)rpmfi_DN, METH_NOARGS,
222 {"FN", (PyCFunction)rpmfi_FN, METH_NOARGS,
224 {"FFlags", (PyCFunction)rpmfi_FFlags, METH_NOARGS,
226 {"VFlags", (PyCFunction)rpmfi_VFlags, METH_NOARGS,
228 {"FMode", (PyCFunction)rpmfi_FMode, METH_NOARGS,
230 {"FState", (PyCFunction)rpmfi_FState, METH_NOARGS,
232 {"MD5", (PyCFunction)rpmfi_Digest, METH_NOARGS,
234 {"Digest", (PyCFunction)rpmfi_Digest, METH_NOARGS,
236 {"FLink", (PyCFunction)rpmfi_FLink, METH_NOARGS,
238 {"FSize", (PyCFunction)rpmfi_FSize, METH_NOARGS,
240 {"FRdev", (PyCFunction)rpmfi_FRdev, METH_NOARGS,
242 {"FMtime", (PyCFunction)rpmfi_FMtime, METH_NOARGS,
244 {"FUser", (PyCFunction)rpmfi_FUser, METH_NOARGS,
246 {"FGroup", (PyCFunction)rpmfi_FGroup, METH_NOARGS,
248 {"FColor", (PyCFunction)rpmfi_FColor, METH_NOARGS,
250 {"FClass", (PyCFunction)rpmfi_FClass, METH_NOARGS,
252 {NULL, NULL} /* sentinel */
258 rpmfi_dealloc(rpmfiObject * s)
260 s->fi = rpmfiFree(s->fi);
261 Py_TYPE(s)->tp_free((PyObject *)s);
265 rpmfi_length(rpmfiObject * s)
267 return rpmfiFC(s->fi);
271 rpmfi_subscript(rpmfiObject * s, PyObject * key)
275 if (!PyInt_Check(key)) {
276 PyErr_SetString(PyExc_TypeError, "integer expected");
280 ix = (int) PyInt_AsLong(key);
281 rpmfiSetFX(s->fi, ix);
282 return Py_BuildValue("s", rpmfiFN(s->fi));
285 static PyMappingMethods rpmfi_as_mapping = {
286 (lenfunc) rpmfi_length, /* mp_length */
287 (binaryfunc) rpmfi_subscript, /* mp_subscript */
288 (objobjargproc)0, /* mp_ass_subscript */
291 static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds)
297 static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
299 PyObject * to = NULL;
302 rpmTag tagN = RPMTAG_BASENAMES;
304 char * kwlist[] = {"header", "tag", "flags", NULL};
306 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|Oi:rpmfi_init", kwlist,
307 hdrFromPyObject, &h, &to, &flags))
310 fi = rpmfiNew(NULL, h, tagN, flags);
312 return rpmfi_Wrap(subtype, fi);
315 static char rpmfi_doc[] =
318 PyTypeObject rpmfi_Type = {
319 PyVarObject_HEAD_INIT(&PyType_Type, 0)
320 "rpm.fi", /* tp_name */
321 sizeof(rpmfiObject), /* tp_basicsize */
324 (destructor) rpmfi_dealloc, /* tp_dealloc */
326 (getattrfunc)0, /* tp_getattr */
327 (setattrfunc)0, /* tp_setattr */
328 (cmpfunc)0, /* tp_compare */
329 (reprfunc)0, /* tp_repr */
330 0, /* tp_as_number */
331 0, /* tp_as_sequence */
332 &rpmfi_as_mapping, /* tp_as_mapping */
333 (hashfunc)0, /* tp_hash */
334 (ternaryfunc)0, /* tp_call */
335 (reprfunc)0, /* tp_str */
336 PyObject_GenericGetAttr, /* tp_getattro */
337 PyObject_GenericSetAttr, /* tp_setattro */
338 0, /* tp_as_buffer */
339 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
340 rpmfi_doc, /* tp_doc */
343 0, /* tp_richcompare */
344 0, /* tp_weaklistoffset */
345 PyObject_SelfIter, /* tp_iter */
346 (iternextfunc) rpmfi_iternext, /* tp_iternext */
347 rpmfi_methods, /* tp_methods */
352 0, /* tp_descr_get */
353 0, /* tp_descr_set */
354 0, /* tp_dictoffset */
355 (initproc) rpmfi_init, /* tp_init */
357 (newfunc) rpmfi_new, /* tp_new */
364 rpmfi fiFromFi(rpmfiObject * s)
369 PyObject * rpmfi_Wrap(PyTypeObject *subtype, rpmfi fi)
371 rpmfiObject *s = (rpmfiObject *)subtype->tp_alloc(subtype, 0);
372 if (s == NULL) return NULL;
376 return (PyObject *) s;