- Adding support for integer keys in ts.dbMatch().

- Adding readHeaderFromFD().

CVS patchset: 7247
CVS date: 2004/05/04 21:12:04
This commit is contained in:
niemeyer 2004-05-04 21:12:04 +00:00
parent bd7c49f4e0
commit 96063191fc
4 changed files with 67 additions and 3 deletions

View File

@ -975,6 +975,49 @@ PyObject * rpmMergeHeadersFromFD(PyObject * self, PyObject * args)
return Py_None;
}
/**
*/
PyObject * rpmSingleHeaderFromFD(PyObject * self, PyObject * args)
{
FD_t fd;
int fileno;
off_t offset;
PyObject * tuple;
Header h;
if (!PyArg_ParseTuple(args, "i", &fileno)) return NULL;
offset = lseek(fileno, 0, SEEK_CUR);
fd = fdDup(fileno);
if (!fd) {
PyErr_SetFromErrno(pyrpmError);
return NULL;
}
Py_BEGIN_ALLOW_THREADS
h = headerRead(fd, HEADER_MAGIC_YES);
Py_END_ALLOW_THREADS
Fclose(fd);
tuple = PyTuple_New(2);
if (h && tuple) {
PyTuple_SET_ITEM(tuple, 0, (PyObject *) hdr_Wrap(h));
PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
h = headerFree(h);
} else {
Py_INCREF(Py_None);
Py_INCREF(Py_None);
PyTuple_SET_ITEM(tuple, 0, Py_None);
PyTuple_SET_ITEM(tuple, 1, Py_None);
}
return tuple;
}
/**
*/
PyObject * versionCompare (PyObject * self, PyObject * args)

View File

@ -37,6 +37,8 @@ PyObject * rpmHeaderFromFile(PyObject * self, PyObject * args)
/*@*/;
PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args)
/*@*/;
PyObject * rpmSingleHeaderFromFD(PyObject * self, PyObject * args)
/*@*/;
PyObject * rpmReadHeaders (FD_t fd)
/*@*/;
PyObject * rhnLoad(PyObject * self, PyObject * args)

View File

@ -139,6 +139,8 @@ static PyMethodDef rpmModuleMethods[] = {
NULL },
{ "readHeaderListFromFile", (PyCFunction) rpmHeaderFromFile, METH_VARARGS,
NULL },
{ "readHeaderFromFD", (PyCFunction) rpmSingleHeaderFromFD, METH_VARARGS,
NULL },
{ "setLogFile", (PyCFunction) setLogFile, METH_VARARGS,
NULL },
@ -433,8 +435,9 @@ void initrpm(void)
REGISTER_ENUM(TR_ADDED);
REGISTER_ENUM(TR_REMOVED);
PyDict_SetItemString(d, "RPMAL_NOMATCH", o=PyInt_FromLong( (long)RPMAL_NOMATCH ));
Py_DECREF(o);
REGISTER_ENUM(RPMDBI_PACKAGES);
REGISTER_ENUM(RPMAL_NOMATCH);
}
/*@}*/

View File

@ -1300,14 +1300,16 @@ rpmts_Match(rpmtsObject * s, PyObject * args)
/*@modifies s, rpmGlobalMacroContext @*/
{
PyObject *TagN = NULL;
PyObject *Key = NULL;
char *key = NULL;
long lkey = 0;
int len = 0;
int tag = RPMDBI_PACKAGES;
if (_rpmts_debug)
fprintf(stderr, "*** rpmts_Match(%p) ts %p\n", s, s->ts);
if (!PyArg_ParseTuple(args, "|Ozi", &TagN, &key, &len))
if (!PyArg_ParseTuple(args, "|OO", &TagN, &Key))
return NULL;
if (TagN && (tag = tagNumFromPyObject (TagN)) == -1) {
@ -1315,6 +1317,20 @@ fprintf(stderr, "*** rpmts_Match(%p) ts %p\n", s, s->ts);
return NULL;
}
if (Key) {
if (PyString_Check(Key)) {
key = PyString_AsString(Key);
len = PyString_Size(Key);
} else if (PyInt_Check(Key)) {
lkey = PyInt_AsLong(Key);
key = (char *)&lkey;
len = sizeof(lkey);
} else {
PyErr_SetString(PyExc_TypeError, "unknown key type");
return NULL;
}
}
/* XXX If not already opened, open the database O_RDONLY now. */
if (s->ts->rdb == NULL) {
int rc = rpmtsOpenDB(s->ts, O_RDONLY);