python/rpmal-py.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmlib.h>
00008 
00009 #include "rpmal-py.h"
00010 #include "rpmds-py.h"
00011 #include "rpmfi-py.h"
00012 
00013 #include "debug.h"
00014 
00015 /*@null@*/
00016 static PyObject *
00017 rpmal_Debug(/*@unused@*/ rpmalObject * s, PyObject * args, PyObject * kwds)
00018         /*@globals _Py_NoneStruct @*/
00019         /*@modifies _Py_NoneStruct @*/
00020 {
00021     char * kwlist[] = {"debugLevel", NULL};
00022 
00023     if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmal_debug))
00024         return NULL;
00025 
00026     Py_INCREF(Py_None);
00027     return Py_None;
00028 }
00029 
00030 /*@null@*/
00031 static PyObject *
00032 rpmal_Add(rpmalObject * s, PyObject * args, PyObject * kwds)
00033         /*@modifies s @*/
00034 {
00035     rpmdsObject * dso;
00036     rpmfiObject * fio;
00037     PyObject * key;
00038     alKey pkgKey;
00039     char * kwlist[] = {"packageKey", "key", "dso", "fileInfo", NULL};
00040 
00041     if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:Add", kwlist,
00042             &pkgKey, &key, &rpmds_Type, &dso, &rpmfi_Type, &fio))
00043         return NULL;
00044 
00045     /* XXX errors */
00046     /* XXX transaction colors */
00047     pkgKey = rpmalAdd(&s->al, pkgKey, key, dso->ds, fio->fi, 0);
00048 
00049     return Py_BuildValue("i", pkgKey);
00050 }
00051 
00052 /*@null@*/
00053 static PyObject *
00054 rpmal_Del(rpmalObject * s, PyObject * args, PyObject * kwds)
00055         /*@globals _Py_NoneStruct @*/
00056         /*@modifies s, _Py_NoneStruct @*/
00057 {
00058     alKey pkgKey;
00059     char * kwlist[] = {"key", NULL};
00060 
00061     if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Del", kwlist, &pkgKey))
00062         return NULL;
00063 
00064     rpmalDel(s->al, pkgKey);
00065 
00066     Py_INCREF(Py_None);
00067     return Py_None;
00068 }
00069 
00070 /*@null@*/
00071 static PyObject *
00072 rpmal_AddProvides(rpmalObject * s, PyObject * args, PyObject * kwds)
00073         /*@globals _Py_NoneStruct @*/
00074         /*@modifies s, _Py_NoneStruct @*/
00075 {
00076     rpmdsObject * dso;
00077     alKey pkgKey;
00078     char * kwlist[] = {"index", "packageIndex", "dso", NULL};
00079 
00080     /* XXX: why is there an argument listed in the format string that
00081      *      isn't handled?  Is that for transaction color? */
00082     if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:AddProvides", kwlist,
00083             &pkgKey, &rpmds_Type, &dso))
00084         return NULL;
00085 
00086     /* XXX transaction colors */
00087     rpmalAddProvides(s->al, pkgKey, dso->ds, 0);
00088 
00089     Py_INCREF(Py_None);
00090     return Py_None;
00091 }
00092 
00093 /*@null@*/
00094 static PyObject *
00095 rpmal_MakeIndex(rpmalObject * s)
00096         /*@globals _Py_NoneStruct @*/
00097         /*@modifies s, _Py_NoneStruct @*/
00098 {
00099     rpmalMakeIndex(s->al);
00100 
00101     Py_INCREF(Py_None);
00102     return Py_None;
00103 }
00104 
00105 /*@-fullinitblock@*/
00106 /*@unchecked@*/ /*@observer@*/
00107 static struct PyMethodDef rpmal_methods[] = {
00108  {"Debug",      (PyCFunction)rpmal_Debug,       METH_VARARGS|METH_KEYWORDS,
00109         NULL},
00110  {"add",        (PyCFunction)rpmal_Add,         METH_VARARGS|METH_KEYWORDS,
00111         NULL},
00112  {"delete",     (PyCFunction)rpmal_Del,         METH_VARARGS|METH_KEYWORDS,
00113         NULL},
00114  {"addProvides",(PyCFunction)rpmal_AddProvides, METH_VARARGS|METH_KEYWORDS,
00115         NULL},
00116  {"makeIndex",(PyCFunction)rpmal_MakeIndex,     METH_NOARGS,
00117         NULL},
00118  {NULL,         NULL }          /* sentinel */
00119 };
00120 /*@=fullinitblock@*/
00121 
00122 /* ---------- */
00123 
00124 static void
00125 rpmal_dealloc(rpmalObject * s)
00126         /*@modifies s @*/
00127 {
00128     if (s) {
00129         s->al = rpmalFree(s->al);
00130         PyObject_Del(s);
00131     }
00132 }
00133 
00134 static PyObject * rpmal_getattro(PyObject * o, PyObject * n)
00135         /*@*/
00136 {
00137     return PyObject_GenericGetAttr(o, n);
00138 }
00139 
00140 static int rpmal_setattro(PyObject * o, PyObject * n, PyObject * v)
00141         /*@*/
00142 {
00143     return PyObject_GenericSetAttr(o, n, v);
00144 }
00145 
00148 /*@unchecked@*/ /*@observer@*/
00149 static char rpmal_doc[] =
00150 "";
00151 
00152 /*@-fullinitblock@*/
00153 /*@unchecked@*/
00154 PyTypeObject rpmal_Type = {
00155         PyObject_HEAD_INIT(&PyType_Type)
00156         0,                              /* ob_size */
00157         "rpm.al",                       /* tp_name */
00158         sizeof(rpmalObject),            /* tp_basicsize */
00159         0,                              /* tp_itemsize */
00160         /* methods */
00161         (destructor) rpmal_dealloc,     /* tp_dealloc */
00162         (printfunc)0,                   /* tp_print */
00163         (getattrfunc)0,                 /* tp_getattr */
00164         (setattrfunc)0,                 /* tp_setattr */
00165         (cmpfunc)0,                     /* tp_compare */
00166         (reprfunc)0,                    /* tp_repr */
00167         0,                              /* tp_as_number */
00168         0,                              /* tp_as_sequence */
00169         0,                              /* tp_as_mapping */
00170         (hashfunc)0,                    /* tp_hash */
00171         (ternaryfunc)0,                 /* tp_call */
00172         (reprfunc)0,                    /* tp_str */
00173         (getattrofunc) rpmal_getattro,  /* tp_getattro */
00174         (setattrofunc) rpmal_setattro,  /* tp_setattro */
00175         0,                              /* tp_as_buffer */
00176         Py_TPFLAGS_DEFAULT,             /* tp_flags */
00177         rpmal_doc,                      /* tp_doc */
00178 #if Py_TPFLAGS_HAVE_ITER
00179         0,                              /* tp_traverse */
00180         0,                              /* tp_clear */
00181         0,                              /* tp_richcompare */
00182         0,                              /* tp_weaklistoffset */
00183         (getiterfunc)0,                 /* tp_iter */
00184         (iternextfunc)0,                /* tp_iternext */
00185         rpmal_methods,                  /* tp_methods */
00186         0,                              /* tp_members */
00187         0,                              /* tp_getset */
00188         0,                              /* tp_base */
00189         0,                              /* tp_dict */
00190         0,                              /* tp_descr_get */
00191         0,                              /* tp_descr_set */
00192         0,                              /* tp_dictoffset */
00193         0,                              /* tp_init */
00194         0,                              /* tp_alloc */
00195         0,                              /* tp_new */
00196         0,                              /* tp_free */
00197         0,                              /* tp_is_gc */
00198 #endif
00199 };
00200 /*@=fullinitblock@*/
00201 
00202 /* ---------- */
00203 
00204 rpmalObject *
00205 rpmal_Wrap(rpmal al)
00206 {
00207     rpmalObject *s = PyObject_New(rpmalObject, &rpmal_Type);
00208     if (s == NULL)
00209         return NULL;
00210     s->al = al;
00211     return s;
00212 }

Generated on Fri Oct 12 08:44:54 2007 for rpm by  doxygen 1.5.2