]> git.ipfire.org Git - pakfire.git/blob - python/src/request.c
Move C module to newer version of libsolv.
[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_push2(&self->_queue, what|SOLVER_SOLVABLE, solvable);
68 }
69
70 void _Request_relation(RequestObject *self, Id what, Id relation) {
71 queue_push2(&self->_queue, what|SOLVER_SOLVABLE_PROVIDES, relation);
72 }
73
74 void _Request_name(RequestObject *self, Id what, Id provides) {
75 queue_push2(&self->_queue, what|SOLVER_SOLVABLE_NAME, provides);
76 }
77
78 PyObject *Request_install_solvable(RequestObject *self, PyObject *args) {
79 SolvableObject *solv;
80
81 if (!PyArg_ParseTuple(args, "O", &solv)) {
82 return NULL;
83 }
84
85 _Request_solvable(self, SOLVER_INSTALL, solv->_id);
86 Py_RETURN_NONE;
87 }
88
89 PyObject *Request_install_relation(RequestObject *self, PyObject *args) {
90 RelationObject *rel;
91
92 if (!PyArg_ParseTuple(args, "O", &rel)) {
93 return NULL;
94 }
95
96 _Request_relation(self, SOLVER_INSTALL, rel->_id);
97 Py_RETURN_NONE;
98 }
99
100 PyObject *Request_install_name(RequestObject *self, PyObject *args) {
101 const char *name;
102
103 if (!PyArg_ParseTuple(args, "s", &name)) {
104 return NULL;
105 }
106
107 Id _name = pool_str2id(self->_pool, name, 1);
108 _Request_name(self, SOLVER_INSTALL, _name);
109
110 Py_RETURN_NONE;
111 }
112
113 PyObject *Request_remove_solvable(RequestObject *self, PyObject *args) {
114 SolvableObject *solv;
115
116 if (!PyArg_ParseTuple(args, "O", &solv)) {
117 return NULL;
118 }
119
120 _Request_solvable(self, SOLVER_ERASE, solv->_id);
121 Py_RETURN_NONE;
122 }
123
124 PyObject *Request_remove_relation(RequestObject *self, PyObject *args) {
125 RelationObject *rel;
126
127 if (!PyArg_ParseTuple(args, "O", &rel)) {
128 return NULL;
129 }
130
131 _Request_relation(self, SOLVER_ERASE, rel->_id);
132 Py_RETURN_NONE;
133 }
134
135 PyObject *Request_remove_name(RequestObject *self, PyObject *args) {
136 const char *name;
137
138 if (!PyArg_ParseTuple(args, "s", &name)) {
139 return NULL;
140 }
141
142 Id _name = pool_str2id(self->_pool, name, 1);
143 _Request_name(self, SOLVER_ERASE, _name);
144
145 Py_RETURN_NONE;
146 }
147
148 PyObject *Request_update_solvable(RequestObject *self, PyObject *args) {
149 SolvableObject *solv;
150
151 if (!PyArg_ParseTuple(args, "O", &solv)) {
152 return NULL;
153 }
154
155 _Request_solvable(self, SOLVER_UPDATE, solv->_id);
156 Py_RETURN_NONE;
157 }
158
159 PyObject *Request_update_relation(RequestObject *self, PyObject *args) {
160 RelationObject *rel;
161
162 if (!PyArg_ParseTuple(args, "O", &rel)) {
163 return NULL;
164 }
165
166 _Request_relation(self, SOLVER_UPDATE, rel->_id);
167 Py_RETURN_NONE;
168 }
169
170 PyObject *Request_update_name(RequestObject *self, PyObject *args) {
171 const char *name;
172
173 if (!PyArg_ParseTuple(args, "s", &name)) {
174 return NULL;
175 }
176
177 Id _name = pool_str2id(self->_pool, name, 1);
178 _Request_name(self, SOLVER_UPDATE, _name);
179
180 Py_RETURN_NONE;
181 }
182
183 PyObject *Request_lock_solvable(RequestObject *self, PyObject *args) {
184 SolvableObject *solv;
185
186 if (!PyArg_ParseTuple(args, "O", &solv)) {
187 return NULL;
188 }
189
190 _Request_solvable(self, SOLVER_LOCK, solv->_id);
191 Py_RETURN_NONE;
192 }
193
194 PyObject *Request_lock_relation(RequestObject *self, PyObject *args) {
195 RelationObject *rel;
196
197 if (!PyArg_ParseTuple(args, "O", &rel)) {
198 return NULL;
199 }
200
201 _Request_relation(self, SOLVER_LOCK, rel->_id);
202 Py_RETURN_NONE;
203 }
204
205 PyObject *Request_lock_name(RequestObject *self, PyObject *args) {
206 const char *name;
207
208 if (!PyArg_ParseTuple(args, "s", &name)) {
209 return NULL;
210 }
211
212 Id _name = pool_str2id(self->_pool, name, 1);
213 _Request_name(self, SOLVER_LOCK, _name);
214
215 Py_RETURN_NONE;
216 }
217
218 PyObject *Request_noobsoletes_solvable(RequestObject *self, PyObject *args) {
219 SolvableObject *solv;
220
221 if (!PyArg_ParseTuple(args, "O", &solv)) {
222 return NULL;
223 }
224
225 _Request_solvable(self, SOLVER_NOOBSOLETES, solv->_id);
226 Py_RETURN_NONE;
227 }
228
229 PyObject *Request_noobsoletes_relation(RequestObject *self, PyObject *args) {
230 RelationObject *rel;
231
232 if (!PyArg_ParseTuple(args, "O", &rel)) {
233 return NULL;
234 }
235
236 _Request_relation(self, SOLVER_NOOBSOLETES, rel->_id);
237 Py_RETURN_NONE;
238 }
239
240 PyObject *Request_noobsoletes_name(RequestObject *self, PyObject *args) {
241 const char *name;
242
243 if (!PyArg_ParseTuple(args, "s", &name)) {
244 return NULL;
245 }
246
247 Id _name = pool_str2id(self->_pool, name, 1);
248 _Request_name(self, SOLVER_NOOBSOLETES, _name);
249
250 Py_RETURN_NONE;
251 }
252
253 PyObject *Request_updateall(RequestObject *self, PyObject *args) {
254 queue_push2(&self->_queue, SOLVER_UPDATE|SOLVER_SOLVABLE_ALL, 0);
255 Py_RETURN_NONE;
256 }
257
258 PyObject *Request_distupgrade(RequestObject *self, PyObject *args) {
259 queue_push2(&self->_queue, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL, 0);
260 Py_RETURN_NONE;
261 }
262
263 PyObject *Request_verify(RequestObject *self, PyObject *args) {
264 queue_push2(&self->_queue, SOLVER_VERIFY|SOLVER_SOLVABLE_ALL, 0);
265 Py_RETURN_NONE;
266 }