From: Panu Matilainen Date: Mon, 5 Oct 2009 12:19:01 +0000 (+0300) Subject: Push hdrFromFdno() error code handling over to python side X-Git-Tag: rpm-4.8.0-beta1~137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=564f1cb02b841f0b0b1c2b7fcafbb9a080233a46;p=platform%2Fupstream%2Frpm.git Push hdrFromFdno() error code handling over to python side - return (rpmrc, header) tuple from C to let python do whatever it wishes with the information - let python side worry about generating backwards compatible returns --- diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py index 07a8db0..b352494 100644 --- a/python/rpm/transaction.py +++ b/python/rpm/transaction.py @@ -148,3 +148,15 @@ class TransactionSet(_rpm.ts): raise _rpm.error, "public key not trusted" elif res != _rpm.RPMRC_OK: raise _rpm.error, msg + + def hdrFromFdno(self, fd): + res, h = _rpm.ts.hdrFromFdno(self, fd) + # generate backwards compatibly broken exceptions + if res == _rpm.RPMRC_NOKEY: + raise _rpm.error, "public key not availaiable" + elif res == _rpm.RPMRC_NOTTRUSTED: + raise _rpm.error, "public key not trusted" + elif res != _rpm.RPMRC_OK: + raise _rpm.error, "error reading package header" + + return h diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 208de9a..05c8303 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -333,44 +333,26 @@ rpmts_VerifyDB(rpmtsObject * s) } static PyObject * -rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds) +rpmts_HdrFromFdno(rpmtsObject * s, PyObject *arg) { - PyObject * result = NULL; + PyObject *ho = NULL; Header h; FD_t fd; rpmRC rpmrc; - char * kwlist[] = {"fd", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:HdrFromFdno", kwlist, - rpmFdFromPyObject, &fd)) + if (!PyArg_Parse(arg, "O&:HdrFromFdno", rpmFdFromPyObject, &fd)) return NULL; rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h); Fclose(fd); - switch (rpmrc) { - case RPMRC_OK: - if (h) - result = Py_BuildValue("N", hdr_Wrap(&hdr_Type, h)); - h = headerFree(h); /* XXX ref held by result */ - break; - - case RPMRC_NOKEY: - PyErr_SetString(pyrpmError, "public key not available"); - break; - - case RPMRC_NOTTRUSTED: - PyErr_SetString(pyrpmError, "public key not trusted"); - break; - - case RPMRC_NOTFOUND: - case RPMRC_FAIL: - default: - PyErr_SetString(pyrpmError, "error reading package header"); - break; + if (rpmrc == RPMRC_OK) { + ho = hdr_Wrap(&hdr_Type, h); + } else { + Py_INCREF(Py_None); + ho = Py_None; } - - return result; + return Py_BuildValue("(iN)", rpmrc, ho); } static PyObject * @@ -639,7 +621,7 @@ static struct PyMethodDef rpmts_methods[] = { {"verifyDB", (PyCFunction) rpmts_VerifyDB, METH_NOARGS, "ts.verifyDB() -> None\n\ - Verify the default transaction rpmdb.\n" }, - {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS|METH_KEYWORDS, + {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_O, "ts.hdrFromFdno(fdno) -> hdr\n\ - Read a package header from a file descriptor.\n" }, {"hdrCheck", (PyCFunction) rpmts_HdrCheck, METH_O,