~ubuntu-branches/ubuntu/precise/rpm/precise-proposed

« back to all changes in this revision

Viewing changes to python/rpmal-py.c

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-06-28 11:12:30 UTC
  • mfrom: (17.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100628111230-8ggjjhgpvrnr3ybx
Tags: 4.8.1-5
Fix compilation on hurd and kfreebsd (Closes: #587366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
    rpmdsObject * dso;
29
 
    rpmfiObject * fio;
30
 
    PyObject * key;
31
 
    rpmalKey pkgKey;
32
 
    char * kwlist[] = {"packageKey", "key", "dso", "fileInfo", NULL};
33
 
 
34
 
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:Add", kwlist,
35
 
            &pkgKey, &key, &rpmds_Type, &dso, &rpmfi_Type, &fio))
36
 
        return NULL;
37
 
 
38
 
    /* XXX errors */
39
 
    /* XXX transaction colors */
40
 
    pkgKey = rpmalAdd(&s->al, pkgKey, key, dso->ds, fio->fi, 0);
41
 
 
42
 
    return Py_BuildValue("i", pkgKey);
43
 
}
44
 
 
45
 
static PyObject *
46
 
rpmal_Del(rpmalObject * s, PyObject * args, PyObject * kwds)
47
 
{
48
 
    rpmalKey pkgKey;
49
 
    char * kwlist[] = {"key", NULL};
50
 
 
51
 
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Del", kwlist, &pkgKey))
52
 
        return NULL;
53
 
 
54
 
    rpmalDel(s->al, pkgKey);
55
 
 
56
 
    Py_INCREF(Py_None);
57
 
    return Py_None;
58
 
}
59
 
 
60
 
static PyObject *
61
 
rpmal_AddProvides(rpmalObject * s, PyObject * args, PyObject * kwds)
62
 
{
63
 
    rpmdsObject * dso;
64
 
    rpmalKey pkgKey;
65
 
    char * kwlist[] = {"index", "packageIndex", "dso", NULL};
66
 
 
67
 
    /* XXX: why is there an argument listed in the format string that
68
 
     *      isn't handled?  Is that for transaction color? */
69
 
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "iOO!O!:AddProvides", kwlist,
70
 
            &pkgKey, &rpmds_Type, &dso))
71
 
        return NULL;
72
 
 
73
 
    /* XXX transaction colors */
74
 
    rpmalAddProvides(s->al, pkgKey, dso->ds, 0);
75
 
 
76
 
    Py_INCREF(Py_None);
77
 
    return Py_None;
78
 
}
79
 
 
80
 
static PyObject *
81
 
rpmal_MakeIndex(rpmalObject * s)
82
 
{
83
 
    rpmalMakeIndex(s->al);
84
 
 
85
 
    Py_INCREF(Py_None);
86
 
    return Py_None;
87
 
}
88
 
 
89
 
static struct PyMethodDef rpmal_methods[] = {
90
 
 {"Debug",      (PyCFunction)rpmal_Debug,       METH_VARARGS|METH_KEYWORDS,
91
 
        NULL},
92
 
 {"add",        (PyCFunction)rpmal_Add,         METH_VARARGS|METH_KEYWORDS,
93
 
        NULL},
94
 
 {"delete",     (PyCFunction)rpmal_Del,         METH_VARARGS|METH_KEYWORDS,
95
 
        NULL},
96
 
 {"addProvides",(PyCFunction)rpmal_AddProvides, METH_VARARGS|METH_KEYWORDS,
97
 
        NULL},
98
 
 {"makeIndex",(PyCFunction)rpmal_MakeIndex,     METH_NOARGS,
99
 
        NULL},
100
 
 {NULL,         NULL }          /* sentinel */
101
 
};
102
 
 
103
 
/* ---------- */
104
 
 
105
 
static void
106
 
rpmal_dealloc(rpmalObject * s)
107
 
{
108
 
    if (s) {
109
 
        s->al = rpmalFree(s->al);
110
 
        PyObject_Del(s);
111
 
    }
112
 
}
113
 
 
114
 
static PyObject * rpmal_getattro(PyObject * o, PyObject * n)
115
 
{
116
 
    return PyObject_GenericGetAttr(o, n);
117
 
}
118
 
 
119
 
static int rpmal_setattro(PyObject * o, PyObject * n, PyObject * v)
120
 
{
121
 
    return PyObject_GenericSetAttr(o, n, v);
122
 
}
123
 
 
124
 
/**
125
 
 */
126
 
static char rpmal_doc[] =
127
 
"";
128
 
 
129
 
PyTypeObject rpmal_Type = {
130
 
        PyObject_HEAD_INIT(&PyType_Type)
131
 
        0,                              /* ob_size */
132
 
        "rpm.al",                       /* tp_name */
133
 
        sizeof(rpmalObject),            /* tp_basicsize */
134
 
        0,                              /* tp_itemsize */
135
 
        /* methods */
136
 
        (destructor) rpmal_dealloc,     /* tp_dealloc */
137
 
        (printfunc)0,                   /* tp_print */
138
 
        (getattrfunc)0,                 /* tp_getattr */
139
 
        (setattrfunc)0,                 /* tp_setattr */
140
 
        (cmpfunc)0,                     /* tp_compare */
141
 
        (reprfunc)0,                    /* tp_repr */
142
 
        0,                              /* tp_as_number */
143
 
        0,                              /* tp_as_sequence */
144
 
        0,                              /* tp_as_mapping */
145
 
        (hashfunc)0,                    /* tp_hash */
146
 
        (ternaryfunc)0,                 /* tp_call */
147
 
        (reprfunc)0,                    /* tp_str */
148
 
        (getattrofunc) rpmal_getattro,  /* tp_getattro */
149
 
        (setattrofunc) rpmal_setattro,  /* tp_setattro */
150
 
        0,                              /* tp_as_buffer */
151
 
        Py_TPFLAGS_DEFAULT,             /* tp_flags */
152
 
        rpmal_doc,                      /* tp_doc */
153
 
#if Py_TPFLAGS_HAVE_ITER
154
 
        0,                              /* tp_traverse */
155
 
        0,                              /* tp_clear */
156
 
        0,                              /* tp_richcompare */
157
 
        0,                              /* tp_weaklistoffset */
158
 
        (getiterfunc)0,                 /* tp_iter */
159
 
        (iternextfunc)0,                /* tp_iternext */
160
 
        rpmal_methods,                  /* tp_methods */
161
 
        0,                              /* tp_members */
162
 
        0,                              /* tp_getset */
163
 
        0,                              /* tp_base */
164
 
        0,                              /* tp_dict */
165
 
        0,                              /* tp_descr_get */
166
 
        0,                              /* tp_descr_set */
167
 
        0,                              /* tp_dictoffset */
168
 
        0,                              /* tp_init */
169
 
        0,                              /* tp_alloc */
170
 
        0,                              /* tp_new */
171
 
        0,                              /* tp_free */
172
 
        0,                              /* tp_is_gc */
173
 
#endif
174
 
};
175
 
 
176
 
/* ---------- */
177
 
 
178
 
rpmalObject *
179
 
rpmal_Wrap(rpmal al)
180
 
{
181
 
    rpmalObject *s = PyObject_New(rpmalObject, &rpmal_Type);
182
 
    if (s == NULL)
183
 
        return NULL;
184
 
    s->al = al;
185
 
    return s;
186
 
}