-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpmal-py.c
167 lines (141 loc) · 3.87 KB
/
rpmal-py.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/** \ingroup py_c
* \file python/rpmal-py.c
*/
#include "system-py.h"
#include <rpmio.h> /* XXX rpmRC returns */
#include <rpmiotypes.h> /* XXX fnpyKey */
#include <rpmtypes.h>
#include <rpmtag.h>
#include "rpmal-py.h"
#include "rpmds-py.h"
#include "rpmfi-py.h"
#include "debug.h"
struct rpmalObject_s {
PyObject_HEAD
PyObject *md_dict; /*!< to look like PyModuleObject */
rpmal al;
};
static PyObject *
rpmal_Add(rpmalObject * s, PyObject * args, PyObject * kwds)
{
rpmdsObject * dso;
rpmfiObject * fio;
PyObject * key;
alKey pkgKey;
char * kwlist[] = {"packageKey", "key", "dso", "fileInfo", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:Add", kwlist,
&pkgKey, &key, &rpmds_Type, &dso, &rpmfi_Type, &fio))
return NULL;
/* XXX errors */
/* XXX transaction colors */
pkgKey = rpmalAdd(&s->al, pkgKey, key, dsFromDs(dso), fiFromFi(fio), 0);
return Py_BuildValue("i", pkgKey);
}
static PyObject *
rpmal_Del(rpmalObject * s, PyObject * args, PyObject * kwds)
{
alKey pkgKey;
char * kwlist[] = {"key", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Del", kwlist, &pkgKey))
return NULL;
rpmalDel(s->al, pkgKey);
Py_RETURN_NONE;
}
static PyObject *
rpmal_AddProvides(rpmalObject * s, PyObject * args, PyObject * kwds)
{
rpmdsObject * dso;
alKey pkgKey;
char * kwlist[] = {"index", "packageIndex", "dso", NULL};
/* XXX: why is there an argument listed in the format string that
* isn't handled? Is that for transaction color? */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:AddProvides", kwlist,
&pkgKey, &rpmds_Type, &dso))
return NULL;
/* XXX transaction colors */
rpmalAddProvides(s->al, pkgKey, dsFromDs(dso), 0);
Py_RETURN_NONE;
}
static PyObject *
rpmal_MakeIndex(rpmalObject * s)
{
rpmalMakeIndex(s->al);
Py_RETURN_NONE;
}
static struct PyMethodDef rpmal_methods[] = {
{"add", (PyCFunction)rpmal_Add, METH_VARARGS|METH_KEYWORDS,
NULL},
{"delete", (PyCFunction)rpmal_Del, METH_VARARGS|METH_KEYWORDS,
NULL},
{"addProvides",(PyCFunction)rpmal_AddProvides, METH_VARARGS|METH_KEYWORDS,
NULL},
{"makeIndex",(PyCFunction)rpmal_MakeIndex, METH_NOARGS,
NULL},
{NULL, NULL } /* sentinel */
};
/* ---------- */
static void
rpmal_dealloc(rpmalObject * s)
{
if (s) {
s->al = rpmalFree(s->al);
Py_TYPE(s)->tp_free((PyObject *)s);
}
}
static char rpmal_doc[] =
"";
PyTypeObject rpmal_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"rpm.al", /* tp_name */
sizeof(rpmalObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor) rpmal_dealloc, /* tp_dealloc */
(printfunc)0, /* 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 */
0, /* tp_as_mapping */
(hashfunc)0, /* tp_hash */
(ternaryfunc)0, /* tp_call */
(reprfunc)0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
rpmal_doc, /* tp_doc */
#if Py_TPFLAGS_HAVE_ITER
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
(getiterfunc)0, /* tp_iter */
(iternextfunc)0, /* tp_iternext */
rpmal_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
};
/* ---------- */
PyObject *
rpmal_Wrap(PyTypeObject *subtype, rpmal al)
{
rpmalObject *s = (rpmalObject *) subtype->tp_alloc(subtype, 0);
if (s == NULL)
return NULL;
s->al = al;
return (PyObject *) s;
}