From: Panu Matilainen Date: Mon, 5 Oct 2009 11:25:43 +0000 (+0300) Subject: Push ts.check() return tuple-o-doom generation over to python side X-Git-Tag: tznext/4.11.0.1.tizen20130304~2624 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fab2debfe440d677dbd072c3cd73d2c99876e7a5;p=tools%2Flibrpm-tizen.git Push ts.check() return tuple-o-doom generation over to python side --- diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py index 4d0454c..c852b86 100644 --- a/python/rpm/transaction.py +++ b/python/rpm/transaction.py @@ -100,3 +100,41 @@ class TransactionSet(_rpm.ts): res.append(item) return res + def check(self, *args, **kwds): + _rpm.ts.check(self, *args, **kwds) + + probs = self.problems() + if not probs: + return None + + # compatibility: munge problem strings into dependency tuples of doom + res = [] + for p in probs: + # is it anything we need to care about? + if p.type == _rpm.RPMPROB_CONFLICT: + sense = _rpm.RPMDEP_SENSE_CONFLICTS + elif p.type == _rpm.RPMPROB_REQUIRES: + sense = _rpm.RPMDEP_SENSE_REQUIRES + else: + continue + + # strip arch, split to name, version, release + nevr = p.pkgNEVR.rsplit('.', 1)[0] + n, v, r = nevr.rsplit('-', 2) + + # extract the dependency information + needs = p.altNEVR.split()[1:] + needname = needs[0] + needflags = _rpm.RPMSENSE_ANY + if len(needs) == 3: + needop = needs[1] + if needop.find('<') >= 0: needflags |= _rpm.RPMSENSE_LESS + if needop.find('=') >= 0: needflags |= _rpm.RPMSENSE_EQUAL + if needop.find('>') >= 0: needflags |= _rpm.RPMSENSE_GREATER + needver = needs[2] + else: + needver = "" + + res.append(((n, v, r),(needname,needver),needflags,sense,p.key)) + + return res diff --git a/python/rpmts-py.c b/python/rpmts-py.c index f8337f1..5d6bf8f 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -226,11 +226,8 @@ rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data) static PyObject * rpmts_Check(rpmtsObject * s, PyObject * args, PyObject * kwds) { - rpmps ps; - rpmProblem p; - PyObject * list, * cf; struct rpmtsCallbackType_s cbInfo; - int xx; + int rc; char * kwlist[] = {"callback", NULL}; memset(&cbInfo, 0, sizeof(cbInfo)); @@ -243,77 +240,17 @@ rpmts_Check(rpmtsObject * s, PyObject * args, PyObject * kwds) PyErr_SetString(PyExc_TypeError, "expected a callable"); return NULL; } - xx = rpmtsSetSolveCallback(s->ts, rpmts_SolveCallback, (void *)&cbInfo); + rc = rpmtsSetSolveCallback(s->ts, rpmts_SolveCallback, (void *)&cbInfo); } cbInfo.tso = s; cbInfo._save = PyEval_SaveThread(); - xx = rpmtsCheck(s->ts); - ps = rpmtsProblems(s->ts); + rc = rpmtsCheck(s->ts); PyEval_RestoreThread(cbInfo._save); - if (ps != NULL) { - list = PyList_New(0); - rpmpsi psi = rpmpsInitIterator(ps); - - /* XXX TODO: rpmlib >= 4.0.3 can return multiple suggested keys. */ - while (rpmpsNextIterator(psi) >= 0) { - char * altNEVR, * needsName; - char * byName, * byVersion, * byRelease, *byArch; - char * needsOP, * needsVersion; - rpmsenseFlags needsFlags, sense; - fnpyKey key; - - p = rpmpsGetProblem(psi); - - byName = xstrdup(rpmProblemGetPkgNEVR(p)); - if ((byArch= strrchr(byName, '.')) != NULL) - *byArch++ = '\0'; - if ((byRelease = strrchr(byName, '-')) != NULL) - *byRelease++ = '\0'; - if ((byVersion = strrchr(byName, '-')) != NULL) - *byVersion++ = '\0'; - - key = rpmProblemGetKey(p); - - altNEVR = needsName = xstrdup(rpmProblemGetAltNEVR(p)); - if (needsName[1] == ' ') { - sense = (needsName[0] == 'C') - ? RPMDEP_SENSE_CONFLICTS : RPMDEP_SENSE_REQUIRES; - needsName += 2; - } else - sense = RPMDEP_SENSE_REQUIRES; - if ((needsVersion = strrchr(needsName, ' ')) != NULL) - *needsVersion++ = '\0'; - - needsFlags = 0; - if ((needsOP = strrchr(needsName, ' ')) != NULL) { - for (*needsOP++ = '\0'; *needsOP != '\0'; needsOP++) { - if (*needsOP == '<') needsFlags |= RPMSENSE_LESS; - else if (*needsOP == '>') needsFlags |= RPMSENSE_GREATER; - else if (*needsOP == '=') needsFlags |= RPMSENSE_EQUAL; - } - } - - cf = Py_BuildValue("((sss)(ss)iOi)", byName, byVersion, byRelease, - needsName, needsVersion, needsFlags, - (key != NULL ? key : Py_None), - sense); - PyList_Append(list, (PyObject *) cf); - Py_DECREF(cf); - free(byName); - free(altNEVR); - } - - psi = rpmpsFreeIterator(psi); - ps = rpmpsFree(ps); - - return list; - } - - Py_RETURN_NONE; + return PyBool_FromLong((rc == 0)); } static PyObject *