- python: enable threads on callbacks and longish rpmlib calls.
authorjbj <devnull@localhost>
Mon, 5 Aug 2002 18:40:58 +0000 (18:40 +0000)
committerjbj <devnull@localhost>
Mon, 5 Aug 2002 18:40:58 +0000 (18:40 +0000)
- python: expose RPMTAG_SOURCEPACKAGE to identify source headers.
- python: eliminate headerFromPackage() tuple return, deprecated.
- python: add ts.hdrFromFdno(fdno) method.

CVS patchset: 5601
CVS date: 2002/08/05 18:40:58

CHANGES
lib/rpmlib.h
python/header-py.c
python/rpmts-py.c
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index b29d597..97c254d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
        - fix: don't repackage %%ghost files.
        - add --predefine to define macros before reading macro configuration.
        - python: bare bones rollback bindings.
+       - python: enable threads on callbacks and longish rpmlib calls.
+       - python: expose RPMTAG_SOURCEPACKAGE to identify source headers.
+       - python: eliminate headerFromPackage() tuple return, deprecated.
+       - python: add ts.hdrFromFdno(fdno) method.
 
 4.0.3 -> 4.0.4:
        - solaris: translate i86pc to i386 (#57182).
index bff95e4..831dc8b 100644 (file)
@@ -371,7 +371,7 @@ typedef enum rpmTag_e {
 /*@-enummemuse@*/
     RPMTAG_CAPABILITY          = 1105, /*!< internal - obsolete */
 /*@=enummemuse@*/
-    RPMTAG_SOURCEPACKAGE       = 1106, /*!< internal */
+    RPMTAG_SOURCEPACKAGE       = 1106, /*!< src.rpm header marker */
 /*@-enummemuse@*/
     RPMTAG_OLDORIGFILENAMES    = 1107, /*!< internal - obsolete */
 /*@=enummemuse@*/
index b3d88e6..978fbc1 100644 (file)
  * Header objects can be returned by database queries or loaded from a
  * binary package on disk.
  * 
- * The headerFromPackage function loads the package header from a
- * package on disk.  It returns a tuple of a "isSource" flag and the
- * header object.  The "isSource" flag is set to 1 if the package
- * header was read from a source rpm or to 0 if the package header was
- * read from a binary rpm.
- * 
- * For example:
+ * The headerFromPackage function returns the package header from a
+ * package on disk.
+ *
+ * Note: rpm.headerFromPackage() used to return a (hdr, isSource) tuple.
+ * If you need to distinguish source/binary headers, do:
  * \code
  *     import os, rpm
- *  
+ *
  *     fd = os.open("/tmp/foo-1.0-1.i386.rpm", os.O_RDONLY)
- *     hdr = rpm.headerFromPackage(fd)[0]
- *     os.close(fd)
+ *     hdr = rpm.headerFromPackage(fd)
+ *     if hdr[rpm.RPMTAG_SOURCEPACKAGE]:
+ *        print "header is from a source package"
+ *     else:
+ *        print "header is from a binary package"
  * \endcode
- *
+ * 
  * The Python interface to the header data is quite elegant.  It
  * presents the data in a dictionary form.  We'll take the header we
  * just loaded and access the data within it:
@@ -865,6 +866,7 @@ Header hdrGetHeader(hdrObject * s)
 }
 
 /**
+ * @deprecated Use ts.hdrFromFdno() instead.
  */
 PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args)
 {
@@ -872,7 +874,6 @@ PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args)
     Header h;
     FD_t fd;
     int rawFd;
-    int isSource = 0;
     rpmRC rc;
 
     if (!PyArg_ParseTuple(args, "i", &rawFd)) return NULL;
@@ -888,7 +889,6 @@ PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args)
     switch (rc) {
     case RPMRC_BADSIZE:
     case RPMRC_OK:
-       isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
        hdr = hdr_Wrap(h);
        h = headerFree(h);      /* XXX ref held by hdr */
        break;
@@ -905,7 +905,7 @@ PyObject * rpmHeaderFromPackage(PyObject * self, PyObject * args)
        return NULL;
     }
 
