Exemplo n.º 1
0
static PyObject * hdr_subscript(hdrObject * s, PyObject * item)
{
    rpmTagVal tag;

    if (!tagNumFromPyObject(item, &tag)) return NULL;
    return hdrGetTag(s->h, tag);
}
Exemplo n.º 2
0
/** \ingroup py_c
 */
static int rpmfi_init(rpmfiObject * s, PyObject *args, PyObject *kwds)
	/*@globals rpmGlobalMacroContext @*/
	/*@modifies s, rpmGlobalMacroContext @*/
{
    hdrObject * ho = NULL;
    PyObject * to = NULL;
    rpmts ts = NULL;	/* XXX FIXME: fiFromHeader should be a ts method. */
    int tagN = RPMTAG_BASENAMES;
    int flags = 0;
    char * kwlist[] = {"header", "tag", "flags", NULL};

if (_rpmfi_debug < 0)
fprintf(stderr, "*** rpmfi_init(%p,%p,%p)\n", s, args, kwds);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmfi_init", kwlist,
	    &hdr_Type, &ho, &to, &flags))
	return -1;

    if (to != NULL) {
	tagN = tagNumFromPyObject(to);
	if (tagN == -1) {
	    PyErr_SetString(PyExc_KeyError, "unknown header tag");
	    return -1;
	}
    }
    s->fi = rpmfiNew(ts, hdrGetHeader(ho), tagN, flags);
    s->active = 0;

    return 0;
}
Exemplo n.º 3
0
static int hdrContains(hdrObject *s, PyObject *pytag)
{
    rpmTagVal tag;
    if (!tagNumFromPyObject(pytag, &tag)) return -1;

    return headerIsEntry(s->h, tag);
}
Exemplo n.º 4
0
static PyObject *rpmtd_new(PyTypeObject *subtype, 
			   PyObject *args, PyObject *kwds)
{
    char *kwlist[] = {"tag", NULL};
    PyObject *pytag;
    rpmTag tag;
    rpmtd td;
    rpmtdObject *self = PyObject_New(rpmtdObject, subtype);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &pytag))
	return NULL;

    tag = tagNumFromPyObject(pytag);
#ifdef	DYING	/* XXX with arbitrary tags, all tags are found. */
    if (tag == RPMTAG_NOT_FOUND) {
	PyErr_SetString(PyExc_TypeError, 
			"can't create container for unknown tag");
	return NULL;
    }
#endif

    td = rpmtdNew();
    td->tag = tag;
    td->type = rpmTagGetType(tag) & RPM_MASK_TYPE;

    self->td = td;
    return (PyObject *)self;
}
Exemplo n.º 5
0
static int rpmtd_set_tag(rpmtdObject *s, PyObject *value, void *closure)
{
    rpmTagVal tag;
    if (!tagNumFromPyObject(value, &tag)) return -1;

    if (!rpmtdSetTag(&(s->td), tag)) {
	PyErr_SetString(PyExc_ValueError, "incompatible tag for data");
	return -1;
    }
    return 0;
}
Exemplo n.º 6
0
static int hdr_ass_subscript(hdrObject *s, PyObject *key, PyObject *value)
{
    rpmTagVal tag;
    if (!tagNumFromPyObject(key, &tag)) return -1;

    if (value == NULL) {
	/* XXX should failure raise key error? */
	headerDel(s->h, tag);
    } else if (!hdrPutTag(s->h, tag, value)) {
	return -1;
    }
    return 0;
}
Exemplo n.º 7
0
static PyObject * hdr_getattro(hdrObject * s, PyObject * n)
{
    PyObject *res = PyObject_GenericGetAttr((PyObject *) s, n);
    if (res == NULL) {
	PyObject *type, *value, *traceback;
	rpmTagVal tag;

	/* Save and restore original exception if it's not a valid tag either */
	PyErr_Fetch(&type, &value, &traceback);
	if (tagNumFromPyObject(n, &tag)) {
	    Py_XDECREF(type);
	    Py_XDECREF(value);
	    Py_XDECREF(traceback);
	    res = hdrGetTag(s->h, tag);
	} else {
	    PyErr_Restore(type, value, traceback);
	}
    }
    return res;
}
Exemplo n.º 8
0
/** \ingroup py_c
 */
