11 #define _RPMTAG_INTERNAL
14 #define _RPMEVR_INTERNAL
155 return PyBool_FromLong(isSource);
172 list = PyList_New(0);
183 #if !defined(SUPPORT_I18NSTRING_TYPE)
194 o=PyInt_FromLong(he->
tag);
220 static char *
kwlist[] = {
"legacyHeader",
NULL};
222 if (!PyArg_ParseTupleAndKeywords(args, keywords,
"|i", kwlist, &legacy))
240 if (buf ==
NULL || nb == 0) {
241 PyErr_SetString(
pyrpmError,
"can't unload bad header\n");
245 rc = PyString_FromStringAndSize(buf, nb);
256 const char * origin =
NULL;
272 const char * origin =
NULL;
274 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s:SetOrigin", kwlist, &origin))
295 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &fmt))
316 {
"keys", (PyCFunction)
hdrKeyList, METH_NOARGS,
318 {
"unload", (PyCFunction)
hdrUnload, METH_VARARGS|METH_KEYWORDS,
322 {
"setorigin", (PyCFunction)
hdrSetOrigin, METH_VARARGS|METH_KEYWORDS,
324 {
"sprintf", (PyCFunction)
hdrSprintf, METH_VARARGS|METH_KEYWORDS,
326 {
"isSource", (PyCFunction)
hdrIsSource, METH_NOARGS,
368 if (PyInt_Check(item)) {
369 return (
rpmTag) PyInt_AsLong(item);
370 }
else if (PyString_Check(item) || PyUnicode_Check(item)) {
371 str = PyString_AsString(item);
374 return (
rpmTag)0xffffffff;
385 PyObject *
o, * metao;
387 const struct headerSprintfExtension_s * ext =
NULL;
390 if (PyCObject_Check (item))
391 ext = PyCObject_AsVoidPtr(item);
395 if (tag == (
rpmTag)0xffffffff && (PyString_Check(item) || PyUnicode_Check(item))) {
400 str = PyString_AsString(item);
401 while (extensions->name) {
402 if (extensions->type == HEADER_EXT_TAG
407 if (extensions->type == HEADER_EXT_MORE)
408 extensions = *extensions->u.more;
414 ext->u.tagFunction(s->
h, he);
416 if (tag == (
rpmTag)0xffffffff) {
417 PyErr_SetString(PyExc_KeyError,
"unknown header tag");
437 return PyList_New(0);
482 o = PyString_FromStringAndSize(he->
p.
str, he->
c);
486 if (he->
c != 1 || forceArray) {
487 metao = PyList_New(0);
491 for (i = 0; i < he->
c; i++) {
492 o = PyInt_FromLong(he->
p.
ui8p[i]);
502 o = PyInt_FromLong(he->
p.
ui8p[0]);
507 if (he->
c != 1 || forceArray) {
508 metao = PyList_New(0);
512 for (i = 0; i < he->
c; i++) {
513 o = PyInt_FromLong(he->
p.
ui16p[i]);
523 o = PyInt_FromLong(he->
p.
ui16p[0]);
528 if (he->
c != 1 || forceArray) {
529 metao = PyList_New(0);
533 for (i = 0; i < he->
c; i++) {
534 o = PyInt_FromLong(he->
p.
ui32p[i]);
544 o = PyInt_FromLong(he->
p.
ui32p[0]);
549 if (he->
c != 1 || forceArray) {
550 metao = PyList_New(0);
554 for (i = 0; i < he->
c; i++) {
555 o = PyInt_FromLong(he->
p.
ui64p[i]);
565 o = PyInt_FromLong(he->
p.
ui64p[0]);
570 metao = PyList_New(0);
574 for (i = 0; i < he->
c; i++) {
575 o = PyString_FromString(he->
p.
argv[i]);
588 o = PyString_FromString(he->
p.
str);
590 o = PyString_FromString(
"");
594 PyErr_SetString(PyExc_TypeError,
"unsupported type in header");
616 res = PyObject_GenericGetAttr((PyObject *)o, n);
625 return PyObject_GenericSetAttr((PyObject *)o, n, v);
637 PyObject_HEAD_INIT(&PyType_Type)
659 #if Py_TPFLAGS_HAVE_ITER
696 PyObject *
hdrLoad(PyObject *
self, PyObject *
args, PyObject * kwds)
705 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s#", kwlist, &obj, &len))
714 memcpy (copy, obj, len);
727 return (PyObject *) hdr;
743 list = PyList_New(0);
747 Py_BEGIN_ALLOW_THREADS
748 {
const char item[] =
"Header";
756 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
773 Py_BEGIN_ALLOW_THREADS
774 {
const char item[] =
"Header";
782 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
801 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
822 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &filespec))
825 fd =
Fopen(filespec,
"r.fdio");
851 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
854 offset = lseek(fileno, 0,
SEEK_CUR);
863 Py_BEGIN_ALLOW_THREADS
864 {
const char item[] =
"Header";
872 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
879 tuple = PyTuple_New(2);
882 PyTuple_SET_ITEM(tuple, 0, (PyObject *)
hdr_Wrap(h));
883 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
889 PyTuple_SET_ITEM(tuple, 0,
Py_None);
890 PyTuple_SET_ITEM(tuple, 1,
Py_None);
907 for(count = 0; count < PyList_Size(list); count++){
908 Py_BEGIN_ALLOW_THREADS
909 const char item[] =
"Header";
914 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgWrite", item, msg, rc);
933 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Oi", kwlist, &list, &fileno))
955 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Os", kwlist, &list, &filespec))
958 fd =
Fopen(filespec,
"w.fdio");
976 char *
kwlist[] = {
"version0",
"version1",
NULL};
978 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O!O!", kwlist, &hdr_Type,
979 &h1, &hdr_Type, &h2))
990 PyObject *aTuple, *bTuple;
992 if (!PyArg_ParseTuple(args,
"OO", &aTuple, &bTuple) ||
993 !PyArg_ParseTuple(aTuple,
"zzz|z",
994 &a->F[RPMEVR_E], &a->F[RPMEVR_V], &a->F[RPMEVR_R], &a->F[RPMEVR_D]) ||
995 !PyArg_ParseTuple(bTuple,
"zzz|z",
996 &b->F[RPMEVR_E], &b->F[RPMEVR_V], &b->F[RPMEVR_R], &b->F[RPMEVR_D]))
1004 if (a->F[RPMEVR_E] ==
NULL) a->F[RPMEVR_E] =
"0";
1005 if (b->F[RPMEVR_E] ==
NULL) b->F[RPMEVR_E] =
"0";
1006 if (a->F[RPMEVR_V] ==
NULL) a->F[RPMEVR_V] =
"";
1007 if (b->F[RPMEVR_V] ==
NULL) b->F[RPMEVR_V] =
"";
1008 if (a->F[RPMEVR_R] ==
NULL) a->F[RPMEVR_R] =
"";
1009 if (b->F[RPMEVR_R] ==
NULL) b->F[RPMEVR_R] =
"";
1010 if (a->F[RPMEVR_D] ==
NULL) a->F[RPMEVR_D] =
"";
1011 if (b->F[RPMEVR_D] ==
NULL) b->F[RPMEVR_D] =
"";
1027 char * evr1, * evr2;
1030 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"ss", kwlist, &evr1, &evr2))
1041 return PyLong_FromLong(rc);
1049 PyObject * tuple =
NULL;
1051 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &evr))
1055 tuple =
Py_BuildValue(
"(Isss)", EVR->F[RPMEVR_E] ? atoi(EVR->F[RPMEVR_E]) : 0, EVR->F[RPMEVR_V], EVR->F[RPMEVR_R], EVR->F[RPMEVR_D]);
int rpmEVRcompare(const EVR_t a, const EVR_t b)
Compare EVR containers for equality.
PyObject * rpmReadHeaders(FD_t fd)
rpmlog(RPMLOG_ERR,"%s\n", buf)
PyObject * rpmHeaderToFD(PyObject *self, PyObject *args, PyObject *kwds)
rpmRC rpmpkgWrite(const char *fn, FD_t fd, void *ptr, const char **msg)
Write item onto file descriptor.
PyObject * rpmHeaderToFile(PyObject *self, PyObject *args, PyObject *kwds)
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
static char *size_t nb
fgets(3) analogue that reads \ continuations.
PyObject * rpmHeaderFromFD(PyObject *self, PyObject *args, PyObject *kwds)
PyObject * evrCompare(PyObject *self, PyObject *args, PyObject *kwds)
EVR_t rpmEVRnew(uint32_t Flags, int initialize)
Create a new EVR container.
PyObject * rpmHeaderFromFile(PyObject *self, PyObject *args, PyObject *kwds)
rpmTag tagValue(const char *tagstr)
Return tag value from name.
int rpmEVRparse(const char *evrstr, EVR_t evr)
Split EVR string into epoch, version, and release components.
rpmdsObject * hdr_dsFromHeader(PyObject *s, PyObject *args, PyObject *kwds)
PyList_Append(s->keyList, key)
enum rpmRC_e rpmRC
RPM return codes.
memset(_r, 0, sizeof(*_r))
assert(key->size==sizeof(hdrNum))
static PyMappingMethods hdr_as_mapping
struct hdrObject_s hdrObject
rpmTag tagNumFromPyObject(PyObject *item)
PyObject * labelCompare(PyObject *self, PyObject *args)
rpmfiObject * hdr_fiFromHeader(PyObject *s, PyObject *args, PyObject *kwds)
The FD_t File Handle data structure.
hdrObject * hdr_Wrap(Header h)
PyObject * rpmWriteHeaders(PyObject *list, FD_t fd)
int Fclose(FD_t fd)
fclose(3) clone.
PyObject * hdrLoad(PyObject *self, PyObject *args, PyObject *kwds)
PyObject * versionCompare(PyObject *self, PyObject *args, PyObject *kwds)
PyObject * evrSplit(PyObject *self, PyObject *args, PyObject *kwds)
EVR_t rpmEVRfree(EVR_t evr)
Destroy an EVR container.
return Py_BuildValue("i", pkgKey)
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
Methods to handle package elements.
Header hdrGetHeader(hdrObject *s)
PyObject * rpmSingleHeaderFromFD(PyObject *self, PyObject *args, PyObject *kwds)
Structures and prototypes used for an "rpmts" transaction set.
static void hdr_dealloc(hdrObject *s)
static PyObject * hdr_subscript(hdrObject *s, PyObject *item)
static struct PyMethodDef hdr_methods[]
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
char * buf
Parse (and execute) macro undefinition.
rpmRC rpmpkgRead(const char *fn, FD_t fd, void *ptr, const char **msg)
Read item from file descriptor.
rpmdsObject * hdr_dsOfHeader(PyObject *s)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int rpmVersionCompare(Header A, Header B)