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