Push the interpretation of ts.run() result code to python side
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 5 Oct 2009 09:09:26 +0000 (12:09 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 5 Oct 2009 09:09:26 +0000 (12:09 +0300)
- at least this lets sub-typers override the hysterical return values

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

index 4c4bba7..f7019ec 100644 (file)
@@ -82,3 +82,20 @@ class TransactionSet(_rpm.ts):
         # garbage collection should take care but just in case...
         if isinstance(hdrs, _rpm.mi):
             del hdrs
+
+    def run(self, callback, data):
+        rc = _rpm.ts.run(self, callback, data)
+
+        # crazy backwards compatibility goo: None for ok, list of problems
+        # if transaction didnt complete and empty list if it completed
+        # with errors
+        if rc == 0:
+            return None
+
+        res = []
+        if rc > 0:
+            for prob in self.problems():
+                item = ("%s" % prob, (prob.type, prob._str, prob._num))
+                res.append(item)
+        return res
+
index 576de02..ab83321 100644 (file)
@@ -590,9 +590,6 @@ static PyObject *
 rpmts_Run(rpmtsObject * s, PyObject * args, PyObject * kwds)
 {
     int rc;
-    PyObject * list;
-    rpmps ps;
-    rpmpsi psi;
     struct rpmtsCallbackType_s cbInfo;
     char * kwlist[] = {"callback", "data", NULL};
 
@@ -612,38 +609,13 @@ rpmts_Run(rpmtsObject * s, PyObject * args, PyObject * kwds)
     }
 
     rc = rpmtsRun(s->ts, NULL, s->ignoreSet);
-    ps = rpmtsProblems(s->ts);
 
     if (cbInfo.cb)
        (void) rpmtsSetNotifyCallback(s->ts, NULL, NULL);
 
     PyEval_RestoreThread(cbInfo._save);
 
-    if (rc < 0) {
-       list = PyList_New(0);
-       return list;
-    } else if (!rc) {
-       Py_RETURN_NONE;
-    }
-
-    list = PyList_New(0);
-    psi = rpmpsInitIterator(ps);
-    while (rpmpsNextIterator(psi) >= 0) {
-       rpmProblem p = rpmpsGetProblem(psi);
-       char * ps = rpmProblemString(p);
-       PyObject * prob = Py_BuildValue("s(isN)", ps,
-                            rpmProblemGetType(p),
-                            rpmProblemGetStr(p),
-                            PyLong_FromLongLong(rpmProblemGetDiskNeed(p)));
-       PyList_Append(list, prob);
-       free(ps);
-       Py_DECREF(prob);
-    }
-
-    psi = rpmpsFreeIterator(psi);
-    ps = rpmpsFree(ps);
-
-    return list;
+    return Py_BuildValue("i", rc);
 }
 
 static PyObject *