-    return Py_BuildValue("(Ni)", hdr, isSource);
+    return Py_BuildValue("N", hdr);
 }
 
 /**
index 3e84cfb..4d77432 100644 (file)
@@ -278,9 +278,9 @@ fprintf(stderr, "*** rpmts_Check(%p) ts %p\n", s, s->ts);
 
     Py_BEGIN_ALLOW_THREADS
     xx = rpmtsCheck(s->ts);
-    Py_END_ALLOW_THREADS
 
     ps = rpmtsProblems(s->ts);
+    Py_END_ALLOW_THREADS
     if (ps) {
        list = PyList_New(0);
 
@@ -447,11 +447,11 @@ fprintf(stderr, "*** rpmts_IDTXglob(%p) ts %p\n", s, s->ts);
 
     if (!PyArg_ParseTuple(args, ":IDTXglob")) return NULL;
 
-    globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
     Py_BEGIN_ALLOW_THREADS
+    globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
     idtx = IDTXglob(s->ts, globstr, tag);
-    Py_END_ALLOW_THREADS
     globstr = _free(globstr);
+    Py_END_ALLOW_THREADS
 
     if (idtx->nidt <= 0) {
        result = Py_None;
@@ -491,6 +491,7 @@ fprintf(stderr, "*** rpmts_Rollback(%p) ts %p\n", s, s->ts);
 
     if (!PyArg_ParseTuple(args, "u:Rollback", &rbtid)) return NULL;
 
+    Py_BEGIN_ALLOW_THREADS
     memset(ia, 0, sizeof(*ia));
     ia->qva_flags = (VERIFY_DIGEST|VERIFY_SIGNATURE|VERIFY_HDRCHK);
     ia->transFlags |= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL);
@@ -501,10 +502,9 @@ fprintf(stderr, "*** rpmts_Rollback(%p) ts %p\n", s, s->ts);
     ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
 
     transFlags = rpmtsSetFlags(s->ts, ia->transFlags);
-    Py_BEGIN_ALLOW_THREADS
     rc = rpmRollback(s->ts, ia, av);
-    Py_END_ALLOW_THREADS
     transFlags = rpmtsSetFlags(s->ts, transFlags);
+    Py_END_ALLOW_THREADS
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -621,6 +621,50 @@ fprintf(stderr, "*** rpmts_VerifyDB(%p) ts %p\n", s, s->ts);
 /** \ingroup python
  */
 static PyObject *
+rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args)
+       /*@globals _Py_NoneStruct, fileSystem @*/
+       /*@modifies s, _Py_NoneStruct, fileSystem @*/
+{
+    hdrObject * hdr;
+    Header h;
+    FD_t fd;
+    int fdno;
+    rpmRC rpmrc;
+
+if (_rpmts_debug)
+fprintf(stderr, "*** rpmts_HdrFromFdno(%p) ts %p\n", s, s->ts);
+
+    if (!PyArg_ParseTuple(args, "i:HdrFromFdno", &fdno)) return NULL;
+
+    fd = fdDup(fdno);
+    rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h);
+    Fclose(fd);
+
+    switch (rpmrc) {
+    case RPMRC_BADSIZE:
+    case RPMRC_OK:
+       hdr = hdr_Wrap(h);
+       h = headerFree(h);      /* XXX ref held by hdr */
+       break;
+
+    case RPMRC_NOTFOUND:
+       Py_INCREF(Py_None);
+       hdr = (hdrObject *) Py_None;
+       break;
+
+    case RPMRC_FAIL:
+    case RPMRC_SHORTREAD:
+    default:
+       PyErr_SetString(pyrpmError, "error reading package header");
+       return NULL;
+    }
+
+    return Py_BuildValue("N", hdr);
+}
+
+/** \ingroup python
+ */
+static PyObject *
 rpmts_HdrCheck(rpmtsObject * s, PyObject * args)
        /*@globals _Py_NoneStruct @*/
        /*@modifies s, _Py_NoneStruct @*/
@@ -726,6 +770,7 @@ struct rpmtsCallbackType_s {
     PyObject * cb;
     PyObject * data;
     int pythonError;
+    PyThreadState *_save;
 };
 
 /** \ingroup python
@@ -745,12 +790,15 @@ rpmtsCallback(/*@unused@*/ const void * hd, const rpmCallbackType what,
 
     if (!pkgKey) pkgKey = Py_None;
 
