]>
git.ipfire.org Git - people/stevee/pakfire.git/blob - src/_pakfire/pool.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
23 #include <solv/poolarch.h>
24 #include <solv/solver.h>
26 #include "constants.h"
32 PyTypeObject PoolType
= {
33 PyObject_HEAD_INIT(NULL
)
34 tp_name
: "_pakfire.Pool",
35 tp_basicsize
: sizeof(PoolObject
),
36 tp_flags
: Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
38 tp_dealloc
: (destructor
) Pool_dealloc
,
39 tp_doc
: "Sat Pool objects",
43 PyObject
* Pool_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
47 if (!PyArg_ParseTuple(args
, "s", &arch
)) {
48 /* XXX raise exception */
52 self
= (PoolObject
*)type
->tp_alloc(type
, 0);
54 self
->_pool
= pool_create();
57 // Enable debug messages when DEBUG is defined.
58 pool_setdebuglevel(self
->_pool
, 1);
61 pool_setarch(self
->_pool
, arch
);
62 if (self
->_pool
== NULL
) {
68 return (PyObject
*)self
;
71 PyObject
*Pool_dealloc(PoolObject
*self
) {
72 pool_free(self
->_pool
);
73 self
->ob_type
->tp_free((PyObject
*)self
);
78 PyObject
*Pool_add_repo(PoolObject
*self
, PyObject
*args
) {
80 if (!PyArg_ParseTuple(args
, "s", &name
)) {
81 /* XXX raise exception */
86 repo
= PyObject_New(RepoObject
, &RepoType
);
90 return (PyObject
*)repo
;
93 PyObject
*Pool_prepare(PoolObject
*self
) {
94 _Pool_prepare(self
->_pool
);
99 void _Pool_prepare(Pool
*pool
) {
100 pool_addfileprovides(pool
);
101 pool_createwhatprovides(pool
);
110 PyObject
*Pool_size(PoolObject
*self
) {
111 Pool
*pool
= self
->_pool
;
113 return Py_BuildValue("i", pool
->nsolvables
);
116 PyObject
*_Pool_search(Pool
*pool
, Repo
*repo
, const char *match
, int option
, const char *keyname
) {
117 // Prepare the pool, so we can search in it.
121 dataiterator_init(&d
, pool
, repo
, 0,
122 keyname
&& pool
? pool_str2id(pool
, keyname
, 0) : 0, match
, option
);
124 PyObject
*list
= PyList_New(0);
126 SolvableObject
*solvable
;
127 while (dataiterator_step(&d
)) {
128 solvable
= PyObject_New(SolvableObject
, &SolvableType
);
129 solvable
->_pool
= pool
;
130 solvable
->_id
= d
.solvid
;
132 PyList_Append(list
, (PyObject
*)solvable
);
135 dataiterator_free(&d
);
139 PyObject
*Pool_search(PoolObject
*self
, PyObject
*args
) {
140 const char *match
= NULL
;
141 int option
= SEARCH_SUBSTRING
;
142 const char *keyname
= NULL
;
144 if (!PyArg_ParseTuple(args
, "s|is", &match
, &option
, &keyname
)) {
145 /* XXX raise exception */
149 return _Pool_search(self
->_pool
, NULL
, match
, option
, keyname
);
152 PyObject
*Pool_set_installed(PoolObject
*self
, PyObject
*args
) {
155 if (!PyArg_ParseTuple(args
, "O", &repo
)) {
156 /* XXX raise exception */
159 pool_set_installed(self
->_pool
, repo
->_repo
);
164 PyObject
*Pool_providers(PoolObject
*self
, PyObject
*args
) {
168 Pool
*pool
= self
->_pool
;
172 if (!PyArg_ParseTuple(args
, "s", &name
)) {
179 Id id
= pool_str2id(pool
, name
, 0);
182 FOR_PROVIDES(p
, pp
, id
) {
183 solvable
= pool
->solvables
+ p
;
185 if (solvable
->name
== id
)
186 queue_push2(&job
, SOLVER_SOLVABLE
, p
);
190 for (p
= 1; p
< pool
->nsolvables
; p
++) {
191 solvable
= pool
->solvables
+ p
;
192 if (!solvable
->repo
|| !pool_installable(pool
, solvable
))
196 if (fnmatch(name
, pool_id2str(pool
, id
), 0) == 0) {
197 for (i
= 0; i
< job
.count
; i
+= 2) {
198 if (job
.elements
[i
] == SOLVER_SOLVABLE
&& job
.elements
[i
+ 1] == id
)
203 queue_push2(&job
, SOLVER_SOLVABLE
, p
);
207 for (id
= 1; id
< pool
->ss
.nstrings
; id
++) {
208 if (!pool
->whatprovides
[id
])
211 if (fnmatch(name
, pool_id2str(pool
, id
), 0) == 0) {
212 Id
*provides
= pool
->whatprovidesdata
+ pool
->whatprovides
[id
];
215 for (i
= 0; i
< job
.count
; i
+= 2) {
216 if (job
.elements
[i
] == SOLVER_SOLVABLE
&& job
.elements
[i
+ 1] == *provides
)
221 queue_push2(&job
, SOLVER_SOLVABLE
, *provides
);
229 PyObject
*list
= PyList_New(0);
231 for (i
= 0; i
< job
.count
; i
+= 2) {
232 switch (job
.elements
[i
]) {
233 case SOLVER_SOLVABLE
:
234 s
= PyObject_New(SolvableObject
, &SolvableType
);
236 s
->_id
= job
.elements
[i
+ 1];
238 PyList_Append(list
, (PyObject
*)s
);