-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpmte-py.c
405 lines (357 loc) · 9.93 KB
/
rpmte-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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/** \ingroup py_c
* \file python/rpmte-py.c
*/
#include "system-py.h"
#include <rpmio.h>
#include <rpmiotypes.h> /* XXX fnpyKey */
#include <rpmtypes.h>
#include <rpmtag.h>
#include "header-py.h" /* XXX tagNumFromPyObject */
#include "rpmds-py.h"
#include "rpmfi-py.h"
#define _RPMTE_INTERNAL /* XXX rpmteAddedKey */
#include "rpmte-py.h"
#include "debug.h"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#endif
/** \ingroup python
* \name Class: Rpmte
* \class Rpmte
* \brief An python rpm.te object represents an element of a transaction set.
*
* Elements of a transaction set are accessible after being added. Each
* element carries descriptive information about the added element as well
* as a file info set and dependency sets for each of the 4 types of dependency.
*
* The rpmte class contains the following methods:
*
* - te.Type() Return transaction element type (TR_ADDED|TR_REMOVED).
* - te.N() Return package name.
* - te.E() Return package epoch.
* - te.V() Return package version.
* - te.R() Return package release.
* - te.A() Return package architecture.
* - te.O() Return package operating system.
* - te.NEVR() Return package name-version-release.
* - te.NEVRA() Return package name-version-release.arch.
* - te.Pkgid() Return package identifier (header+payload md5 digest).
* - te.Hdrid() Return package header identifier (header sha1 digest).
* - te.Color() Return package color bits.
* - te.PkgFileSize() Return no. of bytes in package file.
* - te.Breadth() Return element breadth index.
* - te.Depth() Return element depth index.
* - te.Npreds() Return the number of package prerequisites.
* - te.Degree() Return the parent's degree + 1.
* - te.Parent() Return the parent element index.
* - te.Tree() Return the root dependency tree index.
* - te.AddedKey() Return the added package index.
* - te.DBOffset() Return the Packages database instance number (TR_REMOVED)
* - te.Key() Return the associated opaque key, i.e. 2nd arg to ts.addInstall().
* - te.DS(tag) Return package dependency set.
* @param tag 'Providename', 'Requirename', 'Obsoletename', 'Conflictname'
* - te.FI(tag) Return package file info set.
* @param tag 'Basenames'
*/
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
struct rpmteObject_s {
PyObject_HEAD
PyObject *md_dict; /*!< to look like PyModuleObject */
rpmte te;
};
/** \ingroup python
* \name Class: Rpmte
*/
/*@{*/
static PyObject *
rpmte_Debug(rpmteObject * s, PyObject * args,
PyObject * kwds)
{
char * kwlist[] = {"debugLevel", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmte_debug))
return NULL;
Py_RETURN_NONE;
}
static PyObject *
rpmte_TEType(rpmteObject * s)
{
return Py_BuildValue("i", rpmteType(s->te));
}
static PyObject *
rpmte_N(rpmteObject * s)
{
return Py_BuildValue("s", rpmteN(s->te));
}
static PyObject *
rpmte_E(rpmteObject * s)
{
return Py_BuildValue("s", rpmteE(s->te));
}
static PyObject *
rpmte_V(rpmteObject * s)
{
return Py_BuildValue("s", rpmteV(s->te));
}
static PyObject *
rpmte_R(rpmteObject * s)
{
return Py_BuildValue("s", rpmteR(s->te));
}
#if defined(RPM_VENDOR_MANDRIVA)
static PyObject *
rpmte_D(rpmteObject * s)
{
return Py_BuildValue("s", rpmteD(s->te));
}
#endif
static PyObject *
rpmte_A(rpmteObject * s)
{
return Py_BuildValue("s", rpmteA(s->te));
}
static PyObject *
rpmte_O(rpmteObject * s)
{
return Py_BuildValue("s", rpmteO(s->te));
}
static PyObject *
rpmte_NEVR(rpmteObject * s)
{
return Py_BuildValue("s", rpmteNEVR(s->te));
}
static PyObject *
rpmte_NEVRA(rpmteObject * s)
{
return Py_BuildValue("s", rpmteNEVRA(s->te));
}
static PyObject *
rpmte_Pkgid(rpmteObject * s)
{
return Py_BuildValue("s", rpmtePkgid(s->te));
}
static PyObject *
rpmte_Hdrid(rpmteObject * s)
{
return Py_BuildValue("s", rpmteHdrid(s->te));
}
static PyObject *
rpmte_Color(rpmteObject * s)
{
return Py_BuildValue("i", rpmteColor(s->te));
}
static PyObject *
rpmte_PkgFileSize(rpmteObject * s)
{
return Py_BuildValue("L", rpmtePkgFileSize(s->te));
}
static PyObject *
rpmte_Breadth(rpmteObject * s)
{
return Py_BuildValue("i", rpmteBreadth(s->te));
}
static PyObject *
rpmte_Depth(rpmteObject * s)
{
return Py_BuildValue("i", rpmteDepth(s->te));
}
static PyObject *
rpmte_Npreds(rpmteObject * s)
{
return Py_BuildValue("i", rpmteNpreds(s->te));
}
static PyObject *
rpmte_Degree(rpmteObject * s)
{
return Py_BuildValue("i", rpmteDegree(s->te));
}
static PyObject *
rpmte_Parent(rpmteObject * s)
{
return Py_BuildValue("i", rpmteParent(s->te));
}
static PyObject *
rpmte_Tree(rpmteObject * s)
{
return Py_BuildValue("i", rpmteTree(s->te));
}
static PyObject *
rpmte_AddedKey(rpmteObject * s)
{
return Py_BuildValue("i", rpmteAddedKey(s->te));
}
static PyObject *
rpmte_DBOffset(rpmteObject * s)
{
return Py_BuildValue("i", rpmteDBOffset(s->te));
}
static PyObject *
rpmte_Key(rpmteObject * s)
{
PyObject * Key;
/* XXX how to insure that returned Key is a PyObject??? */
Key = (PyObject *) rpmteKey(s->te);
if (Key == NULL)
Key = Py_None;
Py_INCREF(Key);
return Key;
}
static PyObject *
rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
{
rpmds ds;
rpmTag tag;
char * kwlist[] = {"tag", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:DS", kwlist,
tagNumFromPyObject, &tag))
return NULL;
ds = rpmteDS(s->te, tag);
if (ds == NULL) {
Py_RETURN_NONE;
}
return rpmds_Wrap(&rpmds_Type, rpmdsLink(ds, "rpmte_DS"));
}
static PyObject *
rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
{
rpmfi fi;
rpmTag tag;
char * kwlist[] = {"tag", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:FI", kwlist,
tagNumFromPyObject, &tag))
return NULL;
fi = rpmteFI(s->te, tag);
if (fi == NULL) {
Py_RETURN_NONE;
}
return rpmfi_Wrap(&rpmfi_Type, rpmfiLink(fi, "rpmte_FI"));
}
/*@}*/
static struct PyMethodDef rpmte_methods[] = {
{"Debug", (PyCFunction)rpmte_Debug, METH_VARARGS|METH_KEYWORDS,
NULL},
{"Type", (PyCFunction)rpmte_TEType, METH_NOARGS,
"te.Type() -> Type\n\
- Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
{"N", (PyCFunction)rpmte_N, METH_NOARGS,
"te.N() -> N\n\
- Return element name.\n" },
{"E", (PyCFunction)rpmte_E, METH_NOARGS,
"te.E() -> E\n\
- Return element epoch.\n" },
{"V", (PyCFunction)rpmte_V, METH_NOARGS,
"te.V() -> V\n\
- Return element version.\n" },
{"R", (PyCFunction)rpmte_R, METH_NOARGS,
"te.R() -> R\n\
- Return element release.\n" },
#if defined(RPM_VENDOR_MANDRIVA)
{"D", (PyCFunction)rpmte_D, METH_NOARGS,
"te.D() -> D\n\
- Return element distepoch.\n" },
#endif
{"A", (PyCFunction)rpmte_A, METH_NOARGS,
"te.A() -> A\n\
- Return element arch.\n" },
{"O", (PyCFunction)rpmte_O, METH_NOARGS,
"te.O() -> O\n\
- Return element os.\n" },
{"NEVR", (PyCFunction)rpmte_NEVR, METH_NOARGS,
"te.NEVR() -> NEVR\n\
- Return element name-[epoch:]version-release.\n" },
{"NEVRA", (PyCFunction)rpmte_NEVRA, METH_NOARGS,
"te.NEVRA() -> NEVRA\n\
- Return element name-[epoch:]version-release.arch.\n" },
{"Pkgid", (PyCFunction)rpmte_Pkgid, METH_NOARGS,
"te.Pkgid() -> Pkgid\n\
- Return element pkgid (header+payload md5 digest).\n" },
{"Hdrid", (PyCFunction)rpmte_Hdrid, METH_NOARGS,
"te.Hdrid() -> Hdrid\n\
- Return element hdrid (header sha1 digest).\n" },
{"Color",(PyCFunction)rpmte_Color, METH_NOARGS,
NULL},
{"PkgFileSize",(PyCFunction)rpmte_PkgFileSize, METH_NOARGS,
NULL},
{"Breadth", (PyCFunction)rpmte_Breadth, METH_NOARGS,
"te.Breadth() -> transaction element breadth index.\n" },
{"Depth", (PyCFunction)rpmte_Depth, METH_NOARGS,
"te.Depth() -> transaction element depth index.\n" },
{"Npreds", (PyCFunction)rpmte_Npreds, METH_NOARGS,
NULL},
{"Degree", (PyCFunction)rpmte_Degree, METH_NOARGS,
NULL},
{"Parent", (PyCFunction)rpmte_Parent, METH_NOARGS,
NULL},
{"Tree", (PyCFunction)rpmte_Tree, METH_NOARGS,
NULL},
{"AddedKey",(PyCFunction)rpmte_AddedKey, METH_NOARGS,
NULL},
{"DBOffset",(PyCFunction)rpmte_DBOffset, METH_NOARGS,
NULL},
{"Key", (PyCFunction)rpmte_Key, METH_NOARGS,
NULL},
{"DS", (PyCFunction)rpmte_DS, METH_VARARGS|METH_KEYWORDS,
"te.DS(TagN) -> DS\n\
- Return the TagN dependency set (or None). TagN is one of\n\
'Providename', 'Requirename', 'Obsoletename', 'Conflictname'\n" },
{"FI", (PyCFunction)rpmte_FI, METH_VARARGS|METH_KEYWORDS,
"te.FI(TagN) -> FI\n\
- Return the TagN dependency set (or None). TagN must be 'Basenames'.\n" },
{NULL, NULL} /* sentinel */
};
/* ---------- */
static char rpmte_doc[] =
"";
PyTypeObject rpmte_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"rpm.te", /* tp_name */
sizeof(rpmteObject), /* tp_size */
0, /* tp_itemsize */
(destructor)0, /* tp_dealloc */
0, /* tp_print */
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
rpmte_doc, /* tp_doc */
#if Py_TPFLAGS_HAVE_ITER
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
rpmte_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 * rpmte_Wrap(PyTypeObject *subtype, rpmte te)
{
rpmteObject *s = (rpmteObject *) subtype->tp_alloc(subtype, 0);
if (s == NULL) return NULL;
s->te = te;
return (PyObject *) s;
}