From 834db501abf63981c5445edac45af8de278b0777 Mon Sep 17 00:00:00 2001 From: jbj Date: Tue, 7 Sep 1999 22:48:55 +0000 Subject: Update from anaconda. CVS patchset: 3267 CVS date: 1999/09/07 22:48:55 --- python/rpmmodule.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ python/testit | 33 +++++++++++++-------------------- 2 files changed, 67 insertions(+), 20 deletions(-) (limited to 'python') diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 8cf30b6a5..6138a4ae4 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -9,6 +9,9 @@ #include "rpmlib.h" #include "upgrade.h" +/* from lib/misc.c */ +int rpmvercmp(const char * one, const char * two); + /* Forward types */ typedef struct rpmdbObject_s rpmdbObject; @@ -44,6 +47,9 @@ static PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args); static PyObject * findUpgradeSet(PyObject * self, PyObject * args); static PyObject * errorSetCallback (PyObject * self, PyObject * args); static PyObject * errorString (PyObject * self, PyObject * args); +static PyObject * versionCompare (PyObject * self, PyObject * args); +static PyObject * labelCompare (PyObject * self, PyObject * args); +static PyObject * rebuildDB (PyObject * self, PyObject * args); static PyObject * rpmtransCreate(PyObject * self, PyObject * args); static PyObject * rpmtransAdd(rpmtransObject * s, PyObject * args); @@ -64,10 +70,13 @@ static PyMethodDef rpmModuleMethods[] = { { "headerFromPackage", (PyCFunction) rpmHeaderFromPackage, METH_VARARGS, NULL }, { "headerLoad", (PyCFunction) hdrLoad, METH_VARARGS, NULL }, { "opendb", (PyCFunction) rpmOpenDB, METH_VARARGS, NULL }, + { "rebuilddb", (PyCFunction) rebuildDB, METH_VARARGS, NULL }, { "readHeaderListFromFD", (PyCFunction) rpmHeaderFromFD, METH_VARARGS, NULL }, { "readHeaderListFromFile", (PyCFunction) rpmHeaderFromFile, METH_VARARGS, NULL }, { "errorSetCallback", (PyCFunction) errorSetCallback, METH_VARARGS, NULL }, { "errorString", (PyCFunction) errorString, METH_VARARGS, NULL }, + { "versionCompare", (PyCFunction) versionCompare, METH_VARARGS, NULL }, + { "labelCompare", (PyCFunction) labelCompare, METH_VARARGS, NULL }, { NULL } } ; @@ -424,6 +433,14 @@ static rpmdbObject * rpmOpenDB(PyObject * self, PyObject * args) { return o; } +static PyObject * rebuildDB (PyObject * self, PyObject * args) { + char * root = ""; + + if (!PyArg_ParseTuple(args, "s", &root)) return NULL; + + return Py_BuildValue("i", rpmdbRebuild(root)); +} + static PyObject * rpmReadHeaders (FD_t fd) { PyObject * list; Header header; @@ -567,6 +584,43 @@ static PyObject * errorString (PyObject * self, PyObject * args) { return PyString_FromString(rpmErrorString ()); } +static PyObject * versionCompare (PyObject * self, PyObject * args) { + hdrObject * h1, * h2; + + if (!PyArg_ParseTuple(args, "O!O!", &hdrType, &h1, &hdrType, &h2)) return NULL; + + return Py_BuildValue("i", rpmVersionCompare(h1->h, h2->h)); +} + +static PyObject * labelCompare (PyObject * self, PyObject * args) { + char *v1, *r1, *e1, *v2, *r2, *e2; + int rc; + + if (!PyArg_ParseTuple(args, "(zzz)(zzz)", + &e1, &v1, &r1, + &e2, &v2, &r2)) return NULL; + + if (e1 && !e2) + return Py_BuildValue("i", 1); + else if (!e1 && e2) + return Py_BuildValue("i", -1); + else if (e1 && e2) { + int ep1, ep2; + ep1 = atoi (e1); + ep2 = atoi (e2); + if (ep1 < ep2) + return Py_BuildValue("i", -1); + else if (ep1 > ep2) + return Py_BuildValue("i", 1); + } + + rc = rpmvercmp(v1, v2); + if (rc) + return Py_BuildValue("i", rc); + + return Py_BuildValue("i", rpmvercmp(r1, r2)); +} + static PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args) { hdrObject * h; Header header; diff --git a/python/testit b/python/testit index d2f2d4b3f..fc5e78792 100755 --- a/python/testit +++ b/python/testit @@ -3,27 +3,20 @@ import rpm import os -def cb(what, amount, total, key, data): - if (what == rpm.RPMCALLBACK_INST_OPEN_FILE): - d = os.open(key, os.O_RDONLY) - return d +## fd = os.open('/mnt/redhat/comps/dist/6.0/i386/util-linux-2.9o-13.i386.rpm', 0) +## (hdr1, foo) = rpm.headerFromPackage (fd) +## os.close (fd) +## fd = os.open ('/mnt/redhat/comps/dist/6.1/i386/util-linux-2.9v-20.i386.rpm', 0) +## (hdr2, foo) = rpm.headerFromPackage (fd) +## os.close (fd) -fd = os.open('foo', os.O_RDONLY); -(h, isSource) = rpm.headerFromPackage(fd) -print "from foo:", h[rpm.RPMTAG_NAME] -os.close(fd) +## print rpm.versionCompare (hdr1, hdr1) -#list = rpm.readHeaderList('hdlist') -#print "got", len(list), "items" +## print rpm.labelCompare ((None, "2.9j", "14"), (None, "2.9j", "15")) -d = rpm.opendb(0) - -ts = rpm.TransactionSet("/", d) - -ts.add(h, "foo") -rc = ts.depcheck() -print rc - -ts.order() -print "run", ts.run(rpm.RPMTRANS_FLAG_TEST, 0, cb, "arg") +db = rpm.opendb () +rc = db.findpackage ("Xconfigurator") +for rec in rc: + print db[rec] + print db[rec]['name'] -- cgit v1.2.3