rpm  5.2.1
rpmte-py.c
Go to the documentation of this file.
1 
5 #include "system.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_INCREF(Py_None);
81  return Py_None;
82 }
83 
84 /*@null@*/
85 static PyObject *
87  /*@*/
88 {
89  return Py_BuildValue("i", rpmteType(s->te));
90 }
91 
92 /*@null@*/
93 static PyObject *
95  /*@*/
96 {
97  return Py_BuildValue("s", rpmteN(s->te));
98 }
99 
100 /*@null@*/
101 static PyObject *
103  /*@*/
104 {
105  return Py_BuildValue("s", rpmteE(s->te));
106 }
107 
108 /*@null@*/
109 static PyObject *
111  /*@*/
112 {
113  return Py_BuildValue("s", rpmteV(s->te));
114 }
115 
116 /*@null@*/
117 static PyObject *
119  /*@*/
120 {
121  return Py_BuildValue("s", rpmteR(s->te));
122 }
123 
124 #if defined(RPM_VENDOR_MANDRIVA)
125 /*@null@*/
126 static PyObject *
127 rpmte_D(rpmteObject * s)
128  /*@*/
129 {
130  return Py_BuildValue("s", rpmteD(s->te));
131 }
132 #endif
133 
134 /*@null@*/
135 static PyObject *
137  /*@*/
138 {
139  return Py_BuildValue("s", rpmteA(s->te));
140 }
141 
142 /*@null@*/
143 static PyObject *
145  /*@*/
146 {
147  return Py_BuildValue("s", rpmteO(s->te));
148 }
149 
150 /*@null@*/
151 static PyObject *
153  /*@*/
154 {
155  return Py_BuildValue("s", rpmteNEVR(s->te));
156 }
157 
158 /*@null@*/
159 static PyObject *
161  /*@*/
162 {
163  return Py_BuildValue("s", rpmteNEVRA(s->te));
164 }
165 
166 /*@null@*/
167 static PyObject *
169  /*@*/
170 {
171  return Py_BuildValue("s", rpmtePkgid(s->te));
172 }
173 
174 /*@null@*/
175 static PyObject *
177  /*@*/
178 {
179  return Py_BuildValue("s", rpmteHdrid(s->te));
180 }
181 
182 /*@null@*/
183 static PyObject *
185  /*@*/
186 {
187  return Py_BuildValue("i", rpmteColor(s->te));
188 }
189 
190 /*@null@*/
191 static PyObject *
193  /*@*/
194 {
195  return Py_BuildValue("i", rpmtePkgFileSize(s->te));
196 }
197 
198 /*@null@*/
199 static PyObject *
201  /*@*/
202 {
203  return Py_BuildValue("i", rpmteBreadth(s->te));
204 }
205 
206 /*@null@*/
207 static PyObject *
209  /*@*/
210 {
211  return Py_BuildValue("i", rpmteDepth(s->te));
212 }
213 
214 /*@null@*/
215 static PyObject *
217  /*@*/
218 {
219  return Py_BuildValue("i", rpmteNpreds(s->te));
220 }
221 
222 /*@null@*/
223 static PyObject *
225  /*@*/
226 {
227  return Py_BuildValue("i", rpmteDegree(s->te));
228 }
229 
230 /*@null@*/
231 static PyObject *
233  /*@*/
234 {
235  return Py_BuildValue("i", rpmteParent(s->te));
236 }
237 
238 /*@null@*/
239 static PyObject *
241  /*@*/
242 {
243  return Py_BuildValue("i", rpmteTree(s->te));
244 }
245 
246 /*@null@*/
247 static PyObject *
249  /*@*/
250 {
251  return Py_BuildValue("i", rpmteAddedKey(s->te));
252 }
253 
254 /*@null@*/
255 static PyObject *
257  /*@*/
258 {
259  return Py_BuildValue("i", rpmteDBOffset(s->te));
260 }
261 
262 /*@null@*/
263 static PyObject *
265  /*@globals _Py_NoneStruct @*/
266  /*@modifies _Py_NoneStruct @*/
267 {
268  PyObject * Key;
269 
270  /* XXX how to insure that returned Key is a PyObject??? */
271  Key = (PyObject *) rpmteKey(s->te);
272  if (Key == NULL)
273  Key = Py_None;
274  Py_INCREF(Key);
275  return Key;
276 }
277 
278 /*@null@*/
279 static PyObject *
280 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
281  /*@globals _Py_NoneStruct @*/
282  /*@modifies _Py_NoneStruct @*/
283 {
284  PyObject * TagN = NULL;
285  rpmds ds;
286  rpmTag tag;
287  char * kwlist[] = {"tag", NULL};
288 
289  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:DS", kwlist, &TagN))
290  return NULL;
291 
292  tag = tagNumFromPyObject(TagN);
293  if (tag == (rpmTag)-1) {
294  PyErr_SetString(PyExc_TypeError, "unknown tag type");
295  return NULL;
296  }
297 
298  ds = rpmteDS(s->te, tag);
299  if (ds == NULL) {
300  Py_INCREF(Py_None);
301  return Py_None;
302  }
303  return (PyObject *) rpmds_Wrap(rpmdsLink(ds, "rpmte_DS"));
304 }
305 
306 /*@null@*/
307 static PyObject *
308 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
309  /*@globals _Py_NoneStruct @*/
310  /*@modifies _Py_NoneStruct @*/
311 {
312  PyObject * TagN = NULL;
313  rpmfi fi;
314  rpmTag tag;
315  char * kwlist[] = {"tag", NULL};
316 
317  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:FI", kwlist, &TagN))
318  return NULL;
319 
320  tag = tagNumFromPyObject(TagN);
321  if (tag == (rpmTag)-1) {
322  PyErr_SetString(PyExc_TypeError, "unknown tag type");
323  return NULL;
324  }
325 
326  fi = rpmteFI(s->te, tag);
327  if (fi == NULL) {
328  Py_INCREF(Py_None);
329  return Py_None;
330  }
331  return (PyObject *) rpmfi_Wrap(rpmfiLink(fi, "rpmte_FI"));
332 }
333 
338 /*@-fullinitblock@*/
339 /*@unchecked@*/ /*@observer@*/
340 static struct PyMethodDef rpmte_methods[] = {
341  {"Debug", (PyCFunction)rpmte_Debug, METH_VARARGS|METH_KEYWORDS,
342  NULL},
343  {"Type", (PyCFunction)rpmte_TEType, METH_NOARGS,
344 "te.Type() -> Type\n\
345 - Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
346  {"N", (PyCFunction)rpmte_N, METH_NOARGS,
347 "te.N() -> N\n\
348 - Return element name.\n" },
349  {"E", (PyCFunction)rpmte_E, METH_NOARGS,
350 "te.E() -> E\n\
351 - Return element epoch.\n" },
352  {"V", (PyCFunction)rpmte_V, METH_NOARGS,
353 "te.V() -> V\n\
354 - Return element version.\n" },
355  {"R", (PyCFunction)rpmte_R, METH_NOARGS,
356 "te.R() -> R\n\
357 - Return element release.\n" },
358 #if defined(RPM_VENDOR_MANDRIVA)
359  {"D", (PyCFunction)rpmte_D, METH_NOARGS,
360 "te.D() -> D\n\
361 - Return element distepoch.\n" },
362 #endif
363  {"A", (PyCFunction)rpmte_A, METH_NOARGS,
364 "te.A() -> A\n\
365 - Return element arch.\n" },
366  {"O", (PyCFunction)rpmte_O, METH_NOARGS,
367 "te.O() -> O\n\
368 - Return element os.\n" },
369  {"NEVR", (PyCFunction)rpmte_NEVR, METH_NOARGS,
370 "te.NEVR() -> NEVR\n\
371 - Return element name-version-release.\n" },
372  {"NEVRA", (PyCFunction)rpmte_NEVRA, METH_NOARGS,
373 "te.NEVRA() -> NEVRA\n\
374 - Return element name-version-release.arch.\n" },
375  {"Pkgid", (PyCFunction)rpmte_Pkgid, METH_NOARGS,
376 "te.Pkgid() -> Pkgid\n\
377 - Return element pkgid (header+payload md5 digest).\n" },
378  {"Hdrid", (PyCFunction)rpmte_Hdrid, METH_NOARGS,
379 "te.Hdrid() -> Hdrid\n\
380 - Return element hdrid (header sha1 digest).\n" },
381  {"Color",(PyCFunction)rpmte_Color, METH_NOARGS,
382  NULL},
383  {"PkgFileSize",(PyCFunction)rpmte_PkgFileSize, METH_NOARGS,
384  NULL},
385  {"Breadth", (PyCFunction)rpmte_Breadth, METH_NOARGS,
386 "te.Breadth() -> transaction element breadth index.\n" },
387  {"Depth", (PyCFunction)rpmte_Depth, METH_NOARGS,
388 "te.Depth() -> transaction element depth index.\n" },
389  {"Npreds", (PyCFunction)rpmte_Npreds, METH_NOARGS,
390  NULL},
391  {"Degree", (PyCFunction)rpmte_Degree, METH_NOARGS,
392  NULL},
393  {"Parent", (PyCFunction)rpmte_Parent, METH_NOARGS,
394  NULL},
395  {"Tree", (PyCFunction)rpmte_Tree, METH_NOARGS,
396  NULL},
397  {"AddedKey",(PyCFunction)rpmte_AddedKey, METH_NOARGS,
398  NULL},
399  {"DBOffset",(PyCFunction)rpmte_DBOffset, METH_NOARGS,
400  NULL},
401  {"Key", (PyCFunction)rpmte_Key, METH_NOARGS,
402  NULL},
403  {"DS", (PyCFunction)rpmte_DS, METH_VARARGS|METH_KEYWORDS,
404 "te.DS(TagN) -> DS\n\
405 - Return the TagN dependency set (or None). TagN is one of\n\
406  'Providename', 'Requirename', 'Obsoletename', 'Conflictname'\n" },
407  {"FI", (PyCFunction)rpmte_FI, METH_VARARGS|METH_KEYWORDS,
408 "te.FI(TagN) -> FI\n\
409 - Return the TagN dependency set (or None). TagN must be 'Basenames'.\n" },
410  {NULL, NULL} /* sentinel */
411 };
412 /*@=fullinitblock@*/
413 
414 /* ---------- */
415 
416 static int
417 rpmte_print(rpmteObject * s, FILE * fp, /*@unused@*/ int flags)
418  /*@globals fileSystem @*/
419  /*@modifies fp, fileSystem @*/
420 {
421  const char * tstr;
422  if (!(s && s->te))
423  return -1;
424  switch (rpmteType(s->te)) {
425  case TR_ADDED: tstr = "++"; break;
426  case TR_REMOVED: tstr = "--"; break;
427  default: tstr = "??"; break;
428  }
429  fprintf(fp, "%s %s %s", tstr, rpmteNEVR(s->te), rpmteA(s->te));
430  return 0;
431 }
432 
433 static PyObject * rpmte_getattro(PyObject * o, PyObject * n)
434  /*@*/
435 {
436  return PyObject_GenericGetAttr(o, n);
437 }
438 
439 static int rpmte_setattro(PyObject * o, PyObject * n, PyObject * v)
440  /*@*/
441 {
442  return PyObject_GenericSetAttr(o, n, v);
443 }
444 
447 /*@unchecked@*/ /*@observer@*/
448 static char rpmte_doc[] =
449 "";
450 
453 /*@-fullinitblock@*/
454 PyTypeObject rpmte_Type = {
455  PyObject_HEAD_INIT(&PyType_Type)
456  0, /* ob_size */
457  "rpm.te", /* tp_name */
458  sizeof(rpmteObject), /* tp_size */
459  0, /* tp_itemsize */
460  (destructor)0, /* tp_dealloc */
461  (printfunc) rpmte_print, /* tp_print */
462  (getattrfunc)0, /* tp_getattr */
463  (setattrfunc)0, /* tp_setattr */
464  0, /* tp_compare */
465  0, /* tp_repr */
466  0, /* tp_as_number */
467  0, /* tp_as_sequence */
468  0, /* tp_as_mapping */
469  0, /* tp_hash */
470  0, /* tp_call */
471  0, /* tp_str */
472  (getattrofunc) rpmte_getattro, /* tp_getattro */
473  (setattrofunc) rpmte_setattro, /* tp_setattro */
474  0, /* tp_as_buffer */
475  Py_TPFLAGS_DEFAULT, /* tp_flags */
476  rpmte_doc, /* tp_doc */
477 #if Py_TPFLAGS_HAVE_ITER
478  0, /* tp_traverse */
479  0, /* tp_clear */
480  0, /* tp_richcompare */
481  0, /* tp_weaklistoffset */
482  0, /* tp_iter */
483  0, /* tp_iternext */
484  rpmte_methods, /* tp_methods */
485  0, /* tp_members */
486  0, /* tp_getset */
487  0, /* tp_base */
488  0, /* tp_dict */
489  0, /* tp_descr_get */
490  0, /* tp_descr_set */
491  0, /* tp_dictoffset */
492  0, /* tp_init */
493  0, /* tp_alloc */
494  0, /* tp_new */
495  0, /* tp_free */
496  0, /* tp_is_gc */
497 #endif
498 };
499 /*@=fullinitblock@*/
500 
502 {
503  rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
504  if (s == NULL)
505  return NULL;
506  s->te = te;
507  return s;
508 }