diff options
Diffstat (limited to 'python/header-py.c')
-rw-r--r-- | python/header-py.c | 119 |
1 files changed, 76 insertions, 43 deletions
diff --git a/python/header-py.c b/python/header-py.c index ff581f112..45af51637 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -157,20 +157,11 @@ static PyObject * hdrKeyList(hdrObject * s) return keys; } -static PyObject * hdrAsBytes(hdrObject * s, int legacy) +static PyObject * hdrAsBytes(hdrObject * s) { PyObject *res = NULL; - char *buf = NULL; - unsigned int len; - Header h = headerLink(s->h); - - /* XXX this legacy switch is a hack, needs to be removed. */ - if (legacy) { - h = headerCopy(s->h); /* XXX strip region tags, etc */ - headerFree(s->h); - } - buf = headerExport(h, &len); - h = headerFree(h); + unsigned int len = 0; + char *buf = headerExport(s->h, &len); if (buf == NULL || len == 0) { PyErr_SetString(pyrpmError, "can't unload bad header\n"); @@ -181,15 +172,9 @@ static PyObject * hdrAsBytes(hdrObject * s, int legacy) return res; } -static PyObject * hdrUnload(hdrObject * s, PyObject * args, PyObject *keywords) +static PyObject * hdrUnload(hdrObject * s) { - int legacy = 0; - static char *kwlist[] = { "legacyHeader", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, keywords, "|i", kwlist, &legacy)) - return NULL; - - return hdrAsBytes(s, legacy); + return hdrAsBytes(s); } static PyObject * hdrExpandFilelist(hdrObject * s) @@ -223,7 +208,6 @@ static PyObject * hdrFullFilelist(hdrObject * s) if (headerGet(h, RPMTAG_FILENAMES, fileNames, HEADERGET_EXT)) { rpmtdSetTag(fileNames, RPMTAG_OLDFILENAMES); headerPut(h, fileNames, HEADERPUT_DEFAULT); - rpmtdFreeData(fileNames); } rpmtdFree(fileNames); @@ -337,7 +321,7 @@ static long hdr_hash(PyObject * h) static PyObject * hdr_reduce(hdrObject *s) { PyObject *res = NULL; - PyObject *blob = hdrAsBytes(s, 0); + PyObject *blob = hdrAsBytes(s); if (blob) { res = Py_BuildValue("O(O)", Py_TYPE(s), blob); Py_DECREF(blob); @@ -347,31 +331,31 @@ static PyObject * hdr_reduce(hdrObject *s) static struct PyMethodDef hdr_methods[] = { {"keys", (PyCFunction) hdrKeyList, METH_NOARGS, - NULL }, - {"unload", (PyCFunction) hdrUnload, METH_VARARGS|METH_KEYWORDS, - NULL }, + "hdr.keys() -- Return a list of the header's rpm tags (int RPMTAG_*)." }, + {"unload", (PyCFunction) hdrUnload, METH_NOARGS, + "hdr.unload() -- Return binary representation\nof the header." }, {"expandFilelist", (PyCFunction) hdrExpandFilelist,METH_NOARGS, - NULL }, + "DEPRECATED -- Use hdr.convert() instead." }, {"compressFilelist",(PyCFunction) hdrCompressFilelist,METH_NOARGS, - NULL }, + "DEPRECATED -- Use hdr.convert() instead." }, {"fullFilelist", (PyCFunction) hdrFullFilelist, METH_NOARGS, - NULL }, + "DEPRECATED -- Obsolete method."}, {"convert", (PyCFunction) hdrConvert, METH_VARARGS|METH_KEYWORDS, - NULL }, + "hdr.convert(op=-1) -- Convert header - See HEADERCONV_*\nfor possible values of op."}, {"format", (PyCFunction) hdrFormat, METH_VARARGS|METH_KEYWORDS, - NULL }, + "hdr.format(format) -- Expand a query string with the header data.\n\nSee rpm -q for syntax." }, {"sprintf", (PyCFunction) hdrFormat, METH_VARARGS|METH_KEYWORDS, - NULL }, + "Alias for .format()." }, {"isSource", (PyCFunction)hdrIsSource, METH_NOARGS, - NULL }, + "hdr.isSource() -- Return if header describes a source package." }, {"write", (PyCFunction)hdrWrite, METH_VARARGS|METH_KEYWORDS, - NULL }, + "hdr.write(file, magic=True) -- Write header to file." }, {"dsOfHeader", (PyCFunction)hdr_dsOfHeader, METH_NOARGS, - NULL}, + "hdr.dsOfHeader() -- Return dependency set with the header's NEVR."}, {"dsFromHeader", (PyCFunction)hdr_dsFromHeader, METH_VARARGS|METH_KEYWORDS, - NULL}, + "hdr.dsFromHeader(to=RPMTAG_REQUIRENAME, flags=None)\nGet dependency set from header. to must be one of the NAME tags\nbelonging to a dependency:\n'Providename', 'Requirename', 'Obsoletename', 'Conflictname',\n'Triggername', 'Recommendname', 'Suggestname', 'Supplementname',\n'Enhancename' or one of the corresponding RPMTAG_*NAME constants." }, {"fiFromHeader", (PyCFunction)hdr_fiFromHeader, METH_VARARGS|METH_KEYWORDS, - NULL}, + "hdr.fiFromHeader() -- Return rpm.fi object containing the file\nmeta data from the header.\n\nDEPRECATED - Use rpm.files(hdr) instead."}, {"__reduce__", (PyCFunction)hdr_reduce, METH_NOARGS, NULL}, @@ -393,7 +377,8 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) if (obj == NULL) { h = headerNew(); } else if (CAPSULE_CHECK(obj)) { - h = CAPSULE_EXTRACT(obj, PYTHON_MODULENAME"._C_Header"); + h = CAPSULE_EXTRACT(obj, "rpm._C_Header"); + headerLink(h); } else if (hdrObject_Check(obj)) { h = headerCopy(((hdrObject*) obj)->h); } else if (PyBytes_Check(obj)) { @@ -404,7 +389,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) Py_END_ALLOW_THREADS; Py_XDECREF(fdo); } else { - PyErr_SetString(PyExc_TypeError, "header, blob or file expected!!"); + PyErr_SetString(PyExc_TypeError, "header, blob or file expected"); return NULL; } @@ -606,7 +591,7 @@ static int hdrPutTag(Header h, rpmTagVal tag, PyObject *value) rc = hdrAppendItem(h, tag, type, item); } } else { - PyErr_SetString(PyExc_RuntimeError, "cant happen, right?"); + PyErr_SetString(PyExc_RuntimeError, "can't happen, right?"); } return rc; @@ -680,11 +665,60 @@ static PySequenceMethods hdr_as_sequence = { }; static char hdr_doc[] = -""; + "A header object represents an RPM package header.\n" + "\n" + "All RPM packages have headers that provide metadata for the package.\n" + "Header objects can be returned by database queries or loaded from a\n" + "binary package on disk.\n" + "\n" + "The ts.hdrFromFdno() function returns the package header from a\n" + "package on disk, verifying package signatures and digests of the\n" + "package while reading.\n" + "\n" + "Note: The older method rpm.headerFromPackage() which has been replaced\n" + "by ts.hdrFromFdno() used to return a (hdr, isSource) tuple.\n" + "\n" + "If you need to distinguish source/binary headers, do:\n" + "\n" + " import os, rpm\n" + "\n" + " ts = rpm.TransactionSet()\n" + " fdno = os.open('/tmp/foo-1.0-1.i386.rpm', os.O_RDONLY)\n" + " hdr = ts.hdrFromFdno(fdno)\n" + " os.close(fdno)\n" + " if hdr[rpm.RPMTAG_SOURCEPACKAGE]:\n" + " print 'header is from a source package'\n" + " else:\n" + " print 'header is from a binary package'\n" + "\n" + "The Python interface to the header data is quite elegant. It\n" + "presents the data in a dictionary form. We'll take the header we\n" + "just loaded and access the data within it:\n" + "\n" + " print hdr[rpm.RPMTAG_NAME]\n" + " print hdr[rpm.RPMTAG_VERSION]\n" + " print hdr[rpm.RPMTAG_RELEASE]\n" + "\n" + "in the case of our 'foo-1.0-1.i386.rpm' package, this code would\n" + "output:\n" + " foo\n" + " 1.0\n" + " 1\n" + "\n" + "You make also access the header data by string name:\n" + "\n" + " print hdr['name']\n" + " print hdr['version']\n" + " print hdr['release']\n" + "\n" + "This method of access is a teensy bit slower because the name must be\n" + "translated into the tag number dynamically. You also must make sure\n" + "the strings in header lookups don't get translated, or the lookups\n" + "will fail.\n"; PyTypeObject hdr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - PYTHON_MODULENAME".hdr", /* tp_name */ + "rpm.hdr", /* tp_name */ sizeof(hdrObject), /* tp_size */ 0, /* tp_itemsize */ (destructor) hdr_dealloc, /* tp_dealloc */ @@ -729,8 +763,7 @@ PyObject * hdr_Wrap(PyTypeObject *subtype, Header h) { hdrObject * hdr = (hdrObject *)subtype->tp_alloc(subtype, 0); if (hdr == NULL) return NULL; - - hdr->h = headerLink(h); + hdr->h = h; return (PyObject *) hdr; } |