Add macro %isu_package to generate ISU Package
[platform/upstream/rpm.git] / python / rpmte-py.c
1 #include "rpmsystem-py.h"
2
3 #include "header-py.h"  /* XXX tagNumFromPyObject */
4 #include "rpmds-py.h"
5 #include "rpmfi-py.h"
6 #include "rpmfiles-py.h"
7 #include "rpmte-py.h"
8 #include "rpmps-py.h"
9
10 /** \ingroup python
11  * \name Class: Rpmte
12  * \class Rpmte
13  * \brief An python rpm.te object represents an element of a transaction set.
14  *
15  * Elements of a transaction set are accessible after being added. Each
16  * element carries descriptive information about the added element as well
17  * as a file info set and dependency sets for each of the 4 types of dependency.
18  *
19  * The rpmte class contains the following methods:
20  *
21  * - te.Type()  Return transaction element type (TR_ADDED|TR_REMOVED).
22  * - te.N()     Return package name.
23  * - te.E()     Return package epoch.
24  * - te.V()     Return package version.
25  * - te.R()     Return package release.
26  * - te.A()     Return package architecture.
27  * - te.O()     Return package operating system.
28  * - te.NEVR()  Return package name-version-release.
29  * - te.Color() Return package color bits.
30  * - te.PkgFileSize() Return no. of bytes in package file (approx).
31  * - te.Parent() Return the parent element index.
32  * - te.Problems() Return problems associated with this element.
33  * - te.AddedKey() Return the added package index (TR_ADDED).
34  * - te.DependsOnKey() Return the package index for the added package (TR_REMOVED).
35  * - te.DBOffset() Return the Packages database instance number (TR_REMOVED)
36  * - te.Key()   Return the associated opaque key, i.e. 2nd arg ts.addInstall().
37  * - te.DS(tag) Return package dependency set.
38  * @param tag   'Providename', 'Requirename', 'Obsoletename', 'Conflictname'
39  * - te.FI(tag) Return package file info set iterator (deprecated).
40  * @param tag   'Basenames'
41  * - te.Files() Return package file info set.
42  */
43
44 struct rpmteObject_s {
45     PyObject_HEAD
46     PyObject *md_dict;          /*!< to look like PyModuleObject */
47     rpmte       te;
48 };
49
50 static PyObject *
51 rpmte_TEType(rpmteObject * s, PyObject * unused)
52 {
53     return Py_BuildValue("i", rpmteType(s->te));
54 }
55
56 static PyObject *
57 rpmte_N(rpmteObject * s, PyObject * unused)
58 {
59     return Py_BuildValue("s", rpmteN(s->te));
60 }
61
62 static PyObject *
63 rpmte_E(rpmteObject * s, PyObject * unused)
64 {
65     return Py_BuildValue("s", rpmteE(s->te));
66 }
67
68 static PyObject *
69 rpmte_V(rpmteObject * s, PyObject * unused)
70 {
71     return Py_BuildValue("s", rpmteV(s->te));
72 }
73
74 static PyObject *
75 rpmte_R(rpmteObject * s, PyObject * unused)
76 {
77     return Py_BuildValue("s", rpmteR(s->te));
78 }
79
80 static PyObject *
81 rpmte_A(rpmteObject * s, PyObject * unused)
82 {
83     return Py_BuildValue("s", rpmteA(s->te));
84 }
85
86 static PyObject *
87 rpmte_O(rpmteObject * s, PyObject * unused)
88 {
89     return Py_BuildValue("s", rpmteO(s->te));
90 }
91
92 static PyObject *
93 rpmte_NEVR(rpmteObject * s, PyObject * unused)
94 {
95     return Py_BuildValue("s", rpmteNEVR(s->te));
96 }
97
98 static PyObject *
99 rpmte_NEVRA(rpmteObject * s, PyObject * unused)
100 {
101     return Py_BuildValue("s", rpmteNEVRA(s->te));
102 }
103
104 static PyObject *
105 rpmte_Color(rpmteObject * s, PyObject * unused)
106 {
107     return Py_BuildValue("i", rpmteColor(s->te));
108 }
109
110 static PyObject *
111 rpmte_PkgFileSize(rpmteObject * s, PyObject * unused)
112 {
113     return Py_BuildValue("L", rpmtePkgFileSize(s->te));
114 }
115
116 static PyObject *
117 rpmte_Parent(rpmteObject * s, PyObject * unused)
118 {
119     rpmte parent = rpmteParent(s->te);
120     if (parent)
121         return rpmte_Wrap(&rpmte_Type, parent);
122
123     Py_RETURN_NONE;
124 }
125
126 static PyObject * rpmte_Failed(rpmteObject * s, PyObject * unused)
127 {
128     return Py_BuildValue("i", rpmteFailed(s->te));
129 }
130
131 static PyObject * rpmte_Problems(rpmteObject * s, PyObject * unused)
132 {
133     rpmps ps = rpmteProblems(s->te);
134     PyObject *problems = rpmps_AsList(ps);
135     rpmpsFree(ps);
136     return problems;
137 }
138
139 /*
140 static PyObject *
141 rpmte_DependsOnKey(rpmteObject * s, PyObject * unused)
142 {
143     return Py_BuildValue("i", rpmteDependsOnKey(s->te));
144 }
145 */
146
147 static PyObject *
148 rpmte_DBOffset(rpmteObject * s, PyObject * unused)
149 {
150     return Py_BuildValue("i", rpmteDBOffset(s->te));
151 }
152
153 static PyObject *
154 rpmte_Key(rpmteObject * s, PyObject * unused)
155 {
156     /* XXX how to insure this is a PyObject??? */
157     PyObject * Key = (PyObject *) rpmteKey(s->te);
158     if (Key == NULL)
159         Key = Py_None;
160     Py_INCREF(Key);
161     return Key;
162 }
163
164 static PyObject *
165 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
166 {
167     rpmds ds;
168     rpmTagVal tag;
169     char * kwlist[] = {"tag", NULL};
170
171     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:DS", kwlist,
172                                 tagNumFromPyObject, &tag))
173         return NULL;
174
175     ds = rpmteDS(s->te, tag);
176     if (ds == NULL) {
177         Py_RETURN_NONE;
178     }
179     return rpmds_Wrap(&rpmds_Type, rpmdsLink(ds));
180 }
181
182 static PyObject *
183 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
184 {
185     rpmfi fi;
186
187     DEPRECATED_METHOD("use .Files() instead");
188
189     fi = rpmteFI(s->te);
190     if (fi == NULL) {
191         Py_RETURN_NONE;
192     }
193     return rpmfi_Wrap(&rpmfi_Type, rpmfiLink(fi));
194 }
195
196 static PyObject *
197 rpmte_Files(rpmteObject * s, PyObject * args, PyObject * kwds)
198 {
199     rpmfiles files = rpmteFiles(s->te);
200     if (files == NULL) {
201         Py_RETURN_NONE;
202     }
203     return rpmfiles_Wrap(&rpmfiles_Type, files);
204 }
205 static struct PyMethodDef rpmte_methods[] = {
206     {"Type",    (PyCFunction)rpmte_TEType,      METH_NOARGS,
207      "te.Type() -- Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
208     {"N",       (PyCFunction)rpmte_N,           METH_NOARGS,
209      "te.N() -- Return element name.\n" },
210     {"E",       (PyCFunction)rpmte_E,           METH_NOARGS,
211      "te.E() -- Return element epoch.\n" },
212     {"V",       (PyCFunction)rpmte_V,           METH_NOARGS,
213      "te.V() -- Return element version.\n" },
214     {"R",       (PyCFunction)rpmte_R,           METH_NOARGS,
215      "te.R() -- Return element release.\n" },
216     {"A",       (PyCFunction)rpmte_A,           METH_NOARGS,
217      "te.A() -- Return element arch.\n" },
218     {"O",       (PyCFunction)rpmte_O,           METH_NOARGS,
219      "te.O() -- Return element os.\n" },
220     {"NEVR",    (PyCFunction)rpmte_NEVR,        METH_NOARGS,
221      "te.NEVR() -- Return element name-[epoch:]version-release.\n" },
222     {"NEVRA",   (PyCFunction)rpmte_NEVRA,       METH_NOARGS,
223      "te.NEVRA() -- Return element name-[epoch:]version-release.arch\n" },
224     {"Color",(PyCFunction)rpmte_Color,          METH_NOARGS,
225      "te.Color() -- Return package color bits."},
226     {"PkgFileSize",(PyCFunction)rpmte_PkgFileSize,      METH_NOARGS,
227      "te.PkgFileSize() -- Return no. of bytes in package file (approx)."},
228     {"Parent",  (PyCFunction)rpmte_Parent,      METH_NOARGS,
229      "te.Parent() -- Return the parent element index."},
230     {"Problems",(PyCFunction)rpmte_Problems,    METH_NOARGS,
231      "te.Problems() -- Return problems associated with this element."},
232 /*    {"DependsOnKey",(PyCFunction)rpmte_DependsOnKey,  METH_NOARGS,
233       NULL}, */
234     {"DBOffset",(PyCFunction)rpmte_DBOffset,    METH_NOARGS,
235      "te.DBOffset() -- Return the Package's database instance number.\n\nTR_REMOVED only"},
236     {"Failed",  (PyCFunction)rpmte_Failed,      METH_NOARGS,
237      "te.Failed() -- Return if there are any related errors."},
238     {"Key",     (PyCFunction)rpmte_Key,         METH_NOARGS,
239      "te.Key() -- Return the associated opaque key aka user data\n\
240         as passed e.g. as data arg ts.addInstall()"},
241     {"DS",      (PyCFunction)rpmte_DS,          METH_VARARGS|METH_KEYWORDS,
242 "te.DS(TagN) -- Return the TagN dependency set (or None).\n\
243         TagN is one of 'Providename', 'Requirename', 'Obsoletename',\n\
244         'Conflictname', 'Triggername', 'Recommendname', 'Suggestname',\n\
245         'Supplementname', 'Enhancename'" },
246     {"FI",      (PyCFunction)rpmte_FI,          METH_VARARGS|METH_KEYWORDS,
247 "te.FI(TagN) -- Return file info iterator of element.\n\n DEPRECATED! Use .Files() instead.\n" },
248     {"Files",   (PyCFunction)rpmte_Files,       METH_NOARGS,
249 "te.Files() -- Return file info set of element.\n" },
250     {NULL,              NULL}           /* sentinel */
251 };
252
253 /* ---------- */
254
255 static char rpmte_doc[] =
256 "";
257
258 PyTypeObject rpmte_Type = {
259         PyVarObject_HEAD_INIT(&PyType_Type, 0)
260         "rpm.te",                       /* tp_name */
261         sizeof(rpmteObject),            /* tp_size */
262         0,                              /* tp_itemsize */
263         (destructor)0,                  /* tp_dealloc */
264         0,                              /* tp_print */
265         (getattrfunc)0,                 /* tp_getattr */
266         (setattrfunc)0,                 /* tp_setattr */
267         0,                              /* tp_compare */
268         0,                              /* tp_repr */
269         0,                              /* tp_as_number */
270         0,                              /* tp_as_sequence */
271         0,                              /* tp_as_mapping */
272         0,                              /* tp_hash */
273         0,                              /* tp_call */
274         0,                              /* tp_str */
275         PyObject_GenericGetAttr,        /* tp_getattro */
276         PyObject_GenericSetAttr,        /* tp_setattro */
277         0,                              /* tp_as_buffer */
278         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
279         rpmte_doc,                      /* tp_doc */
280         0,                              /* tp_traverse */
281         0,                              /* tp_clear */
282         0,                              /* tp_richcompare */
283         0,                              /* tp_weaklistoffset */
284         0,                              /* tp_iter */
285         0,                              /* tp_iternext */
286         rpmte_methods,                  /* tp_methods */
287         0,                              /* tp_members */
288         0,                              /* tp_getset */
289         0,                              /* tp_base */
290         0,                              /* tp_dict */
291         0,                              /* tp_descr_get */
292         0,                              /* tp_descr_set */
293         0,                              /* tp_dictoffset */
294         0,                              /* tp_init */
295         0,                              /* tp_alloc */
296         0,                              /* tp_new */
297         0,                              /* tp_free */
298         0,                              /* tp_is_gc */
299 };
300
301 PyObject * rpmte_Wrap(PyTypeObject *subtype, rpmte te)
302 {
303     rpmteObject *s = (rpmteObject *)subtype->tp_alloc(subtype, 0);
304     if (s == NULL) return NULL;
305
306     s->te = te;
307     return (PyObject *) s;
308 }