c503202c917b64fd646ad878797a40b5912249f6
[platform/upstream/rpm.git] / python / rpmal-py.c
1 /** \ingroup py_c
2  * \file python/rpmal-py.c
3  */
4
5 #include "system.h"
6
7 #include "rpmal-py.h"
8 #include "rpmds-py.h"
9 #include "rpmfi-py.h"
10
11 #include "debug.h"
12
13 static PyObject *
14 rpmal_Debug(rpmalObject * s, PyObject * args, PyObject * kwds)
15 {
16     char * kwlist[] = {"debugLevel", NULL};
17
18     if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmal_debug))
19         return NULL;
20
21     Py_INCREF(Py_None);
22     return Py_None;
23 }
24
25 static PyObject *
26 rpmal_Add(rpmalObject * s, PyObject * args, PyObject * kwds)
27 {
28     rpmte p;
29     char * kwlist[] = {"package", NULL};
30
31     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Add", kwlist,
32             &p))
33         return NULL;
34
35     rpmalAdd(s->al, p);
36
37     Py_INCREF(Py_None);
38     return Py_None;
39 }
40
41 static PyObject *
42 rpmal_Del(rpmalObject * s, PyObject * args, PyObject * kwds)
43 {
44     rpmte p;
45     char * kwlist[] = {"key", NULL};
46
47     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Del", kwlist, &p))
48         return NULL;
49
50     rpmalDel(s->al, p);
51
52     Py_INCREF(Py_None);
53     return Py_None;
54 }
55
56 static PyObject *
57 rpmal_MakeIndex(rpmalObject * s)
58 {
59     rpmalMakeIndex(s->al);
60
61     Py_INCREF(Py_None);
62     return Py_None;
63 }
64
65 static struct PyMethodDef rpmal_methods[] = {
66  {"Debug",      (PyCFunction)rpmal_Debug,       METH_VARARGS|METH_KEYWORDS,
67         NULL},
68  {"add",        (PyCFunction)rpmal_Add,         METH_VARARGS|METH_KEYWORDS,
69         NULL},
70  {"delete",     (PyCFunction)rpmal_Del,         METH_VARARGS|METH_KEYWORDS,
71         NULL},
72  {"makeIndex",(PyCFunction)rpmal_MakeIndex,     METH_NOARGS,
73         NULL},
74  {NULL,         NULL }          /* sentinel */
75 };
76
77 /* ---------- */
78
79 static void
80 rpmal_dealloc(rpmalObject * s)
81 {
82     if (s) {
83         s->al = rpmalFree(s->al);
84         PyObject_Del(s);
85     }
86 }
87
88 static PyObject * rpmal_getattro(PyObject * o, PyObject * n)
89 {
90     return PyObject_GenericGetAttr(o, n);
91 }
92
93 static int rpmal_setattro(PyObject * o, PyObject * n, PyObject * v)
94 {
95     return PyObject_GenericSetAttr(o, n, v);
96 }
97
98 /**
99  */
100 static char rpmal_doc[] =
101 "";
102
103 PyTypeObject rpmal_Type = {
104         PyObject_HEAD_INIT(&PyType_Type)
105         0,                              /* ob_size */
106         "rpm.al",                       /* tp_name */
107         sizeof(rpmalObject),            /* tp_basicsize */
108         0,                              /* tp_itemsize */
109         /* methods */
110         (destructor) rpmal_dealloc,     /* tp_dealloc */
111         (printfunc)0,                   /* tp_print */
112         (getattrfunc)0,                 /* tp_getattr */
113         (setattrfunc)0,                 /* tp_setattr */
114         (cmpfunc)0,                     /* tp_compare */
115         (reprfunc)0,                    /* tp_repr */
116         0,                              /* tp_as_number */
117         0,                              /* tp_as_sequence */
118         0,                              /* tp_as_mapping */
119         (hashfunc)0,                    /* tp_hash */
120         (ternaryfunc)0,                 /* tp_call */
121         (reprfunc)0,                    /* tp_str */
122         (getattrofunc) rpmal_getattro,  /* tp_getattro */
123         (setattrofunc) rpmal_setattro,  /* tp_setattro */
124         0,                              /* tp_as_buffer */
125         Py_TPFLAGS_DEFAULT,             /* tp_flags */
126         rpmal_doc,                      /* tp_doc */
127 #if Py_TPFLAGS_HAVE_ITER
128         0,                              /* tp_traverse */
129         0,                              /* tp_clear */
130         0,                              /* tp_richcompare */
131         0,                              /* tp_weaklistoffset */
132         (getiterfunc)0,                 /* tp_iter */
133         (iternextfunc)0,                /* tp_iternext */
134         rpmal_methods,                  /* tp_methods */
135         0,                              /* tp_members */
136         0,                              /* tp_getset */
137         0,                              /* tp_base */
138         0,                              /* tp_dict */
139         0,                              /* tp_descr_get */
140         0,                              /* tp_descr_set */
141         0,                              /* tp_dictoffset */
142         0,                              /* tp_init */
143         0,                              /* tp_alloc */
144         0,                              /* tp_new */
145         0,                              /* tp_free */
146         0,                              /* tp_is_gc */
147 #endif
148 };
149
150 /* ---------- */
151
152 rpmalObject *
153 rpmal_Wrap(rpmal al)
154 {
155     rpmalObject *s = PyObject_New(rpmalObject, &rpmal_Type);
156     if (s == NULL)
157         return NULL;
158     s->al = al;
159     return s;
160 }