diff options
author | jbj <devnull@localhost> | 2004-10-12 00:13:22 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2004-10-12 00:13:22 +0000 |
commit | b576fa4259ff43d09fb56a9bb78f81dd13b8e148 (patch) | |
tree | 39f306a450debe76da8e209796121aac743af82b /python | |
parent | 12ccd4fb2feb43f81ec6db27e38e8a04778f4c3f (diff) | |
download | librpm-tizen-b576fa4259ff43d09fb56a9bb78f81dd13b8e148.tar.gz librpm-tizen-b576fa4259ff43d09fb56a9bb78f81dd13b8e148.tar.bz2 librpm-tizen-b576fa4259ff43d09fb56a9bb78f81dd13b8e148.zip |
rpmps framework created.
CVS patchset: 7450
CVS date: 2004/10/12 00:13:22
Diffstat (limited to 'python')
-rw-r--r-- | python/Makefile.am | 11 | ||||
-rw-r--r-- | python/rpmdebug-py.c | 2 | ||||
-rw-r--r-- | python/rpmmodule.c | 6 | ||||
-rw-r--r-- | python/rpmps-py.c | 222 | ||||
-rw-r--r-- | python/rpmps-py.h | 26 |
5 files changed, 263 insertions, 4 deletions
diff --git a/python/Makefile.am b/python/Makefile.am index 5c0aa385b..e4914848a 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -24,7 +24,8 @@ INCLUDES = -I. \ noinst_HEADERS = header-py.h \ rpmal-py.h rpmds-py.h rpmdb-py.h rpmfd-py.h rpmfts-py.h \ - rpmfi-py.h rpmmi-py.h rpmrc-py.h rpmte-py.h rpmts-py.h spec-py.h + rpmfi-py.h rpmmi-py.h rpmps-py.h rpmrc-py.h rpmte-py.h rpmts-py.h \ + spec-py.h mylibs= \ $(top_builddir)/lib/librpm.la \ @@ -53,15 +54,17 @@ poptmodule_la_LDFLAGS = $(mylibs) $(LIBS) -module -avoid-version rpmmodule_la_SOURCES = rpmmodule.c header-py.c \ rpmal-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ - rpmfi-py.c rpmmi-py.c rpmrc-py.c rpmte-py.c rpmts-py.c spec-py.c + rpmfi-py.c rpmmi-py.c rpmps-py.c rpmrc-py.c rpmte-py.c \ + rpmts-py.c spec-py.c # rpmmodule.c header-py.c \ # rpmal-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfi-py.c rpmmi-py.c \ -# rpmrc-py.c rpmte-py.c rpmts-py.c +# rpmps-py.c rpmrc-py.c rpmte-py.c rpmts-py.c # rpmmodule.c header-py.c splint_srcs = \ rpmal-py.c rpmds-py.c rpmdb-py.c rpmfd-py.c rpmfts-py.c \ - rpmfi-py.c rpmmi-py.c rpmrc-py.c rpmte-py.c rpmts-py.c spec-py.c + rpmfi-py.c rpmmi-py.c rpmps-py.c rpmrc-py.c rpmte-py.c rpmts-py.c \ + spec-py.c .PHONY: lint lint: diff --git a/python/rpmdebug-py.c b/python/rpmdebug-py.c index 9849dd5ac..d45bfc535 100644 --- a/python/rpmdebug-py.c +++ b/python/rpmdebug-py.c @@ -15,6 +15,7 @@ extern PyTypeObject PyFrame_Type; #include "rpmfi-py.h" /* XXX debug only */ #include "rpmfts-py.h" /* XXX debug only */ #include "rpmmi-py.h" /* XXX debug only */ +#include "rpmps-py.h" /* XXX debug only */ #include "rpmrc-py.h" /* XXX debug only */ #include "rpmte-py.h" /* XXX debug only */ #include "rpmts-py.h" /* XXX debug only */ @@ -75,6 +76,7 @@ static const char * lbl(void * s) if (o->ob_type == &rpmfi_Type) return "rpmfi"; if (o->ob_type == &rpmfts_Type) return "rpmfts"; if (o->ob_type == &rpmmi_Type) return "rpmmi"; + if (o->ob_type == &rpmps_Type) return "rpmps"; if (o->ob_type == &rpmrc_Type) return "rpmrc"; if (o->ob_type == &rpmte_Type) return "rpmte"; if (o->ob_type == &rpmts_Type) return "rpmts"; diff --git a/python/rpmmodule.c b/python/rpmmodule.c index f72f5df7d..8ea54fa9f 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -19,6 +19,7 @@ #include "rpmfts-py.h" #include "rpmfi-py.h" #include "rpmmi-py.h" +#include "rpmps-py.h" #include "rpmrc-py.h" #include "rpmte-py.h" #include "rpmts-py.h" @@ -186,6 +187,7 @@ void initrpm(void) if (PyType_Ready(&rpmfts_Type) < 0) return; if (PyType_Ready(&rpmfi_Type) < 0) return; if (PyType_Ready(&rpmmi_Type) < 0) return; + if (PyType_Ready(&rpmps_Type) < 0) return; rpmrc_Type.tp_base = &PyDict_Type; if (PyType_Ready(&rpmrc_Type) < 0) return; @@ -235,6 +237,9 @@ void initrpm(void) Py_INCREF(&rpmmi_Type); PyModule_AddObject(m, "mi", (PyObject *) &rpmmi_Type); + Py_INCREF(&rpmps_Type); + PyModule_AddObject(m, "ps", (PyObject *) &rpmps_Type); + Py_INCREF(&rpmrc_Type); PyModule_AddObject(m, "rc", (PyObject *) &rpmrc_Type); @@ -254,6 +259,7 @@ void initrpm(void) rpmfts_Type.ob_type = &PyType_Type; rpmfi_Type.ob_type = &PyType_Type; rpmmi_Type.ob_type = &PyType_Type; + rpmps_Type.ob_type = &PyType_Type; rpmte_Type.ob_type = &PyType_Type; rpmts_Type.ob_type = &PyType_Type; spec_Type.ob_type = &PyType_Type; diff --git a/python/rpmps-py.c b/python/rpmps-py.c new file mode 100644 index 000000000..7b45d9805 --- /dev/null +++ b/python/rpmps-py.c @@ -0,0 +1,222 @@ +/** \ingroup py_c + * \file python/rpmps-py.c + */ + +#include "system.h" + +#include <rpmlib.h> + +#include "header-py.h" +#include "rpmps-py.h" + +#include "debug.h" + +/*@access rpmps @*/ + +/*@null@*/ +static PyObject * +rpmps_Debug(/*@unused@*/ rpmpsObject * s, PyObject * args) + /*@globals _Py_NoneStruct @*/ + /*@modifies _Py_NoneStruct @*/ +{ + if (!PyArg_ParseTuple(args, "i", &_rpmps_debug)) return NULL; + Py_INCREF(Py_None); + return Py_None; +} + +/*@null@*/ +static PyObject * +rpmps_NumProblems(rpmpsObject * s, PyObject * args) + /*@*/ +{ + if (!PyArg_ParseTuple(args, ":NumProblems")) return NULL; + return Py_BuildValue("i", rpmpsNumProblems(s->ps)); +} + +static PyObject * +rpmps_iter(rpmpsObject * s) + /*@*/ +{ + Py_INCREF(s); + return (PyObject *)s; +} + +/*@null@*/ +static PyObject * +rpmps_iternext(rpmpsObject * s) + /*@globals _Py_NoneStruct @*/ + /*@modifies s, _Py_NoneStruct @*/ +{ + PyObject * result = NULL; + + /* Reset loop indices on 1st entry. */ + if (!s->active) { + s->ix = -1; + s->active = 1; + } + + /* If more to do, return a problem set tuple. */ + s->ix++; + if (s->ix < s->ps->numProblems) { + /* TODO */ + result = Py_BuildValue("i", s->ix); + } else { + s->active = 0; + } + + return result; +} + +/*@null@*/ +static PyObject * +rpmps_Next(rpmpsObject * s, PyObject *args) + /*@globals _Py_NoneStruct @*/ + /*@modifies s, _Py_NoneStruct @*/ +{ + PyObject * result; + + if (!PyArg_ParseTuple(args, ":Next")) + return NULL; + + result = rpmps_iternext(s); + + if (result == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + return result; +} + +/*@-fullinitblock@*/ +/*@unchecked@*/ /*@observer@*/ +static struct PyMethodDef rpmps_methods[] = { + {"Debug", (PyCFunction)rpmps_Debug, METH_VARARGS, + NULL}, + {"NumProblems",(PyCFunction)rpmps_NumProblems, METH_VARARGS, + "ps.NumProblems -> NumProblems - Return no. of elements.\n" }, + {NULL, NULL} /* sentinel */ +}; +/*@=fullinitblock@*/ + +/* ---------- */ + +static void +rpmps_dealloc(rpmpsObject * s) + /*@modifies s @*/ +{ + if (s) { + s->ps = rpmpsFree(s->ps); + PyObject_Del(s); + } +} + +static int +rpmps_print(rpmpsObject * s, FILE * fp, /*@unused@*/ int flags) + /*@globals fileSystem @*/ + /*@modifies s, fp, fileSystem @*/ +{ + if (!(s && s->ps)) + return -1; + + for (s->ix = 0; s->ix < rpmpsNumProblems(s->ps); s->ix++) { + fprintf(fp, "%d\n", s->ix); /* TODO */ + } + return 0; +} + +static PyObject * rpmps_getattro(PyObject * o, PyObject * n) + /*@*/ +{ + return PyObject_GenericGetAttr(o, n); +} + +static int rpmps_setattro(PyObject * o, PyObject * n, PyObject * v) + /*@*/ +{ + return PyObject_GenericSetAttr(o, n, v); +} + +static int +rpmps_length(rpmpsObject * s) + /*@*/ +{ + return rpmpsNumProblems(s->ps); +} + +/*@null@*/ +static PyObject * +rpmps_subscript(rpmpsObject * s, PyObject * key) + /*@modifies s @*/ +{ + if (!PyInt_Check(key)) { + PyErr_SetString(PyExc_TypeError, "integer expected"); + return NULL; + } + + s->ix = (int) PyInt_AsLong(key); + /* TODO */ + return Py_BuildValue("i", s->ix); +} + +static PyMappingMethods rpmps_as_mapping = { + (inquiry) rpmps_length, /* mp_length */ + (binaryfunc) rpmps_subscript, /* mp_subscript */ + (objobjargproc)0, /* mp_ass_subscript */ +}; + +/** + */ +/*@unchecked@*/ /*@observer@*/ +static char rpmps_doc[] = +""; + +/*@-fullinitblock@*/ +PyTypeObject rpmps_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /* ob_size */ + "rpm.ps", /* tp_name */ + sizeof(rpmpsObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor) rpmps_dealloc, /* tp_dealloc */ + (printfunc) rpmps_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)0, /* tp_compare */ + (reprfunc)0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + &rpmps_as_mapping, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)0, /* tp_str */ + (getattrofunc) rpmps_getattro, /* tp_getattro */ + (setattrofunc) rpmps_setattro, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + rpmps_doc, /* tp_doc */ +#if Py_TPFLAGS_HAVE_ITER + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) rpmps_iter, /* tp_iter */ + (iternextfunc) rpmps_iternext, /* tp_iternext */ + rpmps_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ +#endif +}; +/*@=fullinitblock@*/ + +/* ---------- */ diff --git a/python/rpmps-py.h b/python/rpmps-py.h new file mode 100644 index 000000000..18c19ed9e --- /dev/null +++ b/python/rpmps-py.h @@ -0,0 +1,26 @@ +#ifndef H_RPMPS_PY +#define H_RPMPS_PY + +#include "rpmps.h" + +/** \ingroup py_c + * \file python/rpmps-py.h + */ + +/** + */ +typedef struct rpmpsObject_s { + PyObject_HEAD + PyObject *md_dict; /*!< to look like PyModuleObject */ + int active; + int ix; +/*@null@*/ + rpmps ps; +} rpmpsObject; + +/** + */ +/*@unchecked@*/ +extern PyTypeObject rpmps_Type; + +#endif |