static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
{
    PyObject * po = NULL;
    PyObject * to = NULL;
    rpmTag tagN = RPMTAG_REQUIRENAME;
    rpmsenseFlags flags = RPMSENSE_ANY;
    rpmds ds = NULL;
    char * kwlist[] = {"obj", "tag", "flags", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:rpmds_init", kwlist, 
				     &po, &to, &flags)) {
	return NULL;
    }

    if (to != NULL && (tagN = tagNumFromPyObject(to)) == RPMTAG_NOT_FOUND) {
	return NULL;
    }

    if (PyTuple_Check(po) && PyTuple_Size(po) == 2) {
	char *n = PyString_AsString(PyTuple_GetItem(po, 0));
	char *evr = PyString_AsString(PyTuple_GetItem(po, 1));
	if (n && evr) {
	    ds = rpmdsSingle(tagN, n, evr, flags);
	}
    } else if (hdrObject_Check(po)) {
	Header h = hdrGetHeader((hdrObject*) po);
	if (tagN == RPMTAG_NAME) {
	    ds = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
	} else {
	    ds = rpmdsNew(h, tagN, flags);
	}
    } 

    if (ds == NULL) {
	PyErr_SetString(PyExc_TypeError, "(n,evr) tuple or header expected");
	return NULL;
    }

    return rpmds_Wrap(ds);;
}
Exemplo n.º 9
0
rpmfiObject *
hdr_fiFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
{
    hdrObject * ho = (hdrObject *)s;
    PyObject * to = NULL;
    rpmts ts = NULL;	/* XXX FIXME: fiFromHeader should be a ts method. */
    rpmTag tagN = RPMTAG_BASENAMES;
    int flags = 0;
    char * kwlist[] = {"tag", "flags", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:fiFromHeader", kwlist,
	    &to, &flags))
	return NULL;

    if (to != NULL) {
	tagN = tagNumFromPyObject(to);
	if (tagN == (rpmTag)-1) {
	    PyErr_SetString(PyExc_KeyError, "unknown header tag");
	    return NULL;
	}
    }
    return rpmfi_Wrap( rpmfiNew(ts, hdrGetHeader(ho), tagN, flags) );
}
Exemplo n.º 10
0
Arquivo: rpmmi-py.c Projeto: xrg/RPM
static PyObject *
rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
{
    PyObject *TagN = NULL;
    int type;
    char * pattern;
    rpmTag tag;
    char * kwlist[] = {"tag", "type", "patern", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
	    &TagN, &type, &pattern))
	return NULL;

    if ((tag = tagNumFromPyObject (TagN)) == -1) {
	PyErr_SetString(PyExc_TypeError, "unknown tag type");
	return NULL;
    }

    rpmdbSetIteratorRE(s->mi, tag, type, pattern);

    Py_INCREF (Py_None);
    return Py_None;

}
Exemplo n.º 11
0
static PyObject *rpmtd_setTag(rpmtdObject *self, PyObject *args, PyObject *kwds)
{
    PyObject *pytag;
    char *kwlist[] = {"tag", NULL};
    rpmTag tag;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &pytag))
	return NULL;

    tag = tagNumFromPyObject(pytag);
#ifdef	DYING	/* XXX with arbitrary tags, all tags are found. */
    if (tag == RPMTAG_NOT_FOUND) {
	PyErr_SetString(PyExc_KeyError, "unknown header tag");
	return NULL;
    }
#endif
    
    /* tag got just validated, so settag failure must be from type mismatch */
    if (!rpmtdSetTag(self->td, tag)) {
	PyErr_SetString(PyExc_TypeError, "tag type incompatible with data");
	return NULL;
    }
    Py_RETURN_TRUE;
}
Exemplo n.º 12
0
/*@null@*/
static PyObject *
rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
	/*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
	/*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
{
    PyObject *TagN = NULL;
    int type;
    char * pattern;
    rpmTag tag;
    char * kwlist[] = {"tag", "type", "pattern", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
	    &TagN, &type, &pattern))
	return NULL;

    if ((tag = tagNumFromPyObject (TagN)) == (rpmTag)-1) {
	PyErr_SetString(PyExc_TypeError, "unknown tag type");
	return NULL;
    }

    rpmmiAddPattern(s->mi, tag, type, pattern);

    Py_RETURN_NONE;
}