]> git.ipfire.org Git - pakfire.git/blob - src/pool.c
Bump version 0.9.9.
[pakfire.git] / src / pool.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 <Python.h>
22 #include <solv/poolarch.h>
23
24 #include "config.h"
25 #include "pool.h"
26 #include "relation.h"
27 #include "repo.h"
28 #include "solvable.h"
29
30 PyTypeObject PoolType = {
31 PyObject_HEAD_INIT(NULL)
32 tp_name: "_pakfire.Pool",
33 tp_basicsize: sizeof(PoolObject),
34 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
35 tp_new : Pool_new,
36 tp_dealloc: (destructor) Pool_dealloc,
37 tp_doc: "Sat Pool objects",
38 };
39
40 // Pool
41 PyObject* Pool_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
42 PoolObject *self;
43 const char *arch;
44
45 if (!PyArg_ParseTuple(args, "s", &arch)) {
46 /* XXX raise exception */
47 return NULL;
48 }
49
50 self = (PoolObject *)type->tp_alloc(type, 0);
51 if (self != NULL) {
52 self->_pool = pool_create();
53
54 #ifdef DEBUG
55 // Enable debug messages when DEBUG is defined.
56 pool_setdebuglevel(self->_pool, 1);
57 #endif
58
59 pool_setarch(self->_pool, arch);
60 if (self->_pool == NULL) {
61 Py_DECREF(self);
62 return NULL;
63 }
64 }
65
66 return (PyObject *)self;
67 }
68
69 PyObject *Pool_dealloc(PoolObject *self) {
70 pool_free(self->_pool);
71 self->ob_type->tp_free((PyObject *)self);
72
73 Py_RETURN_NONE;
74 }
75
76 PyObject *Pool_add_repo(PoolObject *self, PyObject *args) {
77 const char *name;
78 if (!PyArg_ParseTuple(args, "s", &name)) {
79 /* XXX raise exception */
80 }
81
82 RepoObject *repo;
83
84 repo = PyObject_New(RepoObject, &RepoType);
85 if (repo == NULL)
86 return NULL;
87
88 return (PyObject *)repo;
89 }
90
91 PyObject *Pool_prepare(PoolObject *self) {
92 _Pool_prepare(self->_pool);
93
94 Py_RETURN_NONE;
95 }
96
97 void _Pool_prepare(Pool *pool) {
98 pool_addfileprovides(pool);
99 pool_createwhatprovides(pool);
100
101 Repo *r;
102 int idx;
103 FOR_REPOS(idx, r) {
104 repo_internalize(r);
105 }
106 }
107
108 PyObject *Pool_size(PoolObject *self) {
109 Pool *pool = self->_pool;
110
111 return Py_BuildValue("i", pool->nsolvables);
112 }
113
114 PyObject *_Pool_search(Pool *pool, Repo *repo, const char *match, int option, const char *keyname) {
115 // Prepare the pool, so we can search in it.
116 _Pool_prepare(pool);
117
118 Dataiterator d;
119 dataiterator_init(&d, pool, repo, 0,
120 keyname && pool ? pool_str2id(pool, keyname, 0) : 0, match, option);
121
122 PyObject *list = PyList_New(0);
123
124 SolvableObject *solvable;
125 while (dataiterator_step(&d)) {
126 solvable = PyObject_New(SolvableObject, &SolvableType);
127 solvable->_pool = pool;
128 solvable->_id = d.solvid;
129
130 PyList_Append(list, (PyObject *)solvable);
131 }
132
133 dataiterator_free(&d);
134
135 Py_INCREF(list);
136 return list;
137 }
138
139 PyObject *Pool_search(PoolObject *self, PyObject *args) {
140 const char *match = NULL;
141 int option = SEARCH_SUBSTRING;
142 const char *keyname = NULL;
143
144 if (!PyArg_ParseTuple(args, "s|is", &match, &option, &keyname)) {
145 /* XXX raise exception */
146 return NULL;
147 }
148
149 return _Pool_search(self->_pool, NULL, match, option, keyname);
150 }
151
152 PyObject *Pool_set_installed(PoolObject *self, PyObject *args) {
153 RepoObject *repo;
154
155 if (!PyArg_ParseTuple(args, "O", &repo)) {
156 /* XXX raise exception */
157 }
158
159 pool_set_installed(self->_pool, repo->_repo);
160
161 Py_RETURN_NONE;
162 }
163
164 PyObject *Pool_providers(PoolObject *self, PyObject *args) {
165 RelationObject *relation;
166
167 if (!PyArg_ParseTuple(args, "O", &relation)) {
168 /* XXX raise exception */
169 return NULL;
170 }
171
172 Id id = relation->_id;
173
174 Pool *pool = self->_pool;
175 _Pool_prepare(pool);
176
177 PyObject *list = PyList_New(0);
178
179 Id p, pp;
180 SolvableObject *solvable;
181 FOR_PROVIDES(p, pp, id) {
182 solvable = PyObject_New(SolvableObject, &SolvableType);
183 solvable->_pool = self->_pool;
184 solvable->_id = p;
185
186 PyList_Append(list, (PyObject *)solvable);
187 }
188
189 return list;
190 }