Push the rpmtsGetKeys() stuff over to python completely
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 2 Oct 2009 17:35:20 +0000 (20:35 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 2 Oct 2009 17:35:20 +0000 (20:35 +0300)
- trivially implemented in python by iterating over transaction element
  keys, we dont need no stinking extra librpm APIs for this

lib/rpmts.c
lib/rpmts.h
python/rpm/transaction.py
python/rpmts-py.c

index 3125535..38fedc8 100644 (file)
@@ -1046,34 +1046,6 @@ int rpmtsSetNotifyCallback(rpmts ts,
     return 0;
 }
 
-int rpmtsGetKeys(const rpmts ts, fnpyKey ** ep, int * nep)
-{
-    int rc = 0;
-
-    if (nep) *nep = ts->orderCount;
-    if (ep) {
-       rpmtsi pi;      rpmte p;
-       fnpyKey * e;
-
-       *ep = e = xmalloc(ts->orderCount * sizeof(*e));
-       pi = rpmtsiInit(ts);
-       while ((p = rpmtsiNext(pi, 0)) != NULL) {
-           switch (rpmteType(p)) {
-           case TR_ADDED:
-               *e = rpmteKey(p);
-               break;
-           case TR_REMOVED:
-           default:
-               *e = NULL;
-               break;
-           }
-           e++;
-       }
-       pi = rpmtsiFree(pi);
-    }
-    return rc;
-}
-
 rpmts rpmtsCreate(void)
 {
     rpmts ts;
index 1bf9e62..70e90b9 100644 (file)
@@ -633,18 +633,6 @@ int rpmtsAddInstallElement(rpmts ts, Header h,
  */
 int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset);
 
-/** \ingroup rpmts
- * Retrieve keys from ordered transaction set.
- * @todo Removed packages have no keys, returned as interleaved NULL pointers.
- * @param ts           transaction set
- * @retval ep          address of returned element array pointer (or NULL)
- * @retval nep         address of no. of returned elements (or NULL)
- * @return             0 always
- */
-int rpmtsGetKeys(rpmts ts,
-               fnpyKey ** ep,
-               int * nep);
-
 #ifdef __cplusplus
 }
 #endif
index 7437413..4e8711e 100644 (file)
@@ -30,3 +30,13 @@ class TransactionSet(_rpm.ts):
     def parseSpec(self, specfile):
         import _rpmb
         return _rpmb.spec(specfile)
+
+    def getKeys(self):
+        keys = []
+        for te in self:
+            keys.append(te.Key())
+        # Backwards compatibility goo - WTH does this return a *tuple* ?!
+        if not keys:
+            return None
+        else:
+            return tuple(keys)
index 8a5904b..7566fe4 100644 (file)
@@ -567,33 +567,6 @@ rpmts_PgpImportPubkey(rpmtsObject * s, PyObject * args, PyObject * kwds)
     return Py_BuildValue("i", rc);
 }
 
-static PyObject *
-rpmts_GetKeys(rpmtsObject * s)
-{
-    const void **data = NULL;
-    int num, i;
-    PyObject *tuple;
-
-    rpmtsGetKeys(s->ts, &data, &num);
-    if (data == NULL || num <= 0) {
-       data = _free(data);
-       Py_RETURN_NONE;
-    }
-
-    tuple = PyTuple_New(num);
-
-    for (i = 0; i < num; i++) {
-       PyObject *obj;
-       obj = (data[i] ? (PyObject *) data[i] : Py_None);
-       Py_INCREF(obj);
-       PyTuple_SetItem(tuple, i, obj);
-    }
-
-    data = _free(data);
-
-    return tuple;
-}
-
 static void *
 rpmtsCallback(const void * hd, const rpmCallbackType what,
                         const rpm_loff_t amount, const rpm_loff_t total,
@@ -833,8 +806,6 @@ static struct PyMethodDef rpmts_methods[] = {
        NULL },
  {"pgpImportPubkey",   (PyCFunction) rpmts_PgpImportPubkey,    METH_VARARGS|METH_KEYWORDS,
        NULL },
- {"getKeys",   (PyCFunction) rpmts_GetKeys,    METH_NOARGS,
-       NULL },
  {"dbMatch",   (PyCFunction) rpmts_Match,      METH_VARARGS|METH_KEYWORDS,
 "ts.dbMatch([TagN, [key, [len]]]) -> mi\n\
 - Create a match iterator for the default transaction rpmdb.\n" },