+    PyEval_RestoreThread(cbInfo->_save);
+
     args = Py_BuildValue("(illOO)", what, amount, total, pkgKey, cbInfo->data);
     result = PyEval_CallObject(cbInfo->cb, args);
     Py_DECREF(args);
 
     if (!result) {
        cbInfo->pythonError = 1;
+       cbInfo->_save = PyEval_SaveThread();
        return NULL;
     }
 
@@ -759,9 +807,11 @@ rpmtsCallback(/*@unused@*/ const void * hd, const rpmCallbackType what,
 
         if (!PyArg_Parse(result, "i", &fdno)) {
            cbInfo->pythonError = 1;
+           cbInfo->_save = PyEval_SaveThread();
            return NULL;
        }
        Py_DECREF(result);
+       cbInfo->_save = PyEval_SaveThread();
 
        fd = fdDup(fdno);
 if (_rpmts_debug)
@@ -779,6 +829,7 @@ fprintf(stderr, "\t%ld:%ld key %p\n", amount, total, pkgKey);
     }
 
     Py_DECREF(result);
+    cbInfo->_save = PyEval_SaveThread();
 
     return NULL;
 }
@@ -800,6 +851,7 @@ static PyObject * rpmts_Run(rpmtsObject * s, PyObject * args)
        return NULL;
 
     cbInfo.pythonError = 0;
+    cbInfo._save = PyEval_SaveThread();
 
     (void) rpmtsSetNotifyCallback(s->ts, rpmtsCallback, (void *) &cbInfo);
     (void) rpmtsSetFlags(s->ts, flags);
@@ -807,12 +859,12 @@ static PyObject * rpmts_Run(rpmtsObject * s, PyObject * args)
 if (_rpmts_debug)
 fprintf(stderr, "*** rpmts_Run(%p) ts %p flags %x ignore %x\n", s, s->ts, s->ts->transFlags, ignoreSet);
 
-    Py_BEGIN_ALLOW_THREADS
     rc = rpmtsRun(s->ts, NULL, ignoreSet);
-    Py_END_ALLOW_THREADS
 
     ps = rpmtsProblems(s->ts);
 
+    PyEval_RestoreThread(cbInfo._save);
+
     if (cbInfo.pythonError) {
        ps = rpmpsFree(ps);
        return NULL;
@@ -1002,6 +1054,9 @@ static struct PyMethodDef rpmts_methods[] = {
  {"verifyDB",  (PyCFunction) rpmts_VerifyDB,   METH_VARARGS,
 "ts.verifyDB() -> None\n\
 - Verify the default transaction rpmdb.\n" },
+ {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS,
+"ts.hdrFromFdno(fdno) -> hdr\n\
+- Read a package header from a file descriptor.\n" },
  {"hdrCheck",  (PyCFunction) rpmts_HdrCheck,   METH_VARARGS,
        NULL },
  {"setVerifySigFlags",(PyCFunction) rpmts_SetVerifySigFlags,   METH_VARARGS,
index decacf0..ab393b1 100644 (file)
@@ -17,7 +17,7 @@ Name: rpm
 %define version @VERSION@
 Version: %{version}
 %{expand: %%define rpm_version %{version}}
-Release: 0.69
+Release: 0.70
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/rpm-%{rpm_version}.tar.gz
 Copyright: GPL
@@ -517,8 +517,12 @@ fi
 %{__prefix}/include/popt.h
 
 %changelog
-* Mon Aug  5 2002 Jeff Johnson <jbj@redhat.com> 4.1-0.69
+* Mon Aug  5 2002 Jeff Johnson <jbj@redhat.com> 4.1-0.70
 - python: bare bones rollback bindings.
+- python: enable threads on callbacks and longish rpmlib calls.
+- python: expose RPMTAG_SOURCEPACKAGE to identify source headers.
+- python: eliminate headerFromPackage() tuple return, deprecated.
+- python: add ts.hdrFromFdno(fdno) method.
 
 * Sun Aug  4 2002 Jeff Johnson <jbj@redhat.com> 4.1-0.68
 - resurrect --rollback.