|
Packit Service |
7203c3 |
#include "rpmsystem-py.h"
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
#include <rpm/rpmdb.h>
|
|
Packit Service |
7203c3 |
#include <rpm/header.h>
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
#include "rpmmi-py.h"
|
|
Packit Service |
7203c3 |
#include "header-py.h"
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
/** \ingroup python
|
|
Packit Service |
7203c3 |
* \class Rpmmi
|
|
Packit Service |
7203c3 |
* \brief A python rpm.mi match iterator object represents the result of a
|
|
Packit Service |
7203c3 |
* database query.
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* Instances of the rpm.mi object provide access to headers that match
|
|
Packit Service |
7203c3 |
* certain criteria. Typically, a primary index is accessed to find
|
|
Packit Service |
7203c3 |
* a set of headers that contain a key, and each header is returned
|
|
Packit Service |
7203c3 |
* serially.
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* The rpm.mi class conains the following methods:
|
|
Packit Service |
7203c3 |
* - next() -> hdr Return the next header that matches.
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* - pattern(tag,mire,pattern) Specify secondary match criteria.
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* To obtain a rpm.mi object to query the database used by a transaction,
|
|
Packit Service |
7203c3 |
* the ts.match(tag,key,len) method is used.
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* Here's an example that prints the name of all installed packages:
|
|
Packit Service |
7203c3 |
* \code
|
|
Packit Service |
7203c3 |
* import rpm
|
|
Packit Service |
7203c3 |
* ts = rpm.TransactionSet()
|
|
Packit Service |
7203c3 |
* for h in ts.dbMatch():
|
|
Packit Service |
7203c3 |
* print(h['name'])
|
|
Packit Service |
7203c3 |
* \endcode
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* Here's a more typical example that uses the Name index to retrieve
|
|
Packit Service |
7203c3 |
* all installed kernel(s):
|
|
Packit Service |
7203c3 |
* \code
|
|
Packit Service |
7203c3 |
* import rpm
|
|
Packit Service |
7203c3 |
* ts = rpm.TransactionSet()
|
|
Packit Service |
7203c3 |
* mi = ts.dbMatch('name', 'kernel')
|
|
Packit Service |
7203c3 |
* for h in mi:
|
|
Packit Service |
7203c3 |
* print('%s-%s-%s' % (h['name'], h['version'], h['release']))
|
|
Packit Service |
7203c3 |
* \endcode
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
* Finally, here's an example that retrieves all packages whose name
|
|
Packit Service |
7203c3 |
* matches the glob expression 'XFree*':
|
|
Packit Service |
7203c3 |
* \code
|
|
Packit Service |
7203c3 |
* import rpm
|
|
Packit Service |
7203c3 |
* ts = rpm.TransactionSet()
|
|
Packit Service |
7203c3 |
* mi = ts.dbMatch()
|
|
Packit Service |
7203c3 |
* mi.pattern('name', rpm.RPMMIRE_GLOB, 'XFree*')
|
|
Packit Service |
7203c3 |
* for h in mi:
|
|
Packit Service |
7203c3 |
* print('%s-%s-%s' % (h['name'], h['version'], h['release']))
|
|
Packit Service |
7203c3 |
* \endcode
|
|
Packit Service |
7203c3 |
*
|
|
Packit Service |
7203c3 |
*/
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
/** \ingroup python
|
|
Packit Service |
7203c3 |
* \name Class: Rpmmi
|
|
Packit Service |
7203c3 |
*/
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
struct rpmmiObject_s {
|
|
Packit Service |
7203c3 |
PyObject_HEAD
|
|
Packit Service |
7203c3 |
PyObject *md_dict; /*!< to look like PyModuleObject */
|
|
Packit Service |
7203c3 |
PyObject *ref; /* for db/ts refcounting */
|
|
Packit Service |
7203c3 |
rpmdbMatchIterator mi;
|
|
Packit Service |
7203c3 |
} ;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static PyObject *
|
|
Packit Service |
7203c3 |
rpmmi_iternext(rpmmiObject * s)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
Header h;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
if (s->mi == NULL || (h = rpmdbNextIterator(s->mi)) == NULL) {
|
|
Packit Service |
7203c3 |
s->mi = rpmdbFreeIterator(s->mi);
|
|
Packit Service |
7203c3 |
return NULL;
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
headerLink(h);
|
|
Packit Service |
7203c3 |
return hdr_Wrap(&hdr_Type, h);
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static PyObject *
|
|
Packit Service |
7203c3 |
rpmmi_Instance(rpmmiObject * s, PyObject * unused)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
int rc = 0;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
if (s->mi != NULL)
|
|
Packit Service |
7203c3 |
rc = rpmdbGetIteratorOffset(s->mi);
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
return Py_BuildValue("i", rc);
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static PyObject *
|
|
Packit Service |
7203c3 |
rpmmi_Count(rpmmiObject * s, PyObject * unused)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
DEPRECATED_METHOD("use len(mi) instead");
|
|
Packit Service |
7203c3 |
return Py_BuildValue("i", PyMapping_Size((PyObject *)s));
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static PyObject *
|
|
Packit Service |
7203c3 |
rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
int type;
|
|
Packit Service |
7203c3 |
const char * pattern;
|
|
Packit Service |
7203c3 |
rpmTagVal tag;
|
|
Packit Service |
7203c3 |
char * kwlist[] = {"tag", "type", "patern", NULL};
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&is:Pattern", kwlist,
|
|
Packit Service |
7203c3 |
tagNumFromPyObject, &tag, &type, &pattern))
|
|
Packit Service |
7203c3 |
return NULL;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
rpmdbSetIteratorRE(s->mi, tag, type, pattern);
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
Py_RETURN_NONE;
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static struct PyMethodDef rpmmi_methods[] = {
|
|
Packit Service |
7203c3 |
{"instance", (PyCFunction) rpmmi_Instance, METH_NOARGS,
|
|
Packit Service |
7203c3 |
"mi.instance() -- Return the number (db key) of the current header."},
|
|
Packit Service |
7203c3 |
{"count", (PyCFunction) rpmmi_Count, METH_NOARGS,
|
|
Packit Service |
7203c3 |
"Deprecated, use len(mi) instead.\n" },
|
|
Packit Service |
7203c3 |
{"pattern", (PyCFunction) rpmmi_Pattern, METH_VARARGS|METH_KEYWORDS,
|
|
Packit Service |
7203c3 |
"mi.pattern(TagN, mire_type, pattern)\n\
|
|
Packit Service |
7203c3 |
- Set a secondary match pattern on tags from retrieved header.\n" },
|
|
Packit Service |
7203c3 |
{NULL, NULL} /* sentinel */
|
|
Packit Service |
7203c3 |
};
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static void rpmmi_dealloc(rpmmiObject * s)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
s->mi = rpmdbFreeIterator(s->mi);
|
|
Packit Service |
7203c3 |
Py_DECREF(s->ref);
|
|
Packit Service |
7203c3 |
Py_TYPE(s)->tp_free((PyObject *)s);
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static Py_ssize_t rpmmi_length(rpmmiObject * s)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
return s->mi ? rpmdbGetIteratorCount(s->mi) : 0;
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static int rpmmi_bool(rpmmiObject *s)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
return (s->mi != NULL);
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
PyMappingMethods rpmmi_as_mapping = {
|
|
Packit Service |
7203c3 |
(lenfunc) rpmmi_length, /* mp_length */
|
|
Packit Service |
7203c3 |
0,
|
|
Packit Service |
7203c3 |
};
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static PyNumberMethods rpmmi_as_number = {
|
|
Packit Service |
7203c3 |
0, /* nb_add */
|
|
Packit Service |
7203c3 |
0, /* nb_subtract */
|
|
Packit Service |
7203c3 |
0, /* nb_multiply */
|
|
Packit Service |
7203c3 |
#if PY_MAJOR_VERSION < 3
|
|
Packit Service |
7203c3 |
0, /* nb_divide */
|
|
Packit Service |
7203c3 |
#endif
|
|
Packit Service |
7203c3 |
0, /* nb_remainder */
|
|
Packit Service |
7203c3 |
0, /* nb_divmod */
|
|
Packit Service |
7203c3 |
0, /* nb_power */
|
|
Packit Service |
7203c3 |
0, /* nb_negative */
|
|
Packit Service |
7203c3 |
0, /* nb_positive */
|
|
Packit Service |
7203c3 |
0, /* nb_absolute */
|
|
Packit Service |
7203c3 |
(inquiry)rpmmi_bool, /* nb_bool/nonzero */
|
|
Packit Service |
7203c3 |
};
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
static char rpmmi_doc[] =
|
|
Packit Service |
7203c3 |
"rpm.mi match iterator object represents the result of a\n"
|
|
Packit Service |
7203c3 |
" database query.\n"
|
|
Packit Service |
7203c3 |
"\n"
|
|
Packit Service |
7203c3 |
"Instances of the rpm.mi object provide access to headers that match\n"
|
|
Packit Service |
7203c3 |
"certain criteria. Typically, a primary index is accessed to find\n"
|
|
Packit Service |
7203c3 |
"a set of headers that contain a key, and each header is returned\n"
|
|
Packit Service |
7203c3 |
"serially.\n"
|
|
Packit Service |
7203c3 |
"\n"
|
|
Packit Service |
7203c3 |
"To obtain a rpm.mi object to query the database used by a transaction,\n"
|
|
Packit Service |
7203c3 |
"the ts.match(tag,key,len) method is used.\n"
|
|
Packit Service |
7203c3 |
"\n"
|
|
Packit Service |
7203c3 |
"Here's an example that prints the name of all installed packages:\n"
|
|
Packit Service |
7203c3 |
" import rpm\n"
|
|
Packit Service |
7203c3 |
" ts = rpm.TransactionSet()\n"
|
|
Packit Service |
7203c3 |
" for h in ts.dbMatch():\n"
|
|
Packit Service |
7203c3 |
" print(h['name'])\n"
|
|
Packit Service |
7203c3 |
"\n"
|
|
Packit Service |
7203c3 |
"Here's a more typical example that uses the Name index to retrieve\n"
|
|
Packit Service |
7203c3 |
"all installed kernel(s):\n"
|
|
Packit Service |
7203c3 |
" import rpm\n"
|
|
Packit Service |
7203c3 |
" ts = rpm.TransactionSet()\n"
|
|
Packit Service |
7203c3 |
" mi = ts.dbMatch('name', 'kernel')\n"
|
|
Packit Service |
7203c3 |
" for h in mi:\n"
|
|
Packit Service |
7203c3 |
" print('%s-%s-%s' % (h['name'], h['version'], h['release']))\n"
|
|
Packit Service |
7203c3 |
"\n"
|
|
Packit Service |
7203c3 |
"Finally, here's an example that retrieves all packages whose name\n"
|
|
Packit Service |
7203c3 |
"matches the glob expression 'XFree*':\n"
|
|
Packit Service |
7203c3 |
" import rpm\n"
|
|
Packit Service |
7203c3 |
" ts = rpm.TransactionSet()\n"
|
|
Packit Service |
7203c3 |
" mi = ts.dbMatch()\n"
|
|
Packit Service |
7203c3 |
" mi.pattern('name', rpm.RPMMIRE_GLOB, 'XFree*')\n"
|
|
Packit Service |
7203c3 |
" for h in mi:\n"
|
|
Packit Service |
7203c3 |
" print('%s-%s-%s' % (h['name'], h['version'], h['release']))\n"
|
|
Packit Service |
7203c3 |
;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
PyTypeObject rpmmi_Type = {
|
|
Packit Service |
7203c3 |
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
Packit Service |
7203c3 |
"rpm.mi", /* tp_name */
|
|
Packit Service |
7203c3 |
sizeof(rpmmiObject), /* tp_size */
|
|
Packit Service |
7203c3 |
0, /* tp_itemsize */
|
|
Packit Service |
7203c3 |
(destructor) rpmmi_dealloc, /* tp_dealloc */
|
|
Packit Service |
7203c3 |
0, /* tp_print */
|
|
Packit Service |
7203c3 |
(getattrfunc)0, /* tp_getattr */
|
|
Packit Service |
7203c3 |
0, /* tp_setattr */
|
|
Packit Service |
7203c3 |
0, /* tp_compare */
|
|
Packit Service |
7203c3 |
0, /* tp_repr */
|
|
Packit Service |
7203c3 |
&rpmmi_as_number, /* tp_as_number */
|
|
Packit Service |
7203c3 |
0, /* tp_as_sequence */
|
|
Packit Service |
7203c3 |
&rpmmi_as_mapping, /* tp_as_mapping */
|
|
Packit Service |
7203c3 |
0, /* tp_hash */
|
|
Packit Service |
7203c3 |
0, /* tp_call */
|
|
Packit Service |
7203c3 |
0, /* tp_str */
|
|
Packit Service |
7203c3 |
PyObject_GenericGetAttr, /* tp_getattro */
|
|
Packit Service |
7203c3 |
PyObject_GenericSetAttr, /* tp_setattro */
|
|
Packit Service |
7203c3 |
0, /* tp_as_buffer */
|
|
Packit Service |
7203c3 |
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
Packit Service |
7203c3 |
rpmmi_doc, /* tp_doc */
|
|
Packit Service |
7203c3 |
0, /* tp_traverse */
|
|
Packit Service |
7203c3 |
0, /* tp_clear */
|
|
Packit Service |
7203c3 |
0, /* tp_richcompare */
|
|
Packit Service |
7203c3 |
0, /* tp_weaklistoffset */
|
|
Packit Service |
7203c3 |
PyObject_SelfIter, /* tp_iter */
|
|
Packit Service |
7203c3 |
(iternextfunc) rpmmi_iternext, /* tp_iternext */
|
|
Packit Service |
7203c3 |
rpmmi_methods, /* tp_methods */
|
|
Packit Service |
7203c3 |
0, /* tp_members */
|
|
Packit Service |
7203c3 |
0, /* tp_getset */
|
|
Packit Service |
7203c3 |
0, /* tp_base */
|
|
Packit Service |
7203c3 |
0, /* tp_dict */
|
|
Packit Service |
7203c3 |
0, /* tp_descr_get */
|
|
Packit Service |
7203c3 |
0, /* tp_descr_set */
|
|
Packit Service |
7203c3 |
0, /* tp_dictoffset */
|
|
Packit Service |
7203c3 |
0, /* tp_init */
|
|
Packit Service |
7203c3 |
0, /* tp_alloc */
|
|
Packit Service |
7203c3 |
0, /* tp_new */
|
|
Packit Service |
7203c3 |
0, /* tp_free */
|
|
Packit Service |
7203c3 |
0, /* tp_is_gc */
|
|
Packit Service |
7203c3 |
};
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
PyObject * rpmmi_Wrap(PyTypeObject *subtype, rpmdbMatchIterator mi, PyObject *s)
|
|
Packit Service |
7203c3 |
{
|
|
Packit Service |
7203c3 |
rpmmiObject * mio = (rpmmiObject *)subtype->tp_alloc(subtype, 0);
|
|
Packit Service |
7203c3 |
if (mio == NULL) return NULL;
|
|
Packit Service |
7203c3 |
|
|
Packit Service |
7203c3 |
mio->mi = mi;
|
|
Packit Service |
7203c3 |
mio->ref = s;
|
|
Packit Service |
7203c3 |
Py_INCREF(mio->ref);
|
|
Packit Service |
7203c3 |
return (PyObject *) mio;
|
|
Packit Service |
7203c3 |
}
|
|
Packit Service |
7203c3 |
|