2003-11-24 03:50:52 +08:00
|
|
|
/** \ingroup py_c
|
2002-05-24 01:29:21 +08:00
|
|
|
* \file python/rpmfi-py.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
|
2007-11-23 13:46:19 +08:00
|
|
|
#include <rpmlib.h>
|
2002-05-24 01:29:21 +08:00
|
|
|
|
|
|
|
#include "header-py.h"
|
|
|
|
#include "rpmfi-py.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2002-07-15 05:23:29 +08:00
|
|
|
|
2002-05-24 01:29:21 +08:00
|
|
|
static PyObject *
|
2007-09-11 21:28:26 +08:00
|
|
|
rpmfi_Debug(rpmfiObject * s, PyObject * args, PyObject * kwds)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2004-11-18 01:05:39 +08:00
|
|
|
char * kwlist[] = {"debugLevel", NULL};
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmfi_debug))
|
|
|
|
return NULL;
|
|
|
|
|
2002-05-24 01:29:21 +08:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FC(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFC(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FX(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFX(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_DC(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiDC(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_DX(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiDX(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_BN(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiBN(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_DN(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiDN(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FN(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiFN(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FFlags(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFFlags(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_VFlags(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiVFlags(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FMode(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFMode(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FState(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFState(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX rpmfiMD5 */
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_MD5(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2002-12-11 08:12:17 +08:00
|
|
|
const unsigned char * MD5;
|
2002-05-24 01:29:21 +08:00
|
|
|
char fmd5[33];
|
|
|
|
char * t;
|
|
|
|
int i;
|
2003-11-24 03:50:52 +08:00
|
|
|
|
2002-12-11 08:12:17 +08:00
|
|
|
MD5 = rpmfiMD5(s->fi);
|
2004-10-10 05:58:33 +08:00
|
|
|
t = fmd5;
|
2003-12-02 03:15:38 +08:00
|
|
|
if (MD5 != NULL)
|
2004-10-10 05:58:33 +08:00
|
|
|
for (i = 0; i < 16; i++, t += 2)
|
2002-12-11 08:12:17 +08:00
|
|
|
sprintf(t, "%02x", MD5[i]);
|
2002-05-24 01:29:21 +08:00
|
|
|
*t = '\0';
|
|
|
|
return Py_BuildValue("s", xstrdup(fmd5));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FLink(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiFLink(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FSize(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFSize(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FRdev(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFRdev(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FMtime(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFMtime(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FUser(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiFUser(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FGroup(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiFGroup(s->fi)));
|
|
|
|
}
|
|
|
|
|
2002-12-30 08:03:53 +08:00
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FColor(rpmfiObject * s)
|
2002-12-30 08:03:53 +08:00
|
|
|
{
|
|
|
|
return Py_BuildValue("i", rpmfiFColor(s->fi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_FClass(rpmfiObject * s)
|
2002-12-30 08:03:53 +08:00
|
|
|
{
|
|
|
|
const char * FClass;
|
|
|
|
|
|
|
|
if ((FClass = rpmfiFClass(s->fi)) == NULL)
|
|
|
|
FClass = "";
|
|
|
|
return Py_BuildValue("s", xstrdup(FClass));
|
|
|
|
}
|
|
|
|
|
2002-05-24 01:29:21 +08:00
|
|
|
#if Py_TPFLAGS_HAVE_ITER
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_iter(rpmfiObject * s)
|
2002-07-20 04:26:38 +08:00
|
|
|
{
|
|
|
|
Py_INCREF(s);
|
|
|
|
return (PyObject *)s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rpmfi_iternext(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
PyObject * result = NULL;
|
|
|
|
|
2002-07-20 04:26:38 +08:00
|
|
|
/* Reset loop indices on 1st entry. */
|
|
|
|
if (!s->active) {
|
2003-05-03 05:05:46 +08:00
|
|
|
s->fi = rpmfiInit(s->fi, 0);
|
2002-07-20 04:26:38 +08:00
|
|
|
s->active = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If more to do, return the file tuple. */
|
2002-05-24 01:29:21 +08:00
|
|
|
if (rpmfiNext(s->fi) >= 0) {
|
|
|
|
const char * FN = rpmfiFN(s->fi);
|
|
|
|
int FSize = rpmfiFSize(s->fi);
|
|
|
|
int FMode = rpmfiFMode(s->fi);
|
|
|
|
int FMtime = rpmfiFMtime(s->fi);
|
|
|
|
int FFlags = rpmfiFFlags(s->fi);
|
2002-07-20 04:26:38 +08:00
|
|
|
int FRdev = rpmfiFRdev(s->fi);
|
|
|
|
int FInode = rpmfiFInode(s->fi);
|
|
|
|
int FNlink = rpmfiFNlink(s->fi);
|
|
|
|
int FState = rpmfiFState(s->fi);
|
|
|
|
int VFlags = rpmfiVFlags(s->fi);
|
|
|
|
const char * FUser = rpmfiFUser(s->fi);
|
|
|
|
const char * FGroup = rpmfiFGroup(s->fi);
|
2002-12-11 08:12:17 +08:00
|
|
|
const unsigned char * MD5 = rpmfiMD5(s->fi), *s = MD5;
|
2002-07-20 04:26:38 +08:00
|
|
|
char FMD5[2*16+1], *t = FMD5;
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
2002-12-11 08:12:17 +08:00
|
|
|
int gotMD5, i;
|
2002-07-20 04:26:38 +08:00
|
|
|
|
2002-12-11 08:12:17 +08:00
|
|
|
gotMD5 = 0;
|
2002-07-20 04:26:38 +08:00
|
|
|
if (s)
|
|
|
|
for (i = 0; i < 16; i++) {
|
2002-12-11 08:12:17 +08:00
|
|
|
gotMD5 |= *s;
|
2002-07-20 04:26:38 +08:00
|
|
|
*t++ = hex[ (*s >> 4) & 0xf ];
|
|
|
|
*t++ = hex[ (*s++ ) & 0xf ];
|
|
|
|
}
|
|
|
|
*t = '\0';
|
|
|
|
|
|
|
|
result = PyTuple_New(13);
|
|
|
|
if (FN == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
PyTuple_SET_ITEM(result, 0, Py_None);
|
|
|
|
} else
|
|
|
|
PyTuple_SET_ITEM(result, 0, Py_BuildValue("s", FN));
|
|
|
|
PyTuple_SET_ITEM(result, 1, PyInt_FromLong(FSize));
|
|
|
|
PyTuple_SET_ITEM(result, 2, PyInt_FromLong(FMode));
|
|
|
|
PyTuple_SET_ITEM(result, 3, PyInt_FromLong(FMtime));
|
|
|
|
PyTuple_SET_ITEM(result, 4, PyInt_FromLong(FFlags));
|
|
|
|
PyTuple_SET_ITEM(result, 5, PyInt_FromLong(FRdev));
|
|
|
|
PyTuple_SET_ITEM(result, 6, PyInt_FromLong(FInode));
|
|
|
|
PyTuple_SET_ITEM(result, 7, PyInt_FromLong(FNlink));
|
|
|
|
PyTuple_SET_ITEM(result, 8, PyInt_FromLong(FState));
|
|
|
|
PyTuple_SET_ITEM(result, 9, PyInt_FromLong(VFlags));
|
|
|
|
if (FUser == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
PyTuple_SET_ITEM(result, 10, Py_None);
|
|
|
|
} else
|
|
|
|
PyTuple_SET_ITEM(result, 10, Py_BuildValue("s", FUser));
|
|
|
|
if (FGroup == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
PyTuple_SET_ITEM(result, 11, Py_None);
|
|
|
|
} else
|
|
|
|
PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup));
|
2002-12-11 08:12:17 +08:00
|
|
|
if (!gotMD5) {
|
2002-07-20 04:26:38 +08:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
PyTuple_SET_ITEM(result, 12, Py_None);
|
|
|
|
} else
|
|
|
|
PyTuple_SET_ITEM(result, 12, Py_BuildValue("s", FMD5));
|
|
|
|
|
|
|
|
} else
|
|
|
|
s->active = 0;
|
2002-05-24 01:29:21 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_Next(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2002-07-20 04:26:38 +08:00
|
|
|
PyObject * result = NULL;
|
|
|
|
|
|
|
|
result = rpmfi_iternext(s);
|
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2002-05-24 01:29:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOTYET
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_NextD(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
rpmfi_InitD(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct PyMethodDef rpmfi_methods[] = {
|
2004-11-18 01:05:39 +08:00
|
|
|
{"Debug", (PyCFunction)rpmfi_Debug, METH_VARARGS|METH_KEYWORDS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FC", (PyCFunction)rpmfi_FC, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FX", (PyCFunction)rpmfi_FX, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"DC", (PyCFunction)rpmfi_DC, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"DX", (PyCFunction)rpmfi_DX, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"BN", (PyCFunction)rpmfi_BN, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"DN", (PyCFunction)rpmfi_DN, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FN", (PyCFunction)rpmfi_FN, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FFlags", (PyCFunction)rpmfi_FFlags, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"VFlags", (PyCFunction)rpmfi_VFlags, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FMode", (PyCFunction)rpmfi_FMode, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FState", (PyCFunction)rpmfi_FState, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"MD5", (PyCFunction)rpmfi_MD5, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FLink", (PyCFunction)rpmfi_FLink, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FSize", (PyCFunction)rpmfi_FSize, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FRdev", (PyCFunction)rpmfi_FRdev, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FMtime", (PyCFunction)rpmfi_FMtime, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FUser", (PyCFunction)rpmfi_FUser, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FGroup", (PyCFunction)rpmfi_FGroup, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FColor", (PyCFunction)rpmfi_FColor, METH_NOARGS,
|
2002-12-30 08:03:53 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"FClass", (PyCFunction)rpmfi_FClass, METH_NOARGS,
|
2002-12-30 08:03:53 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"next", (PyCFunction)rpmfi_Next, METH_NOARGS,
|
2002-07-20 04:26:38 +08:00
|
|
|
"fi.next() -> (FN, FSize, FMode, FMtime, FFlags, FRdev, FInode, FNlink, FState, VFlags, FUser, FGroup, FMD5))\n\
|
|
|
|
- Retrieve next file info tuple.\n" },
|
2002-05-24 01:29:21 +08:00
|
|
|
#ifdef NOTYET
|
2004-11-18 01:05:39 +08:00
|
|
|
{"NextD", (PyCFunction)rpmfi_NextD, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2004-11-18 01:05:39 +08:00
|
|
|
{"InitD", (PyCFunction)rpmfi_InitD, METH_NOARGS,
|
2002-05-28 02:12:12 +08:00
|
|
|
NULL},
|
2002-05-24 01:29:21 +08:00
|
|
|
#endif
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ---------- */
|
|
|
|
|
|
|
|
static void
|
2007-09-11 21:28:26 +08:00
|
|
|
rpmfi_dealloc(rpmfiObject * s)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
if (s) {
|
2002-08-20 06:27:44 +08:00
|
|
|
s->fi = rpmfiFree(s->fi);
|
2002-12-11 03:46:03 +08:00
|
|
|
PyObject_Del(s);
|
2002-05-24 01:29:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-09-11 21:28:26 +08:00
|
|
|
rpmfi_print(rpmfiObject * s, FILE * fp, int flags)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
|
|
|
if (!(s && s->fi))
|
|
|
|
return -1;
|
|
|
|
|
2003-05-03 05:05:46 +08:00
|
|
|
s->fi = rpmfiInit(s->fi, 0);
|
2002-05-24 01:29:21 +08:00
|
|
|
while (rpmfiNext(s->fi) >= 0)
|
|
|
|
fprintf(fp, "%s\n", rpmfiFN(s->fi));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-05 01:34:53 +08:00
|
|
|
static PyObject * rpmfi_getattro(PyObject * o, PyObject * n)
|
|
|
|
{
|
|
|
|
return PyObject_GenericGetAttr(o, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmfi_setattro(PyObject * o, PyObject * n, PyObject * v)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2003-05-05 01:34:53 +08:00
|
|
|
return PyObject_GenericSetAttr(o, n, v);
|
2002-05-24 01:29:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rpmfi_length(rpmfiObject * s)
|
|
|
|
{
|
|
|
|
return rpmfiFC(s->fi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rpmfi_subscript(rpmfiObject * s, PyObject * key)
|
|
|
|
{
|
|
|
|
int ix;
|
|
|
|
|
|
|
|
if (!PyInt_Check(key)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "integer expected");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ix = (int) PyInt_AsLong(key);
|
|
|
|
rpmfiSetFX(s->fi, ix);
|
|
|
|
return Py_BuildValue("s", xstrdup(rpmfiFN(s->fi)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMappingMethods rpmfi_as_mapping = {
|
2007-07-10 20:25:32 +08:00
|
|
|
(lenfunc) rpmfi_length, /* mp_length */
|
2002-05-24 01:29:21 +08:00
|
|
|
(binaryfunc) rpmfi_subscript, /* mp_subscript */
|
|
|
|
(objobjargproc)0, /* mp_ass_subscript */
|
|
|
|
};
|
|
|
|
|
2004-10-13 23:28:19 +08:00
|
|
|
/** \ingroup py_c
|
|
|
|
*/
|
|
|
|
static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
|
|
|
hdrObject * ho = NULL;
|
|
|
|
PyObject * to = NULL;
|
|
|
|
rpmts ts = NULL; /* XXX FIXME: fiFromHeader should be a ts method. */
|
|
|
|
int tagN = RPMTAG_BASENAMES;
|
|
|
|
int flags = 0;
|
2004-11-18 01:05:39 +08:00
|
|
|
char * kwlist[] = {"header", "tag", "flags", NULL};
|
2004-10-13 23:28:19 +08:00
|
|
|
|
|
|
|
if (_rpmfi_debug < 0)
|
|
|
|
fprintf(stderr, "*** rpmfi_init(%p,%p,%p)\n", s, args, kwds);
|
|
|
|
|
2004-11-18 01:05:39 +08:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmfi_init", kwlist,
|
|
|
|
&hdr_Type, &ho, &to, &flags))
|
2004-10-13 23:28:19 +08:00
|
|
|
return -1;
|
2004-11-18 01:05:39 +08:00
|
|
|
|
2004-10-13 23:28:19 +08:00
|
|
|
if (to != NULL) {
|
|
|
|
tagN = tagNumFromPyObject(to);
|
|
|
|
if (tagN == -1) {
|
|
|
|
PyErr_SetString(PyExc_KeyError, "unknown header tag");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->fi = rpmfiNew(ts, hdrGetHeader(ho), tagN, flags);
|
|
|
|
s->active = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup py_c
|
|
|
|
*/
|
2007-09-11 21:28:26 +08:00
|
|
|
static void rpmfi_free(rpmfiObject * s)
|
2004-10-13 23:28:19 +08:00
|
|
|
{
|
|
|
|
if (_rpmfi_debug)
|
|
|
|
fprintf(stderr, "%p -- fi %p\n", s, s->fi);
|
|
|
|
s->fi = rpmfiFree(s->fi);
|
|
|
|
|
|
|
|
PyObject_Del((PyObject *)s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup py_c
|
|
|
|
*/
|
|
|
|
static PyObject * rpmfi_alloc(PyTypeObject * subtype, int nitems)
|
|
|
|
{
|
|
|
|
PyObject * s = PyType_GenericAlloc(subtype, nitems);
|
|
|
|
|
|
|
|
if (_rpmfi_debug < 0)
|
|
|
|
fprintf(stderr, "*** rpmfi_alloc(%p,%d) ret %p\n", subtype, nitems, s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup py_c
|
|
|
|
*/
|
|
|
|
static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
|
|
|
rpmfiObject * s = (void *) PyObject_New(rpmfiObject, subtype);
|
|
|
|
|
|
|
|
/* Perform additional initialization. */
|
|
|
|
if (rpmfi_init(s, args, kwds) < 0) {
|
|
|
|
rpmfi_free(s);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_rpmfi_debug)
|
|
|
|
fprintf(stderr, "%p ++ fi %p\n", s, s->fi);
|
|
|
|
|
|
|
|
return (PyObject *)s;
|
|
|
|
}
|
|
|
|
|
2002-05-28 02:12:12 +08:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static char rpmfi_doc[] =
|
|
|
|
"";
|
|
|
|
|
2002-05-24 01:29:21 +08:00
|
|
|
PyTypeObject rpmfi_Type = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
|
|
0, /* ob_size */
|
2002-05-28 02:12:12 +08:00
|
|
|
"rpm.fi", /* tp_name */
|
2002-05-24 01:29:21 +08:00
|
|
|
sizeof(rpmfiObject), /* tp_basicsize */
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
/* methods */
|
2002-12-11 08:12:17 +08:00
|
|
|
(destructor) rpmfi_dealloc, /* tp_dealloc */
|
|
|
|
(printfunc) rpmfi_print, /* tp_print */
|
2003-05-05 01:34:53 +08:00
|
|
|
(getattrfunc)0, /* tp_getattr */
|
2002-05-24 01:29:21 +08:00
|
|
|
(setattrfunc)0, /* tp_setattr */
|
|
|
|
(cmpfunc)0, /* tp_compare */
|
|
|
|
(reprfunc)0, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
&rpmfi_as_mapping, /* tp_as_mapping */
|
|
|
|
(hashfunc)0, /* tp_hash */
|
|
|
|
(ternaryfunc)0, /* tp_call */
|
|
|
|
(reprfunc)0, /* tp_str */
|
2003-05-05 01:34:53 +08:00
|
|
|
(getattrofunc) rpmfi_getattro, /* tp_getattro */
|
|
|
|
(setattrofunc) rpmfi_setattro, /* tp_setattro */
|
2002-05-24 01:29:21 +08:00
|
|
|
0, /* tp_as_buffer */
|
|
|
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
2002-05-28 02:12:12 +08:00
|
|
|
rpmfi_doc, /* tp_doc */
|
2002-05-24 01:29:21 +08:00
|
|
|
#if Py_TPFLAGS_HAVE_ITER
|
|
|
|
0, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
0, /* tp_richcompare */
|
|
|
|
0, /* tp_weaklistoffset */
|
2002-12-11 08:12:17 +08:00
|
|
|
(getiterfunc) rpmfi_iter, /* tp_iter */
|
|
|
|
(iternextfunc) rpmfi_iternext, /* tp_iternext */
|
2002-05-28 02:12:12 +08:00
|
|
|
rpmfi_methods, /* tp_methods */
|
2002-05-24 01:29:21 +08:00
|
|
|
0, /* tp_members */
|
|
|
|
0, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
2004-10-13 23:28:19 +08:00
|
|
|
(initproc) rpmfi_init, /* tp_init */
|
|
|
|
(allocfunc) rpmfi_alloc, /* tp_alloc */
|
|
|
|
(newfunc) rpmfi_new, /* tp_new */
|
2007-07-10 20:19:04 +08:00
|
|
|
(freefunc) rpmfi_free, /* tp_free */
|
2002-05-24 01:29:21 +08:00
|
|
|
0, /* tp_is_gc */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ---------- */
|
|
|
|
|
|
|
|
rpmfi fiFromFi(rpmfiObject * s)
|
|
|
|
{
|
|
|
|
return s->fi;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmfiObject *
|
2002-05-24 05:06:42 +08:00
|
|
|
rpmfi_Wrap(rpmfi fi)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2002-12-11 03:46:03 +08:00
|
|
|
rpmfiObject *s = PyObject_New(rpmfiObject, &rpmfi_Type);
|
2002-07-20 04:26:38 +08:00
|
|
|
|
2002-05-24 01:29:21 +08:00
|
|
|
if (s == NULL)
|
|
|
|
return NULL;
|
|
|
|
s->fi = fi;
|
2002-07-20 04:26:38 +08:00
|
|
|
s->active = 0;
|
2002-05-24 01:29:21 +08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmfiObject *
|
2004-11-18 01:05:39 +08:00
|
|
|
hdr_fiFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
|
2002-05-24 01:29:21 +08:00
|
|
|
{
|
2002-07-20 04:26:38 +08:00
|
|
|
hdrObject * ho = (hdrObject *)s;
|
|
|
|
PyObject * to = NULL;
|
2002-08-20 06:27:44 +08:00
|
|
|
rpmts ts = NULL; /* XXX FIXME: fiFromHeader should be a ts method. */
|
2002-07-20 04:26:38 +08:00
|
|
|
rpmTag tagN = RPMTAG_BASENAMES;
|
2004-10-13 23:28:19 +08:00
|
|
|
int flags = 0;
|
2004-11-18 01:05:39 +08:00
|
|
|
char * kwlist[] = {"tag", "flags", NULL};
|
2002-05-24 01:29:21 +08:00
|
|
|
|
2004-11-18 01:05:39 +08:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:fiFromHeader", kwlist,
|
|
|
|
&to, &flags))
|
2002-05-24 01:29:21 +08:00
|
|
|
return NULL;
|
2004-11-18 01:05:39 +08:00
|
|
|
|
2002-07-20 04:26:38 +08:00
|
|
|
if (to != NULL) {
|
|
|
|
tagN = tagNumFromPyObject(to);
|
|
|
|
if (tagN == -1) {
|
|
|
|
PyErr_SetString(PyExc_KeyError, "unknown header tag");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-10-13 23:28:19 +08:00
|
|
|
return rpmfi_Wrap( rpmfiNew(ts, hdrGetHeader(ho), tagN, flags) );
|
2002-05-24 01:29:21 +08:00
|
|
|
}
|