* 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:
}
/**
+ * @deprecated Use ts.hdrFromFdno() instead.
*/
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;
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;
return NULL;
}
- return Py_BuildValue("(Ni)", hdr, isSource);
+ return Py_BuildValue("N", hdr);
}
/**
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);
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;
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);
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;
/** \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 @*/
PyObject * cb;
PyObject * data;
int pythonError;
+ PyThreadState *_save;
};
/** \ingroup python
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;
}
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)
}
Py_DECREF(result);
+ cbInfo->_save = PyEval_SaveThread();
return NULL;
}
return NULL;
cbInfo.pythonError = 0;
+ cbInfo._save = PyEval_SaveThread();
(void) rpmtsSetNotifyCallback(s->ts, rpmtsCallback, (void *) &cbInfo);
(void) rpmtsSetFlags(s->ts, flags);
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;
{"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,