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