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