rpm  5.4.15
rpmte-py.c
Go to the documentation of this file.
1 
5 #include "system-py.h"
6 
7 #include <rpmio.h>
8 #include <rpmiotypes.h> /* XXX fnpyKey */
9 #include <rpmtypes.h>
10 #include <rpmtag.h>
11 
12 #include "header-py.h" /* XXX tagNumFromPyObject */
13 #include "rpmds-py.h"
14 #include "rpmfi-py.h"
15 
16 #define _RPMTE_INTERNAL /* XXX rpmteAddedKey */
17 #include "rpmte-py.h"
18 
19 #include "debug.h"
20 
21 /*@access rpmte @*/
22 /*@access fnpyKey @*/
23 
67 
68 /*@null@*/
69 static PyObject *
70 rpmte_Debug(/*@unused@*/ rpmteObject * s, PyObject * args,
71  PyObject * kwds)
72  /*@globals _Py_NoneStruct @*/
73  /*@modifies _Py_NoneStruct @*/
74 {
75  char * kwlist[] = {"debugLevel", NULL};
76 
77  if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmte_debug))
78  return NULL;
79 
80  Py_RETURN_NONE;
81 }
82 
83 /*@null@*/
84 static PyObject *
86  /*@*/
87 {
88  return Py_BuildValue("i", rpmteType(s->te));
89 }
90 
91 /*@null@*/
92 static PyObject *
94  /*@*/
95 {
96  return Py_BuildValue("s", rpmteN(s->te));
97 }
98 
99 /*@null@*/
100 static PyObject *
102  /*@*/
103 {
104  return Py_BuildValue("s", rpmteE(s->te));
105 }
106 
107 /*@null@*/
108 static PyObject *
110  /*@*/
111 {
112  return Py_BuildValue("s", rpmteV(s->te));
113 }
114 
115 /*@null@*/
116 static PyObject *
118  /*@*/
119 {
120  return Py_BuildValue("s", rpmteR(s->te));
121 }
122 
123 #if defined(RPM_VENDOR_MANDRIVA)
124 /*@null@*/
125 static PyObject *
126 rpmte_D(rpmteObject * s)
127  /*@*/
128 {
129  return Py_BuildValue("s", rpmteD(s->te));
130 }
131 #endif
132 
133 /*@null@*/
134 static PyObject *
136  /*@*/
137 {
138  return Py_BuildValue("s", rpmteA(s->te));
139 }
140 
141 /*@null@*/
142 static PyObject *
144  /*@*/
145 {
146  return Py_BuildValue("s", rpmteO(s->te));
147 }
148 
149 /*@null@*/
150 static PyObject *
152  /*@*/
153 {
154  return Py_BuildValue("s", rpmteNEVR(s->te));
155 }
156 
157 /*@null@*/
158 static PyObject *
160  /*@*/
161 {
162  return Py_BuildValue("s", rpmteNEVRA(s->te));
163 }
164 
165 /*@null@*/
166 static PyObject *
168  /*@*/
169 {
170  return Py_BuildValue("s", rpmtePkgid(s->te));
171 }
172 
173 /*@null@*/
174 static PyObject *
176  /*@*/
177 {
178  return Py_BuildValue("s", rpmteHdrid(s->te));
179 }
180 
181 /*@null@*/
182 static PyObject *
184  /*@*/
185 {
186  return Py_BuildValue("i", rpmteColor(s->te));
187 }
188 
189 /*@null@*/
190 static PyObject *
192  /*@*/
193 {
194  return Py_BuildValue("i", rpmtePkgFileSize(s->te));
195 }
196 
197 /*@null@*/
198 static PyObject *
200  /*@*/
201 {
202  return Py_BuildValue("i", rpmteBreadth(s->te));
203 }
204 
205 /*@null@*/
206 static PyObject *
208  /*@*/
209 {
210  return Py_BuildValue("i", rpmteDepth(s->te));
211 }
212 
213 /*@null@*/
214 static PyObject *
216  /*@*/
217 {
218  return Py_BuildValue("i", rpmteNpreds(s->te));
219 }
220 
221 /*@null@*/
222 static PyObject *
224  /*@*/
225 {
226  return Py_BuildValue("i", rpmteDegree(s->te));
227 }
228 
229 /*@null@*/
230 static PyObject *
232  /*@*/
233 {
234  return Py_BuildValue("i", rpmteParent(s->te));
235 }
236 
237 /*@null@*/
238 static PyObject *
240  /*@*/
241 {
242  return Py_BuildValue("i", rpmteTree(s->te));
243 }
244 
245 /*@null@*/
246 static PyObject *
248  /*@*/
249 {
250  return Py_BuildValue("i", rpmteAddedKey(s->te));
251 }
252 
253 /*@null@*/
254 static PyObject *
256  /*@*/
257 {
258  return Py_BuildValue("i", rpmteDBOffset(s->te));
259 }
260 
261 /*@null@*/
262 static PyObject *
264  /*@globals _Py_NoneStruct @*/
265  /*@modifies _Py_NoneStruct @*/
266 {
267  PyObject * Key;
268 
269  /* XXX how to insure that returned Key is a PyObject??? */
270  Key = (PyObject *) rpmteKey(s->te);
271  if (Key == NULL)
272  Key = Py_None;
273  Py_INCREF(Key);
274  return Key;
275 }
276 
277 /*@null@*/
278 static PyObject *
279 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
280  /*@globals _Py_NoneStruct @*/
281  /*@modifies _Py_NoneStruct @*/
282 {
283  PyObject * TagN = NULL;
284  rpmds ds;
285  rpmTag tag;
286  char * kwlist[] = {"tag", NULL};
287 
288  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:DS", kwlist, &TagN))
289  return NULL;
290 
291  tag = tagNumFromPyObject(TagN);
292  if (tag == (rpmTag)-1) {
293  PyErr_SetString(PyExc_TypeError, "unknown tag type");
294  return NULL;
295  }
296 
297  ds = rpmteDS(s->te, tag);
298  if (ds == NULL) {
299  Py_RETURN_NONE;
300  }
301  return (PyObject *) rpmds_Wrap(rpmdsLink(ds, "rpmte_DS"));
302 }
303 
304 /*@null@*/
305 static PyObject *
306 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
307  /*@globals _Py_NoneStruct @*/
308  /*@modifies _Py_NoneStruct @*/
309 {
310  PyObject * TagN = NULL;
311  rpmfi fi;
312  rpmTag tag;
313  char * kwlist[] = {"tag", NULL};
314 
315  DEPRECATED_METHOD("use .Files() instead");
316  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:FI", kwlist, &TagN))
317  return NULL;
318 
319  tag = tagNumFromPyObject(TagN);
320  if (tag == (rpmTag)-1) {
321  PyErr_SetString(PyExc_TypeError, "unknown tag type");
322  return NULL;
323  }
324 
325  fi = rpmteFI(s->te, tag);
326  if (fi == NULL) {
327  Py_RETURN_NONE;
328  }
329  return (PyObject *) rpmfi_Wrap(rpmfiLink(fi, "rpmte_FI"));
330 }
331 
336 /*@-fullinitblock@*/
337 /*@unchecked@*/ /*@observer@*/
338 static struct PyMethodDef rpmte_methods[] = {
339  {"Debug", (PyCFunction)rpmte_Debug, METH_VARARGS|METH_KEYWORDS,
340  NULL},
341  {"Type", (PyCFunction)rpmte_TEType, METH_NOARGS,
342 "te.Type() -> Type\n\
343 - Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
344  {"N", (PyCFunction)rpmte_N, METH_NOARGS,
345 "te.N() -> N\n\
346 - Return element name.\n" },
347  {"E", (PyCFunction)rpmte_E, METH_NOARGS,
348 "te.E() -> E\n\
349 - Return element epoch.\n" },
350  {"V", (PyCFunction)rpmte_V, METH_NOARGS,
351 "te.V() -> V\n\
352 - Return element version.\n" },
353  {"R", (PyCFunction)rpmte_R, METH_NOARGS,
354 "te.R() -> R\n\
355 - Return element release.\n" },
356 #if defined(RPM_VENDOR_MANDRIVA)
357  {"D", (PyCFunction)rpmte_D, METH_NOARGS,
358 "te.D() -> D\n\
359 - Return element distepoch.\n" },
360 #endif
361  {"A", (PyCFunction)rpmte_A, METH_NOARGS,
362 "te.A() -> A\n\
363 - Return element arch.\n" },
364  {"O", (PyCFunction)rpmte_O, METH_NOARGS,
365 "te.O() -> O\n\
366 - Return element os.\n" },
367  {"NEVR", (PyCFunction)rpmte_NEVR, METH_NOARGS,
368 "te.NEVR() -> NEVR\n\
369 - Return element name-version-release.\n" },
370  {"NEVRA", (PyCFunction)rpmte_NEVRA, METH_NOARGS,
371 "te.NEVRA() -> NEVRA\n\
372 - Return element name-version-release.arch.\n" },
373  {"Pkgid", (PyCFunction)rpmte_Pkgid, METH_NOARGS,
374 "te.Pkgid() -> Pkgid\n\
375 - Return element pkgid (header+payload md5 digest).\n" },
376  {"Hdrid", (PyCFunction)rpmte_Hdrid, METH_NOARGS,
377 "te.Hdrid() -> Hdrid\n\
378 - Return element hdrid (header sha1 digest).\n" },
379  {"Color",(PyCFunction)rpmte_Color, METH_NOARGS,
380  NULL},
381  {"PkgFileSize",(PyCFunction)rpmte_PkgFileSize, METH_NOARGS,
382  NULL},
383  {"Breadth", (PyCFunction)rpmte_Breadth, METH_NOARGS,
384 "te.Breadth() -> transaction element breadth index.\n" },
385  {"Depth", (PyCFunction)rpmte_Depth, METH_NOARGS,
386 "te.Depth() -> transaction element depth index.\n" },
387  {"Npreds", (PyCFunction)rpmte_Npreds, METH_NOARGS,
388  NULL},
389  {"Degree", (PyCFunction)rpmte_Degree, METH_NOARGS,
390  NULL},
391  {"Parent", (PyCFunction)rpmte_Parent, METH_NOARGS,
392  NULL},
393  {"Tree", (PyCFunction)rpmte_Tree, METH_NOARGS,
394  NULL},
395  {"AddedKey",(PyCFunction)rpmte_AddedKey, METH_NOARGS,
396  NULL},
397  {"DBOffset",(PyCFunction)rpmte_DBOffset, METH_NOARGS,
398  NULL},
399  {"Key", (PyCFunction)rpmte_Key, METH_NOARGS,
400  NULL},
401  {"DS", (PyCFunction)rpmte_DS, METH_VARARGS|METH_KEYWORDS,
402 "te.DS(TagN) -> DS\n\
403 - Return the TagN dependency set (or None). TagN is one of\n\
404  'Providename', 'Requirename', 'Obsoletename', 'Conflictname'\n" },
405  {"FI", (PyCFunction)rpmte_FI, METH_VARARGS|METH_KEYWORDS,
406 "te.FI(TagN) -> FI\n\
407 - Return the TagN dependency set (or None). TagN must be 'Basenames'.\n" },
408  {NULL, NULL} /* sentinel */
409 };
410 /*@=fullinitblock@*/
411 
412 /* ---------- */
413 
414 static int
415 rpmte_print(rpmteObject * s, FILE * fp, /*@unused@*/ int flags)
416  /*@globals fileSystem @*/
417  /*@modifies fp, fileSystem @*/
418 {
419  const char * tstr;
420  if (!(s && s->te))
421  return -1;
422  switch (rpmteType(s->te)) {
423  case TR_ADDED: tstr = "++"; break;
424  case TR_REMOVED: tstr = "--"; break;
425  default: tstr = "??"; break;
426  }
427  fprintf(fp, "%s %s %s", tstr, rpmteNEVR(s->te), rpmteA(s->te));
428  return 0;
429 }
430 
433 /*@unchecked@*/ /*@observer@*/
434 static char rpmte_doc[] =
435 "";
436 
439 /*@-fullinitblock@*/
440 PyTypeObject rpmte_Type = {
441  PyVarObject_HEAD_INIT(&PyType_Type, 0)
442  "rpm.te", /* tp_name */
443  sizeof(rpmteObject), /* tp_size */
444  0, /* tp_itemsize */
445  (destructor)0, /* tp_dealloc */
446  (printfunc) rpmte_print, /* tp_print */
447  (getattrfunc)0, /* tp_getattr */
448  (setattrfunc)0, /* tp_setattr */
449  0, /* tp_compare */
450  0, /* tp_repr */
451  0, /* tp_as_number */
452  0, /* tp_as_sequence */
453  0, /* tp_as_mapping */
454  0, /* tp_hash */
455  0, /* tp_call */
456  0, /* tp_str */
457  PyObject_GenericGetAttr, /* tp_getattro */
458  PyObject_GenericSetAttr, /* tp_setattro */
459  0, /* tp_as_buffer */
460  Py_TPFLAGS_DEFAULT, /* tp_flags */
461  rpmte_doc, /* tp_doc */
462 #if Py_TPFLAGS_HAVE_ITER
463  0, /* tp_traverse */
464  0, /* tp_clear */
465  0, /* tp_richcompare */
466  0, /* tp_weaklistoffset */
467  0, /* tp_iter */
468  0, /* tp_iternext */
469  rpmte_methods, /* tp_methods */
470  0, /* tp_members */
471  0, /* tp_getset */
472  0, /* tp_base */
473  0, /* tp_dict */
474  0, /* tp_descr_get */
475  0, /* tp_descr_set */
476  0, /* tp_dictoffset */
477  0, /* tp_init */
478  0, /* tp_alloc */
479  0, /* tp_new */
480  0, /* tp_free */
481  0, /* tp_is_gc */
482 #endif
483 };
484 /*@=fullinitblock@*/
485 
487 {
488  rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
489  if (s == NULL)
490  return NULL;
491  s->te = te;
492  return s;
493 }
rpmTag tagNumFromPyObject(PyObject *item)
Definition: header-py.c:362
static PyObject * rpmte_NEVR(rpmteObject *s)
Definition: rpmte-py.c:151
rpmuint32_t rpmteColor(rpmte te)
Retrieve color bits of transaction element.
Definition: rpmte.c:360
static PyObject * rpmte_Pkgid(rpmteObject *s)
Definition: rpmte-py.c:167
static PyObject * rpmte_R(rpmteObject *s)
Definition: rpmte-py.c:117
static PyObject * rpmte_Key(rpmteObject *s)
Definition: rpmte-py.c:263
static PyObject * rpmte_NEVRA(rpmteObject *s)
Definition: rpmte-py.c:159
const char * rpmteN(rpmte te)
Retrieve name string of transaction element.
Definition: rpmte.c:316
static PyObject * rpmte_N(rpmteObject *s)
Definition: rpmte-py.c:93
static int rpmte_print(rpmteObject *s, FILE *fp, int flags)
Definition: rpmte-py.c:415
int rpmteDegree(rpmte te)
Retrieve number of children of transaction element.
Definition: rpmte.c:467
int rpmteNpreds(rpmte te)
Retrieve tsort no.
Definition: rpmte.c:420
rpmElementType rpmteType(rpmte te)
Retrieve type of transaction element.
Definition: rpmte.c:311
PyTypeObject rpmte_Type
Definition: rpmte-py.c:440
const char * rpmteA(rpmte te)
Retrieve arch string of transaction element.
Definition: rpmte.c:345
struct rpmds_s * rpmds
Dependency tag sets from a header, so that a header can be discarded early.
Definition: rpmtypes.h:28
rpmte te
Definition: rpmte-py.h:18
rpmds rpmteDS(rpmte te, rpmTag tag)
Retrieve dependency tag set from transaction element.
Definition: rpmte.c:573
struct rpmte_s * rpmte
An element of a transaction set, i.e.
Definition: rpmtypes.h:38
static PyObject * rpmte_PkgFileSize(rpmteObject *s)
Definition: rpmte-py.c:191
const char * rpmteE(rpmte te)
Retrieve epoch string of transaction element.
Definition: rpmte.c:321
static PyObject * rpmte_Breadth(rpmteObject *s)
Definition: rpmte-py.c:199
static PyObject * rpmte_V(rpmteObject *s)
Definition: rpmte-py.c:109
int rpmteBreadth(rpmte te)
Retrieve dependency tree breadth of transaction element.
Definition: rpmte.c:405
static PyObject * rpmte_Debug(rpmteObject *s, PyObject *args, PyObject *kwds)
Definition: rpmte-py.c:70
struct rpmteObject_s rpmteObject
const char * rpmteV(rpmte te)
Retrieve version string of transaction element.
Definition: rpmte.c:326
const char * rpmteNEVR(rpmte te)
Retrieve name-version-release string from transaction element.
Definition: rpmte.c:536
rpmte rpmteParent(rpmte te)
Retrieve parent transaction element.
Definition: rpmte.c:450
int rpmteDepth(rpmte te)
Retrieve dependency tree depth of transaction element.
Definition: rpmte.c:390
alKey rpmteAddedKey(rpmte te)
Definition: rpmte.c:515
rpmfi rpmteFI(rpmte te, rpmTag tag)
Retrieve file info tag set from transaction element.
Definition: rpmte.c:587
static PyObject * rpmte_FI(rpmteObject *s, PyObject *args, PyObject *kwds)
Definition: rpmte-py.c:306
struct rpmfi_s * rpmfi
File info tag sets from a header, so that a header can be discarded early.
Definition: rpmfi.h:83
static PyObject * rpmte_Degree(rpmteObject *s)
Definition: rpmte-py.c:223
static PyObject * rpmte_O(rpmteObject *s)
Definition: rpmte-py.c:143
static PyObject * rpmte_Color(rpmteObject *s)
Definition: rpmte-py.c:183
static PyObject * rpmte_Hdrid(rpmteObject *s)
Definition: rpmte-py.c:175
static PyObject * rpmte_E(rpmteObject *s)
Definition: rpmte-py.c:101
static PyObject * rpmte_Depth(rpmteObject *s)
Definition: rpmte-py.c:207
const char * rpmteD(rpmte te)
Retrieve distepoch string of transaction element.
Definition: rpmte.c:336
const char * rpmteNEVRA(rpmte te)
Retrieve name-version-release.arch string from transaction element.
Definition: rpmte.c:541
rpmdsObject * rpmds_Wrap(rpmds ds)
Definition: rpmds-py.c:792
static PyObject * rpmte_TEType(rpmteObject *s)
Definition: rpmte-py.c:85
static char rpmte_doc[]
Definition: rpmte-py.c:434
const char * rpmteO(rpmte te)
Retrieve os string of transaction element.
Definition: rpmte.c:350
const char * rpmteHdrid(rpmte te)
Retrieve hdrid string from transaction element.
Definition: rpmte.c:551
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
rpmteObject * rpmte_Wrap(rpmte te)
Definition: rpmte-py.c:486
static PyObject * rpmte_Tree(rpmteObject *s)
Definition: rpmte-py.c:239
int _rpmte_debug
Definition: rpmte.c:26
fnpyKey rpmteKey(rpmte te)
Retrieve key from transaction element.
Definition: rpmte.c:568
Definition: rpmte.h:37
static PyObject * rpmte_DBOffset(rpmteObject *s)
Definition: rpmte-py.c:255
rpmfi rpmfiLink(rpmfi fi, const char *msg)
Reference a file info set instance.
rpmds rpmdsLink(rpmds ds, const char *msg)
Reference a dependency set instance.
static PyObject * rpmte_DS(rpmteObject *s, PyObject *args, PyObject *kwds)
Definition: rpmte-py.c:279
static PyObject * rpmte_Parent(rpmteObject *s)
Definition: rpmte-py.c:231
int rpmteDBOffset(rpmte te)
Retrieve rpmdb instance of TR_REMOVED transaction element.
Definition: rpmte.c:531
rpmuint32_t rpmtePkgFileSize(rpmte te)
Retrieve size in bytes of package file.
Definition: rpmte.c:375
static struct PyMethodDef rpmte_methods[]
Definition: rpmte-py.c:338
rpmfi fi
Definition: filetriggers.h:15
rpmfiObject * rpmfi_Wrap(rpmfi fi)
Definition: rpmfi-py.c:586
static PyObject * rpmte_Npreds(rpmteObject *s)
Definition: rpmte-py.c:215
enum rpmTag_e rpmTag
Definition: rpmtag.h:470
const char * rpmtePkgid(rpmte te)
Retrieve pkgid string from transaction element.
Definition: rpmte.c:546
int rpmteTree(rpmte te)
Retrieve tree index of transaction element.
Definition: rpmte.c:435
const char * rpmteR(rpmte te)
Retrieve release string of transaction element.
Definition: rpmte.c:331
static PyObject * rpmte_A(rpmteObject *s)
Definition: rpmte-py.c:135
static PyObject * rpmte_AddedKey(rpmteObject *s)
Definition: rpmte-py.c:247