From 9b20c706a4f93266450fae2f94007343b2e8fd9e Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 2 Oct 2009 22:48:03 +0300 Subject: Push most work of ts.addErase() over to python - minimize the stuff done in C: rpmtsAddEraseElement() only cares about header, so that's what we accept on C-level bindings - on python side, handle db recno's and labels like we've always done, additionally accept match iterators and plain headers too --- python/rpm/transaction.py | 21 +++++++++++++++++++++ python/rpmts-py.c | 33 +++------------------------------ 2 files changed, 24 insertions(+), 30 deletions(-) (limited to 'python') diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py index 9c8de0c73..4c4bba75c 100644 --- a/python/rpm/transaction.py +++ b/python/rpm/transaction.py @@ -61,3 +61,24 @@ class TransactionSet(_rpm.ts): if not _rpm.ts.addInstall(self, header, key, upgrade): raise _rpm.error, "adding package to transaction failed" self._keyList.append(key) + + def addErase(self, item): + hdrs = [] + if isinstance(item, _rpm.hdr): + hdrs = [item] + elif isinstance(item, _rpm.mi): + hdrs = item + elif isinstance(item, int): + hdrs = self.dbMatch(_rpm.RPMDBI_PACKAGES, item) + elif isinstance(item, str): + hdrs = self.dbMatch(_rpm.RPMDBI_LABEL, item) + else: + raise TypeError, "invalid type %s" % type(item) + + for h in hdrs: + if not _rpm.ts.addErase(self, h): + raise _rpm.error, "package not installed" + + # garbage collection should take care but just in case... + if isinstance(hdrs, _rpm.mi): + del hdrs diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 39c183cc2..576de02b1 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -183,42 +183,15 @@ rpmts_AddInstall(rpmtsObject * s, PyObject * args) return PyBool_FromLong((rc == 0)); } -/* TODO Permit finer control (i.e. not just --allmatches) of deleted elments.*/ static PyObject * -rpmts_AddErase(rpmtsObject * s, PyObject * args, PyObject * kwds) +rpmts_AddErase(rpmtsObject * s, PyObject * args) { - PyObject * o; - int installed = 0; - rpmdbMatchIterator mi = NULL; Header h; - char * kwlist[] = {"name", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:AddErase", kwlist, &o)) + if (!PyArg_ParseTuple(args, "O&:AddErase", hdrFromPyObject, &h)) return NULL; - if (PyString_Check(o)) { - char * name = PyString_AsString(o); - mi = rpmtsInitIterator(s->ts, RPMDBI_LABEL, name, 0); - } else if (PyInt_Check(o)) { - uint32_t recno = PyInt_AsLong(o); - mi = rpmtsInitIterator(s->ts, RPMDBI_PACKAGES, &recno, sizeof(recno)); - } else { - PyErr_SetString(PyExc_TypeError, "string or integer expected"); - return NULL; - } - - while ((h = rpmdbNextIterator(mi)) != NULL) { - installed++; - rpmtsAddEraseElement(s->ts, h, -1); - } - rpmdbFreeIterator(mi); - - if (installed) { - Py_RETURN_NONE; - } else { - PyErr_SetString(pyrpmError, "package not installed"); - return NULL; - } + return PyBool_FromLong(rpmtsAddEraseElement(s->ts, h, -1) == 0); } static int -- cgit v1.2.3