]> git.ipfire.org Git - pakfire.git/blob - python/src/request.c
168b455a00286345e22ae55fee007e81bb326bb0
[pakfire.git] / python / src / request.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #include "pool.h"
22 #include "relation.h"
23 #include "request.h"
24 #include "solvable.h"
25
26 #include <solv/solver.h>
27
28 PyTypeObject RequestType = {
29 PyObject_HEAD_INIT(NULL)
30 tp_name: "_pakfire.Request",
31 tp_basicsize: sizeof(RequestObject),
32 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
33 tp_new : Request_new,
34 tp_dealloc: (destructor) Request_dealloc,
35 tp_doc: "Sat Request objects",
36 };
37
38 PyObject* Request_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
39 RequestObject *self;
40 PoolObject *pool;
41
42 if (!PyArg_ParseTuple(args, "O", &pool)) {
43 /* XXX raise exception */
44 }
45
46 self = (RequestObject *)type->tp_alloc(type, 0);
47 if (self != NULL) {
48 self->_pool = pool->_pool;
49 if (self->_pool == NULL) {
50 Py_DECREF(self);
51 return NULL;
52 }
53
54 queue_init(&self->_queue);
55 }
56
57 return (PyObject *)self;
58 }
59
60 PyObject *Request_dealloc(RequestObject *self) {
61 self->ob_type->tp_free((PyObject *)self);
62
63 Py_RETURN_NONE;
64 }
65
66 void _Request_solvable(RequestObject *self, Id what, Id solvable) {
67 queue_push(&self->_queue, what|SOLVER_SOLVABLE);
68 queue_push(&self->_queue, solvable);
69 }
70
71 void _Request_relation(RequestObject *self, Id what, Id relation) {
72 queue_push(&self->_queue, what|SOLVER_SOLVABLE_PROVIDES);
73 queue_push(&self->_queue, relation);
74 }
75
76 void _Request_name(RequestObject *self, Id what, Id provides) {
77 queue_push(&self->_queue, what|SOLVER_SOLVABLE_NAME);
78 queue_push(&self->_queue, provides);
79 }
80
81 PyObject *Request_install_solvable(RequestObject *self, PyObject *args) {
82 SolvableObject *solv;
83
84 if (!PyArg_ParseTuple(args, "O", &solv)) {
85 /* XXX raise exception */
86 }
87
88 _Request_solvable(self, SOLVER_INSTALL, solv->_id);
89
90 Py_RETURN_NONE;
91 }
92
93 PyObject *Request_install_relation(RequestObject *self, PyObject *args) {
94 RelationObject *rel;
95
96 if (!PyArg_ParseTuple(args, "O", &rel)) {
97 /* XXX raise exception */
98 }
99
100 _Request_relation(self, SOLVER_INSTALL, rel->_id);
101
102 Py_RETURN_NONE;
103 }
104
105 PyObject *Request_install_name(RequestObject *self, PyObject *args) {
106 const char *name;
107
108 if (!PyArg_ParseTuple(args, "s", &name)) {
109 /* XXX raise exception */
110 }
111
112 Id _name = pool_str2id(self->_pool, name, 1);
113 _Request_name(self, SOLVER_INSTALL, _name);
114
115 Py_RETURN_NONE;
116 }
117
118 PyObject *Request_remove_solvable(RequestObject *self, PyObject *args) {
119 SolvableObject *solv;
120
121 if (!PyArg_ParseTuple(args, "O", &solv)) {
122 /* XXX raise exception */
123 }
124
125 _Request_solvable(self, SOLVER_ERASE, solv->_id);
126
127 Py_RETURN_NONE;
128 }
129
130 PyObject *Request_remove_relation(RequestObject *self, PyObject *args) {
131 RelationObject *rel;
132
133 if (!PyArg_ParseTuple(args, "O", &rel)) {
134 /* XXX raise exception */
135 }
136
137 _Request_relation(self, SOLVER_ERASE, rel->_id);
138
139 Py_RETURN_NONE;
140 }
141
142 PyObject *Request_remove_name(RequestObject *self, PyObject *args) {
143 const char *name;
144
145 if (!PyArg_ParseTuple(args, "s", &name)) {
146 /* XXX raise exception */
147 }
148
149 Id _name = pool_str2id(self->_pool, name, 1);
150 _Request_name(self, SOLVER_ERASE, _name);
151
152 Py_RETURN_NONE;
153 }
154
155 PyObject *Request_update_solvable(RequestObject *self, PyObject *args) {
156 SolvableObject *solv;
157
158 if (!PyArg_ParseTuple(args, "O", &solv)) {
159 /* XXX raise exception */
160 }
161
162 _Request_solvable(self, SOLVER_UPDATE, solv->_id);
163
164 Py_RETURN_NONE;
165 }
166
167 PyObject *Request_update_relation(RequestObject *self, PyObject *args) {
168 RelationObject *rel;
169
170 if (!PyArg_ParseTuple(args, "O", &rel)) {
171 /* XXX raise exception */
172 }
173
174 _Request_relation(self, SOLVER_UPDATE, rel->_id);
175
176 Py_RETURN_NONE;
177 }
178
179 PyObject *Request_update_name(RequestObject *self, PyObject *args) {
180 const char *name;
181
182 if (!PyArg_ParseTuple(args, "s", &name)) {
183 /* XXX raise exception */
184 }
185
186 Id _name = pool_str2id(self->_pool, name, 1);
187 _Request_name(self, SOLVER_UPDATE, _name);
188
189 Py_RETURN_NONE;
190 }
191
192 PyObject *Request_lock_solvable(RequestObject *self, PyObject *args) {
193 SolvableObject *solv;
194
195 if (!PyArg_ParseTuple(args, "O", &solv)) {
196 /* XXX raise exception */
197 }
198
199 _Request_solvable(self, SOLVER_LOCK, solv->_id);
200
201 Py_RETURN_NONE;
202 }
203
204 PyObject *Request_lock_relation(RequestObject *self, PyObject *args) {
205 RelationObject *rel;
206
207 if (!PyArg_ParseTuple(args, "O", &rel)) {
208 /* XXX raise exception */
209 }
210
211 _Request_relation(self, SOLVER_LOCK, rel->_id);
212
213 Py_RETURN_NONE;
214 }
215
216 PyObject *Request_lock_name(RequestObject *self, PyObject *args) {
217 const char *name;
218
219 if (!PyArg_ParseTuple(args, "s", &name)) {
220 /* XXX raise exception */
221 }
222
223 Id _name = pool_str2id(self->_pool, name, 1);
224 _Request_name(self, SOLVER_LOCK, _name);
225
226 Py_RETURN_NONE;
227 }
228
229 PyObject *Request_noobsoletes_solvable(RequestObject *self, PyObject *args) {
230 SolvableObject *solv;
231
232 if (!PyArg_ParseTuple(args, "O", &solv)) {
233 /* XXX raise exception */
234 }
235
236 _Request_solvable(self, SOLVER_NOOBSOLETES, solv->_id);
237
238 Py_RETURN_NONE;
239 }
240
241 PyObject *Request_noobsoletes_relation(RequestObject *self, PyObject *args) {
242 RelationObject *rel;
243
244 if (!PyArg_ParseTuple(args, "O", &rel)) {
245 /* XXX raise exception */
246 }
247
248 _Request_relation(self, SOLVER_NOOBSOLETES, rel->_id);
249
250 Py_RETURN_NONE;
251 }
252
253 PyObject *Request_noobsoletes_name(RequestObject *self, PyObject *args) {
254 const char *name;
255
256 if (!PyArg_ParseTuple(args, "s", &name)) {
257 /* XXX raise exception */
258 }
259
260 Id _name = pool_str2id(self->_pool, name, 1);
261 _Request_name(self, SOLVER_NOOBSOLETES, _name);
262
263 Py_RETURN_NONE;
264 }