diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-10-02 22:48:03 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-10-02 22:48:03 +0300 |
commit | 9b20c706a4f93266450fae2f94007343b2e8fd9e (patch) | |
tree | cdd0a6b58c4914dfee6514dfd4bc2f757f5edadf /python | |
parent | ab04cfb08c5fbdf4e9803b2d63352fee0527937e (diff) | |
download | librpm-tizen-9b20c706a4f93266450fae2f94007343b2e8fd9e.tar.gz librpm-tizen-9b20c706a4f93266450fae2f94007343b2e8fd9e.tar.bz2 librpm-tizen-9b20c706a4f93266450fae2f94007343b2e8fd9e.zip |
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
Diffstat (limited to 'python')
-rw-r--r-- | python/rpm/transaction.py | 21 | ||||
-rw-r--r-- | python/rpmts-py.c | 33 |
2 files changed, 24 insertions, 30 deletions
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 |