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