]> git.ipfire.org Git - people/stevee/pakfire.git/blob - python/src/_pakfiremodule.c
Create an extra namespace for build environments and private network.
[people/stevee/pakfire.git] / python / src / _pakfiremodule.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 #ifndef _GNU_SOURCE
22 #define _GNU_SOURCE
23 #endif
24
25 #include <Python.h>
26
27 #include <locale.h>
28 #include <sched.h>
29 #include <sys/personality.h>
30
31 #include "capabilities.h"
32 #include "config.h"
33 #include "pool.h"
34 #include "problem.h"
35 #include "relation.h"
36 #include "repo.h"
37 #include "request.h"
38 #include "solution.h"
39 #include "solvable.h"
40 #include "solver.h"
41 #include "step.h"
42 #include "transaction.h"
43 #include "util.h"
44
45 static PyMethodDef pakfireModuleMethods[] = {
46 {"version_compare", (PyCFunction)version_compare, METH_VARARGS, NULL},
47 {"get_capabilities", (PyCFunction)get_capabilities, METH_VARARGS, NULL},
48 {"set_capabilities", (PyCFunction)set_capabilities, METH_VARARGS, NULL},
49 {"personality", (PyCFunction)_personality, METH_VARARGS, NULL},
50 {"sync", (PyCFunction)_sync, METH_NOARGS, NULL},
51 {"unshare", (PyCFunction)_unshare, METH_VARARGS, NULL},
52 { NULL, NULL, 0, NULL }
53 };
54
55 static PyMethodDef Pool_methods[] = {
56 {"prepare", (PyCFunction)Pool_prepare, METH_NOARGS, NULL},
57 {"size", (PyCFunction)Pool_size, METH_NOARGS, NULL},
58 {"set_installed", (PyCFunction)Pool_set_installed, METH_VARARGS, NULL},
59 {"providers", (PyCFunction)Pool_providers, METH_VARARGS, NULL},
60 {"search", (PyCFunction)Pool_search, METH_VARARGS, NULL},
61 { NULL, NULL, 0, NULL }
62 };
63
64 static PyMethodDef Problem_methods[] = {
65 {"get_rule", (PyCFunction)Problem_get_rule, METH_NOARGS, NULL},
66 {"get_source", (PyCFunction)Problem_get_source, METH_NOARGS, NULL},
67 {"get_target", (PyCFunction)Problem_get_target, METH_NOARGS, NULL},
68 {"get_dep", (PyCFunction)Problem_get_dep, METH_NOARGS, NULL},
69 {"get_solutions", (PyCFunction)Problem_get_solutions, METH_NOARGS, NULL},
70 { NULL, NULL, 0, NULL }
71 };
72
73 static PyMethodDef Request_methods[] = {
74 {"install_solvable", (PyCFunction)Request_install_solvable, METH_VARARGS, NULL},
75 {"install_relation", (PyCFunction)Request_install_relation, METH_VARARGS, NULL},
76 {"install_name", (PyCFunction)Request_install_name, METH_VARARGS, NULL},
77 {"remove_solvable", (PyCFunction)Request_remove_solvable, METH_VARARGS, NULL},
78 {"remove_relation", (PyCFunction)Request_remove_relation, METH_VARARGS, NULL},
79 {"remove_name", (PyCFunction)Request_remove_name, METH_VARARGS, NULL},
80 {"update_solvable", (PyCFunction)Request_update_solvable, METH_VARARGS, NULL},
81 {"update_relation", (PyCFunction)Request_update_relation, METH_VARARGS, NULL},
82 {"update_name", (PyCFunction)Request_update_name, METH_VARARGS, NULL},
83 {"lock_solvable", (PyCFunction)Request_lock_solvable, METH_VARARGS, NULL},
84 {"lock_relation", (PyCFunction)Request_lock_relation, METH_VARARGS, NULL},
85 {"lock_name", (PyCFunction)Request_lock_name, METH_VARARGS, NULL},
86 {"noobsoletes_solvable", (PyCFunction)Request_noobsoletes_solvable, METH_VARARGS, NULL},
87 {"noobsoletes_relation", (PyCFunction)Request_noobsoletes_relation, METH_VARARGS, NULL},
88 {"noobsoletes_name", (PyCFunction)Request_noobsoletes_name, METH_VARARGS, NULL},
89 {"updateall", (PyCFunction)Request_updateall, METH_NOARGS, NULL},
90 {"distupgrade", (PyCFunction)Request_distupgrade, METH_NOARGS, NULL},
91 {"verify", (PyCFunction)Request_verify, METH_NOARGS, NULL},
92 { NULL, NULL, 0, NULL }
93 };
94
95 static PyMethodDef Relation_methods[] = {
96 { NULL, NULL, 0, NULL }
97 };
98
99 static PyMethodDef Repo_methods[] = {
100 {"name", (PyCFunction)Repo_name, METH_NOARGS, NULL},
101 {"size", (PyCFunction)Repo_size, METH_NOARGS, NULL},
102 {"get_enabled", (PyCFunction)Repo_get_enabled, METH_NOARGS, NULL},
103 {"set_enabled", (PyCFunction)Repo_set_enabled, METH_VARARGS, NULL},
104 {"get_priority", (PyCFunction)Repo_get_priority, METH_NOARGS, NULL},
105 {"set_priority", (PyCFunction)Repo_set_priority, METH_VARARGS, NULL},
106 {"write", (PyCFunction)Repo_write, METH_VARARGS, NULL},
107 {"read", (PyCFunction)Repo_read, METH_VARARGS, NULL},
108 {"internalize", (PyCFunction)Repo_internalize, METH_NOARGS, NULL},
109 {"clear", (PyCFunction)Repo_clear, METH_NOARGS, NULL},
110 {"get_all", (PyCFunction)Repo_get_all, METH_NOARGS, NULL},
111 { NULL, NULL, 0, NULL }
112 };
113
114 static PyMethodDef Solvable_methods[] = {
115 {"get_name", (PyCFunction)Solvable_get_name, METH_NOARGS, NULL},
116 {"get_evr", (PyCFunction)Solvable_get_evr, METH_NOARGS, NULL},
117 {"get_arch", (PyCFunction)Solvable_get_arch, METH_NOARGS, NULL},
118 {"get_vendor", (PyCFunction)Solvable_get_vendor, METH_NOARGS, NULL},
119 {"set_vendor", (PyCFunction)Solvable_set_vendor, METH_VARARGS, NULL},
120 {"get_repo_name", (PyCFunction)Solvable_get_repo_name, METH_NOARGS, NULL},
121 {"get_uuid", (PyCFunction)Solvable_get_uuid, METH_NOARGS, NULL},
122 {"set_uuid", (PyCFunction)Solvable_set_uuid, METH_VARARGS, NULL},
123 {"get_hash1", (PyCFunction)Solvable_get_hash1, METH_NOARGS, NULL},
124 {"set_hash1", (PyCFunction)Solvable_set_hash1, METH_VARARGS, NULL},
125 {"get_summary", (PyCFunction)Solvable_get_summary, METH_NOARGS, NULL},
126 {"set_summary", (PyCFunction)Solvable_set_summary, METH_VARARGS, NULL},
127 {"get_description", (PyCFunction)Solvable_get_description, METH_NOARGS, NULL},
128 {"set_description", (PyCFunction)Solvable_set_description, METH_VARARGS, NULL},
129 {"get_groups", (PyCFunction)Solvable_get_groups, METH_NOARGS, NULL},
130 {"set_groups", (PyCFunction)Solvable_set_groups, METH_VARARGS, NULL},
131 {"get_url", (PyCFunction)Solvable_get_url, METH_NOARGS, NULL},
132 {"set_url", (PyCFunction)Solvable_set_url, METH_VARARGS, NULL},
133 {"get_filename", (PyCFunction)Solvable_get_filename, METH_NOARGS, NULL},
134 {"set_filename", (PyCFunction)Solvable_set_filename, METH_VARARGS, NULL},
135 {"get_license", (PyCFunction)Solvable_get_license, METH_NOARGS, NULL},
136 {"set_license", (PyCFunction)Solvable_set_license, METH_VARARGS, NULL},
137 {"get_buildhost", (PyCFunction)Solvable_get_buildhost, METH_NOARGS, NULL},
138 {"set_buildhost", (PyCFunction)Solvable_set_buildhost, METH_VARARGS, NULL},
139 {"get_maintainer", (PyCFunction)Solvable_get_maintainer, METH_NOARGS, NULL},
140 {"set_maintainer", (PyCFunction)Solvable_set_maintainer, METH_VARARGS, NULL},
141 {"get_downloadsize", (PyCFunction)Solvable_get_downloadsize, METH_NOARGS, NULL},
142 {"set_downloadsize", (PyCFunction)Solvable_set_downloadsize, METH_VARARGS, NULL},
143 {"get_installsize", (PyCFunction)Solvable_get_installsize, METH_NOARGS, NULL},
144 {"set_installsize", (PyCFunction)Solvable_set_installsize, METH_VARARGS, NULL},
145 {"get_buildtime", (PyCFunction)Solvable_get_buildtime, METH_NOARGS, NULL},
146 {"set_buildtime", (PyCFunction)Solvable_set_buildtime, METH_VARARGS, NULL},
147 {"add_provides", (PyCFunction)Solvable_add_provides, METH_VARARGS, NULL},
148 {"get_provides", (PyCFunction)Solvable_get_provides, METH_NOARGS, NULL},
149 {"add_requires", (PyCFunction)Solvable_add_requires, METH_VARARGS, NULL},
150 {"get_requires", (PyCFunction)Solvable_get_requires, METH_NOARGS, NULL},
151 {"add_obsoletes", (PyCFunction)Solvable_add_obsoletes, METH_VARARGS, NULL},
152 {"get_obsoletes", (PyCFunction)Solvable_get_obsoletes, METH_NOARGS, NULL},
153 {"add_conflicts", (PyCFunction)Solvable_add_conflicts, METH_VARARGS, NULL},
154 {"get_conflicts", (PyCFunction)Solvable_get_conflicts, METH_NOARGS, NULL},
155 {"add_recommends", (PyCFunction)Solvable_add_recommends, METH_VARARGS, NULL},
156 {"get_recommends", (PyCFunction)Solvable_get_recommends, METH_NOARGS, NULL},
157 {"add_suggests", (PyCFunction)Solvable_add_suggests, METH_VARARGS, NULL},
158 {"get_suggests", (PyCFunction)Solvable_get_suggests, METH_NOARGS, NULL},
159 { NULL, NULL, 0, NULL }
160 };
161
162 static PyMethodDef Solution_methods[] = {
163 { NULL, NULL, 0, NULL }
164 };
165
166 static PyMethodDef Solver_methods[] = {
167 {"solve", (PyCFunction)Solver_solve, METH_VARARGS, NULL},
168 {"get_flag", (PyCFunction)Solver_get_flag, METH_VARARGS, NULL},
169 {"set_flag", (PyCFunction)Solver_set_flag, METH_VARARGS, NULL},
170 {"get_allow_archchange", (PyCFunction)Solver_get_allow_archchange, METH_NOARGS, NULL},
171 {"set_allow_archchange", (PyCFunction)Solver_set_allow_archchange, METH_VARARGS, NULL},
172 {"get_allow_vendorchange", (PyCFunction)Solver_get_allow_vendorchange, METH_NOARGS, NULL},
173 {"set_allow_vendorchange", (PyCFunction)Solver_set_allow_vendorchange, METH_VARARGS, NULL},
174 {"get_allow_uninstall", (PyCFunction)Solver_get_allow_uninstall, METH_NOARGS, NULL},
175 {"set_allow_uninstall", (PyCFunction)Solver_set_allow_uninstall, METH_VARARGS, NULL},
176 {"get_updatesystem", (PyCFunction)Solver_get_updatesystem, METH_NOARGS, NULL},
177 {"set_updatesystem", (PyCFunction)Solver_set_updatesystem, METH_VARARGS, NULL},
178 {"get_do_split_provides", (PyCFunction)Solver_get_do_split_provides, METH_NOARGS, NULL},
179 {"set_do_split_provides", (PyCFunction)Solver_set_do_split_provides, METH_VARARGS, NULL},
180 {"get_problems", (PyCFunction)Solver_get_problems, METH_VARARGS, NULL},
181 { NULL, NULL, 0, NULL }
182 };
183
184 static PyMethodDef Step_methods[] = {
185 {"get_solvable", (PyCFunction)Step_get_solvable, METH_NOARGS, NULL},
186 {"get_type", (PyCFunction)Step_get_type, METH_NOARGS, NULL},
187 { NULL, NULL, 0, NULL }
188 };
189
190 static PyMethodDef Transaction_methods[] = {
191 {"steps", (PyCFunction)Transaction_steps, METH_NOARGS, NULL},
192 {"get_installsizechange", (PyCFunction)Transaction_get_installsizechange, METH_NOARGS, NULL},
193 { NULL, NULL, 0, NULL }
194 };
195
196 void init_pakfire(void) {
197 /* Initialize locale */
198 setlocale(LC_ALL, "");
199 bindtextdomain(TEXTDOMAIN, "/usr/share/locale");
200 textdomain(TEXTDOMAIN);
201
202 /* Load the python module */
203 PyObject *m, *d;
204
205 m = Py_InitModule("_pakfire", pakfireModuleMethods);
206
207 // Pool
208 PoolType.tp_methods = Pool_methods;
209 if (PyType_Ready(&PoolType) < 0)
210 return;
211 Py_INCREF(&PoolType);
212 PyModule_AddObject(m, "Pool", (PyObject *)&PoolType);
213
214 // Problem
215 ProblemType.tp_methods = Problem_methods;
216 if (PyType_Ready(&ProblemType) < 0)
217 return;
218 Py_INCREF(&ProblemType);
219 PyModule_AddObject(m, "Problem", (PyObject *)&ProblemType);
220
221 // Repo
222 RepoType.tp_methods = Repo_methods;
223 if (PyType_Ready(&RepoType) < 0)
224 return;
225 Py_INCREF(&RepoType);
226 PyModule_AddObject(m, "Repo", (PyObject *)&RepoType);
227
228 // Solvable
229 SolvableType.tp_methods = Solvable_methods;
230 if (PyType_Ready(&SolvableType) < 0)
231 return;
232 Py_INCREF(&SolvableType);
233 PyModule_AddObject(m, "Solvable", (PyObject *)&SolvableType);
234
235 // Relation
236 RelationType.tp_methods = Relation_methods;
237 if (PyType_Ready(&RelationType) < 0)
238 return;
239 Py_INCREF(&RelationType);
240 PyModule_AddObject(m, "Relation", (PyObject *)&RelationType);
241
242 // Request
243 RequestType.tp_methods = Request_methods;
244 if (PyType_Ready(&RequestType) < 0)
245 return;
246 Py_INCREF(&RequestType);
247 PyModule_AddObject(m, "Request", (PyObject *)&RequestType);
248
249 // Solution
250 SolutionType.tp_methods = Solution_methods;
251 if (PyType_Ready(&SolutionType) < 0)
252 return;
253 Py_INCREF(&SolutionType);
254 PyModule_AddObject(m, "Solution", (PyObject *)&SolutionType);
255
256 // Solver
257 SolverType.tp_methods = Solver_methods;
258 if (PyType_Ready(&SolverType) < 0)
259 return;
260 Py_INCREF(&SolverType);
261 PyModule_AddObject(m, "Solver", (PyObject *)&SolverType);
262
263 // Step
264 StepType.tp_methods = Step_methods;
265 if (PyType_Ready(&StepType) < 0)
266 return;
267 Py_INCREF(&StepType);
268 PyModule_AddObject(m, "Step", (PyObject *)&StepType);
269
270 // Transaction
271 TransactionType.tp_methods = Transaction_methods;
272 if (PyType_Ready(&TransactionType) < 0)
273 return;
274 Py_INCREF(&TransactionType);
275 PyModule_AddObject(m, "Transaction", (PyObject *)&TransactionType);
276
277 // Add constants
278 d = PyModule_GetDict(m);
279
280 // Personalities
281 PyDict_SetItemString(d, "PERSONALITY_LINUX", Py_BuildValue("i", PER_LINUX));
282 PyDict_SetItemString(d, "PERSONALITY_LINUX32", Py_BuildValue("i", PER_LINUX32));
283
284 // Namespace stuff
285 PyDict_SetItemString(d, "SCHED_CLONE_NEWIPC", Py_BuildValue("i", CLONE_NEWIPC));
286 PyDict_SetItemString(d, "SCHED_CLONE_NEWPID", Py_BuildValue("i", CLONE_NEWPID));
287 PyDict_SetItemString(d, "SCHED_CLONE_NEWNET", Py_BuildValue("i", CLONE_NEWNET));
288 PyDict_SetItemString(d, "SCHED_CLONE_NEWNS", Py_BuildValue("i", CLONE_NEWNS));
289 PyDict_SetItemString(d, "SCHED_CLONE_NEWUTS", Py_BuildValue("i", CLONE_NEWUTS));
290
291 // Add constants for relations
292 PyDict_SetItemString(d, "REL_EQ", Py_BuildValue("i", REL_EQ));
293 PyDict_SetItemString(d, "REL_LT", Py_BuildValue("i", REL_LT));
294 PyDict_SetItemString(d, "REL_GT", Py_BuildValue("i", REL_GT));
295 PyDict_SetItemString(d, "REL_LE", Py_BuildValue("i", REL_LT|REL_EQ));
296 PyDict_SetItemString(d, "REL_GE", Py_BuildValue("i", REL_GT|REL_EQ));
297
298 // Add constants for search
299 PyDict_SetItemString(d, "SEARCH_STRING", Py_BuildValue("i", SEARCH_STRING));
300 PyDict_SetItemString(d, "SEARCH_STRINGSTART", Py_BuildValue("i", SEARCH_STRINGSTART));
301 PyDict_SetItemString(d, "SEARCH_STRINGEND", Py_BuildValue("i", SEARCH_STRINGEND));
302 PyDict_SetItemString(d, "SEARCH_SUBSTRING", Py_BuildValue("i", SEARCH_SUBSTRING));
303 PyDict_SetItemString(d, "SEARCH_GLOB", Py_BuildValue("i", SEARCH_GLOB));
304 PyDict_SetItemString(d, "SEARCH_REGEX", Py_BuildValue("i", SEARCH_REGEX));
305 PyDict_SetItemString(d, "SEARCH_FILES", Py_BuildValue("i", SEARCH_FILES));
306 PyDict_SetItemString(d, "SEARCH_CHECKSUMS", Py_BuildValue("i", SEARCH_CHECKSUMS));
307
308 // Add constants for rules
309 PyDict_SetItemString(d, "SOLVER_RULE_DISTUPGRADE", Py_BuildValue("i", SOLVER_RULE_DISTUPGRADE));
310 PyDict_SetItemString(d, "SOLVER_RULE_INFARCH", Py_BuildValue("i", SOLVER_RULE_INFARCH));
311 PyDict_SetItemString(d, "SOLVER_RULE_UPDATE", Py_BuildValue("i", SOLVER_RULE_UPDATE));
312 PyDict_SetItemString(d, "SOLVER_RULE_JOB", Py_BuildValue("i", SOLVER_RULE_JOB));
313 PyDict_SetItemString(d, "SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP", Py_BuildValue("i", SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP));
314 PyDict_SetItemString(d, "SOLVER_RULE_RPM", Py_BuildValue("i", SOLVER_RULE_RPM));
315 PyDict_SetItemString(d, "SOLVER_RULE_RPM_NOT_INSTALLABLE", Py_BuildValue("i", SOLVER_RULE_RPM_NOT_INSTALLABLE));
316 PyDict_SetItemString(d, "SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP", Py_BuildValue("i", SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP));
317 PyDict_SetItemString(d, "SOLVER_RULE_RPM_SAME_NAME", Py_BuildValue("i", SOLVER_RULE_RPM_SAME_NAME));
318 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_CONFLICT", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_CONFLICT));
319 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_OBSOLETES));
320 PyDict_SetItemString(d, "SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES));
321 PyDict_SetItemString(d, "SOLVER_RULE_RPM_IMPLICIT_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_IMPLICIT_OBSOLETES));
322 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_REQUIRES", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_REQUIRES));
323 PyDict_SetItemString(d, "SOLVER_RULE_RPM_SELF_CONFLICT", Py_BuildValue("i", SOLVER_RULE_RPM_SELF_CONFLICT));
324 PyDict_SetItemString(d, "SOLVER_RULE_UNKNOWN", Py_BuildValue("i", SOLVER_RULE_UNKNOWN));
325 PyDict_SetItemString(d, "SOLVER_RULE_FEATURE", Py_BuildValue("i", SOLVER_RULE_FEATURE));
326 PyDict_SetItemString(d, "SOLVER_RULE_LEARNT", Py_BuildValue("i", SOLVER_RULE_LEARNT));
327 PyDict_SetItemString(d, "SOLVER_RULE_CHOICE", Py_BuildValue("i", SOLVER_RULE_CHOICE));
328
329 /* Solver flags */
330 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_DOWNGRADE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_DOWNGRADE));
331 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_ARCHCHANGE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_ARCHCHANGE));
332 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_VENDORCHANGE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_VENDORCHANGE));
333 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_UNINSTALL", Py_BuildValue("i", SOLVER_FLAG_ALLOW_UNINSTALL));
334 PyDict_SetItemString(d, "SOLVER_FLAG_NO_UPDATEPROVIDE", Py_BuildValue("i", SOLVER_FLAG_NO_UPDATEPROVIDE));
335 PyDict_SetItemString(d, "SOLVER_FLAG_SPLITPROVIDES", Py_BuildValue("i", SOLVER_FLAG_SPLITPROVIDES));
336 PyDict_SetItemString(d, "SOLVER_FLAG_IGNORE_RECOMMENDED", Py_BuildValue("i", SOLVER_FLAG_IGNORE_RECOMMENDED));
337 }