rpm  4.5
rpmal-py.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include <rpmlib.h>
8 
9 #include "rpmal-py.h"
10 #include "rpmds-py.h"
11 #include "rpmfi-py.h"
12 
13 #include "debug.h"
14 
15 /*@null@*/
16 static PyObject *
17 rpmal_Debug(/*@unused@*/ rpmalObject * s, PyObject * args, PyObject * kwds)
18  /*@globals _Py_NoneStruct @*/
19  /*@modifies _Py_NoneStruct @*/
20 {
21  char * kwlist[] = {"debugLevel", NULL};
22 
23  if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmal_debug))
24  return NULL;
25 
26  Py_INCREF(Py_None);
27  return Py_None;
28 }
29 
30 /*@null@*/
31 static PyObject *
32 rpmal_Add(rpmalObject * s, PyObject * args, PyObject * kwds)
33  /*@modifies s @*/
34 {
35  rpmdsObject * dso;
36  rpmfiObject * fio;
37  PyObject * key;
38  alKey pkgKey;
39  char * kwlist[] = {"packageKey", "key", "dso", "fileInfo", NULL};
40 
41  if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:Add", kwlist,
42  &pkgKey, &key, &rpmds_Type, &dso, &rpmfi_Type, &fio))
43  return NULL;
44 
45  /* XXX errors */
46  /* XXX transaction colors */
47  pkgKey = rpmalAdd(&s->al, pkgKey, key, dso->ds, fio->fi, 0);
48 
49  return Py_BuildValue("i", pkgKey);
50 }
51 
52 /*@null@*/
53 static PyObject *
54 rpmal_Del(rpmalObject * s, PyObject * args, PyObject * kwds)
55  /*@globals _Py_NoneStruct @*/
56  /*@modifies s, _Py_NoneStruct @*/
57 {
58  alKey pkgKey;
59  char * kwlist[] = {"key", NULL};
60 
61  if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Del", kwlist, &pkgKey))
62  return NULL;
63 
64  rpmalDel(s->al, pkgKey);
65 
66  Py_INCREF(Py_None);
67  return Py_None;
68 }
69 
70 /*@null@*/
71 static PyObject *
72 rpmal_AddProvides(rpmalObject * s, PyObject * args, PyObject * kwds)
73  /*@globals _Py_NoneStruct @*/
74  /*@modifies s, _Py_NoneStruct @*/
75 {
76  rpmdsObject * dso;
77  alKey pkgKey;
78  char * kwlist[] = {"index", "packageIndex", "dso", NULL};
79 
80  /* XXX: why is there an argument listed in the format string that
81  * isn't handled? Is that for transaction color? */
82  if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:AddProvides", kwlist,
83  &pkgKey, &rpmds_Type, &dso))
84  return NULL;
85 
86  /* XXX transaction colors */
87  rpmalAddProvides(s->al, pkgKey, dso->ds, 0);
88 
89  Py_INCREF(Py_None);
90  return Py_None;
91 }
92 
93 /*@null@*/
94 static PyObject *
96  /*@globals _Py_NoneStruct @*/
97  /*@modifies s, _Py_NoneStruct @*/
98 {
99  rpmalMakeIndex(s->al);
100 
101  Py_INCREF(Py_None);
102  return Py_None;
103 }
104 
105 /*@-fullinitblock@*/
106 /*@unchecked@*/ /*@observer@*/
107 static struct PyMethodDef rpmal_methods[] = {
108  {"Debug", (PyCFunction)rpmal_Debug, METH_VARARGS|METH_KEYWORDS,
109  NULL},
110  {"add", (PyCFunction)rpmal_Add, METH_VARARGS|METH_KEYWORDS,
111  NULL},
112  {"delete", (PyCFunction)rpmal_Del, METH_VARARGS|METH_KEYWORDS,
113  NULL},
114  {"addProvides",(PyCFunction)rpmal_AddProvides, METH_VARARGS|METH_KEYWORDS,
115  NULL},
116  {"makeIndex",(PyCFunction)rpmal_MakeIndex, METH_NOARGS,
117  NULL},
118  {NULL, NULL } /* sentinel */
119 };
120 /*@=fullinitblock@*/
121 
122 /* ---------- */
123 
124 static void
126  /*@modifies s @*/
127 {
128  if (s) {
129  s->al = rpmalFree(s->al);
130  PyObject_Del(s);
131  }
132 }
133 
134 static PyObject * rpmal_getattro(PyObject * o, PyObject * n)
135  /*@*/
136 {
137  return PyObject_GenericGetAttr(o, n);
138 }
139 
140 static int rpmal_setattro(PyObject * o, PyObject * n, PyObject * v)
141  /*@*/
142 {
143  return PyObject_GenericSetAttr(o, n, v);
144 }
145 
148 /*@unchecked@*/ /*@observer@*/
149 static char rpmal_doc[] =
150 "";
151 
152 /*@-fullinitblock@*/
153 /*@unchecked@*/
154 PyTypeObject rpmal_Type = {
155  PyObject_HEAD_INIT(&PyType_Type)
156  0, /* ob_size */
157  "rpm.al", /* tp_name */
158  sizeof(rpmalObject), /* tp_basicsize */
159  0, /* tp_itemsize */
160  /* methods */
161  (destructor) rpmal_dealloc, /* tp_dealloc */
162  (printfunc)0, /* tp_print */
163  (getattrfunc)0, /* tp_getattr */
164  (setattrfunc)0, /* tp_setattr */
165  (cmpfunc)0, /* tp_compare */
166  (reprfunc)0, /* tp_repr */
167  0, /* tp_as_number */
168  0, /* tp_as_sequence */
169  0, /* tp_as_mapping */
170  (hashfunc)0, /* tp_hash */
171  (ternaryfunc)0, /* tp_call */
172  (reprfunc)0, /* tp_str */
173  (getattrofunc) rpmal_getattro, /* tp_getattro */
174  (setattrofunc) rpmal_setattro, /* tp_setattro */
175  0, /* tp_as_buffer */
176  Py_TPFLAGS_DEFAULT, /* tp_flags */
177  rpmal_doc, /* tp_doc */
178 #if Py_TPFLAGS_HAVE_ITER
179  0, /* tp_traverse */
180  0, /* tp_clear */
181  0, /* tp_richcompare */
182  0, /* tp_weaklistoffset */
183  (getiterfunc)0, /* tp_iter */
184  (iternextfunc)0, /* tp_iternext */
185  rpmal_methods, /* tp_methods */
186  0, /* tp_members */
187  0, /* tp_getset */
188  0, /* tp_base */
189  0, /* tp_dict */
190  0, /* tp_descr_get */
191  0, /* tp_descr_set */
192  0, /* tp_dictoffset */
193  0, /* tp_init */
194  0, /* tp_alloc */
195  0, /* tp_new */
196  0, /* tp_free */
197  0, /* tp_is_gc */
198 #endif
199 };
200 /*@=fullinitblock@*/
201 
202 /* ---------- */
203 
204 rpmalObject *
206 {
207  rpmalObject *s = PyObject_New(rpmalObject, &rpmal_Type);
208  if (s == NULL)
209  return NULL;
210  s->al = al;
211  return s;
212 }