]> git.ipfire.org Git - pakfire.git/blob - src/_pakfire/_pakfiremodule.c
Move logging stuff away from Pakfire context
[pakfire.git] / src / _pakfire / _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 <libintl.h>
24 #include <locale.h>
25 #include <sched.h>
26 #include <sys/personality.h>
27
28 #include "archive.h"
29 #include "capabilities.h"
30 #include "constants.h"
31 #include "errors.h"
32 #include "key.h"
33 #include "package.h"
34 #include "pakfire.h"
35 #include "pool.h"
36 #include "problem.h"
37 #include "relation.h"
38 #include "repo.h"
39 #include "request.h"
40 #include "solution.h"
41 #include "solvable.h"
42 #include "step.h"
43 #include "transaction.h"
44 #include "util.h"
45
46 static PyMethodDef pakfireModuleMethods[] = {
47 {"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL},
48 {"version_compare", (PyCFunction)version_compare, METH_VARARGS, NULL},
49 {"get_capabilities", (PyCFunction)get_capabilities, METH_VARARGS, NULL},
50 {"set_capabilities", (PyCFunction)set_capabilities, METH_VARARGS, NULL},
51 {"personality", (PyCFunction)_personality, METH_VARARGS, NULL},
52 {"sync", (PyCFunction)_sync, METH_NOARGS, NULL},
53 {"unshare", (PyCFunction)_unshare, METH_VARARGS, NULL},
54 { NULL, NULL, 0, NULL }
55 };
56
57 static PyMethodDef Solvable_methods[] = {
58 {"get_name", (PyCFunction)Solvable_get_name, METH_NOARGS, NULL},
59 {"get_evr", (PyCFunction)Solvable_get_evr, METH_NOARGS, NULL},
60 {"get_arch", (PyCFunction)Solvable_get_arch, METH_NOARGS, NULL},
61 {"get_vendor", (PyCFunction)Solvable_get_vendor, METH_NOARGS, NULL},
62 {"set_vendor", (PyCFunction)Solvable_set_vendor, METH_VARARGS, NULL},
63 {"get_repo_name", (PyCFunction)Solvable_get_repo_name, METH_NOARGS, NULL},
64 {"get_uuid", (PyCFunction)Solvable_get_uuid, METH_NOARGS, NULL},
65 {"set_uuid", (PyCFunction)Solvable_set_uuid, METH_VARARGS, NULL},
66 {"get_hash1", (PyCFunction)Solvable_get_hash1, METH_NOARGS, NULL},
67 {"set_hash1", (PyCFunction)Solvable_set_hash1, METH_VARARGS, NULL},
68 {"get_summary", (PyCFunction)Solvable_get_summary, METH_NOARGS, NULL},
69 {"set_summary", (PyCFunction)Solvable_set_summary, METH_VARARGS, NULL},
70 {"get_description", (PyCFunction)Solvable_get_description, METH_NOARGS, NULL},
71 {"set_description", (PyCFunction)Solvable_set_description, METH_VARARGS, NULL},
72 {"get_groups", (PyCFunction)Solvable_get_groups, METH_NOARGS, NULL},
73 {"set_groups", (PyCFunction)Solvable_set_groups, METH_VARARGS, NULL},
74 {"get_url", (PyCFunction)Solvable_get_url, METH_NOARGS, NULL},
75 {"set_url", (PyCFunction)Solvable_set_url, METH_VARARGS, NULL},
76 {"get_filename", (PyCFunction)Solvable_get_filename, METH_NOARGS, NULL},
77 {"set_filename", (PyCFunction)Solvable_set_filename, METH_VARARGS, NULL},
78 {"get_license", (PyCFunction)Solvable_get_license, METH_NOARGS, NULL},
79 {"set_license", (PyCFunction)Solvable_set_license, METH_VARARGS, NULL},
80 {"get_buildhost", (PyCFunction)Solvable_get_buildhost, METH_NOARGS, NULL},
81 {"set_buildhost", (PyCFunction)Solvable_set_buildhost, METH_VARARGS, NULL},
82 {"get_maintainer", (PyCFunction)Solvable_get_maintainer, METH_NOARGS, NULL},
83 {"set_maintainer", (PyCFunction)Solvable_set_maintainer, METH_VARARGS, NULL},
84 {"get_downloadsize", (PyCFunction)Solvable_get_downloadsize, METH_NOARGS, NULL},
85 {"set_downloadsize", (PyCFunction)Solvable_set_downloadsize, METH_VARARGS, NULL},
86 {"get_installsize", (PyCFunction)Solvable_get_installsize, METH_NOARGS, NULL},
87 {"set_installsize", (PyCFunction)Solvable_set_installsize, METH_VARARGS, NULL},
88 {"get_buildtime", (PyCFunction)Solvable_get_buildtime, METH_NOARGS, NULL},
89 {"set_buildtime", (PyCFunction)Solvable_set_buildtime, METH_VARARGS, NULL},
90 {"add_provides", (PyCFunction)Solvable_add_provides, METH_VARARGS, NULL},
91 {"get_provides", (PyCFunction)Solvable_get_provides, METH_NOARGS, NULL},
92 {"add_requires", (PyCFunction)Solvable_add_requires, METH_VARARGS, NULL},
93 {"get_requires", (PyCFunction)Solvable_get_requires, METH_NOARGS, NULL},
94 {"add_obsoletes", (PyCFunction)Solvable_add_obsoletes, METH_VARARGS, NULL},
95 {"get_obsoletes", (PyCFunction)Solvable_get_obsoletes, METH_NOARGS, NULL},
96 {"add_conflicts", (PyCFunction)Solvable_add_conflicts, METH_VARARGS, NULL},
97 {"get_conflicts", (PyCFunction)Solvable_get_conflicts, METH_NOARGS, NULL},
98 {"add_recommends", (PyCFunction)Solvable_add_recommends, METH_VARARGS, NULL},
99 {"get_recommends", (PyCFunction)Solvable_get_recommends, METH_NOARGS, NULL},
100 {"add_suggests", (PyCFunction)Solvable_add_suggests, METH_VARARGS, NULL},
101 {"get_suggests", (PyCFunction)Solvable_get_suggests, METH_NOARGS, NULL},
102 { NULL, NULL, 0, NULL }
103 };
104
105 static struct PyModuleDef moduledef = {
106 .m_base = PyModuleDef_HEAD_INIT,
107 .m_name = "_pakfire",
108 .m_size = -1,
109 .m_methods = pakfireModuleMethods,
110 };
111
112 PyMODINIT_FUNC PyInit__pakfire(void) {
113 /* Initialize locale */
114 setlocale(LC_ALL, "");
115 bindtextdomain(PACKAGE_TARNAME, "/usr/share/locale");
116 textdomain(PACKAGE_TARNAME);
117
118 // Initialize the pakfire library
119 int r = pakfire_init();
120 if (r)
121 return NULL;
122
123 // Create the module
124 PyObject* module = PyModule_Create(&moduledef);
125 if (!module)
126 return NULL;
127
128 PyExc_BadSignatureError = PyErr_NewException("_pakfire.BadSignatureError", NULL, NULL);
129 Py_INCREF(PyExc_BadSignatureError);
130 PyModule_AddObject(module, "BadSignatureError", PyExc_BadSignatureError);
131
132 PyExc_DependencyError = PyErr_NewException("_pakfire.DependencyError", NULL, NULL);
133 Py_INCREF(PyExc_DependencyError);
134 PyModule_AddObject(module, "DependencyError", PyExc_DependencyError);
135
136 // Pakfire
137 if (PyType_Ready(&PakfireType) < 0)
138 return NULL;
139
140 Py_INCREF(&PakfireType);
141 PyModule_AddObject(module, "Pakfire", (PyObject *)&PakfireType);
142
143 // Archive
144 if (PyType_Ready(&ArchiveType) < 0)
145 return NULL;
146
147 Py_INCREF(&ArchiveType);
148 PyModule_AddObject(module, "Archive", (PyObject *)&ArchiveType);
149
150 // Archive Signature
151 if (PyType_Ready(&ArchiveSignatureType) < 0)
152 return NULL;
153
154 Py_INCREF(&ArchiveSignatureType);
155 PyModule_AddObject(module, "ArchiveSignature", (PyObject *)&ArchiveSignatureType);
156
157 // Key
158 if (PyType_Ready(&KeyType) < 0)
159 return NULL;
160
161 Py_INCREF(&KeyType);
162 PyModule_AddObject(module, "Key", (PyObject *)&KeyType);
163
164 // Package
165 if (PyType_Ready(&PackageType) < 0)
166 return NULL;
167
168 Py_INCREF(&PackageType);
169 PyModule_AddObject(module, "Package", (PyObject *)&PackageType);
170
171 // Pool
172 if (PyType_Ready(&PoolType) < 0)
173 return NULL;
174 Py_INCREF(&PoolType);
175 PyModule_AddObject(module, "Pool", (PyObject *)&PoolType);
176
177 // Problem
178 if (PyType_Ready(&ProblemType) < 0)
179 return NULL;
180 Py_INCREF(&ProblemType);
181 PyModule_AddObject(module, "Problem", (PyObject *)&ProblemType);
182
183 // Repo
184 if (PyType_Ready(&RepoType) < 0)
185 return NULL;
186
187 Py_INCREF(&RepoType);
188 PyModule_AddObject(module, "Repo", (PyObject *)&RepoType);
189
190 // Solvable
191 SolvableType.tp_methods = Solvable_methods;
192 if (PyType_Ready(&SolvableType) < 0)
193 return NULL;
194 Py_INCREF(&SolvableType);
195 PyModule_AddObject(module, "Solvable", (PyObject *)&SolvableType);
196
197 // Relation
198 if (PyType_Ready(&RelationType) < 0)
199 return NULL;
200
201 Py_INCREF(&RelationType);
202 PyModule_AddObject(module, "Relation", (PyObject *)&RelationType);
203
204 // Request
205 if (PyType_Ready(&RequestType) < 0)
206 return NULL;
207
208 Py_INCREF(&RequestType);
209 PyModule_AddObject(module, "Request", (PyObject *)&RequestType);
210
211 // Solution
212 if (PyType_Ready(&SolutionType) < 0)
213 return NULL;
214
215 Py_INCREF(&SolutionType);
216 PyModule_AddObject(module, "Solution", (PyObject *)&SolutionType);
217
218 // Step
219 if (PyType_Ready(&StepType) < 0)
220 return NULL;
221
222 Py_INCREF(&StepType);
223 PyModule_AddObject(module, "Step", (PyObject *)&StepType);
224
225 // Transaction
226 if (PyType_Ready(&TransactionType) < 0)
227 return NULL;
228
229 Py_INCREF(&TransactionType);
230 PyModule_AddObject(module, "Transaction", (PyObject *)&TransactionType);
231
232 // Transaction Iterator
233 if (PyType_Ready(&TransactionIteratorType) < 0)
234 return NULL;
235
236 Py_INCREF(&TransactionIteratorType);
237 PyModule_AddObject(module, "TransactionIterator", (PyObject *)&TransactionIteratorType);
238
239 // Add constants
240 PyObject* d = PyModule_GetDict(module);
241
242 // Personalities
243 PyDict_SetItemString(d, "PERSONALITY_LINUX", Py_BuildValue("i", PER_LINUX));
244 PyDict_SetItemString(d, "PERSONALITY_LINUX32", Py_BuildValue("i", PER_LINUX32));
245
246 // Namespace stuff
247 PyDict_SetItemString(d, "SCHED_CLONE_NEWIPC", Py_BuildValue("i", CLONE_NEWIPC));
248 PyDict_SetItemString(d, "SCHED_CLONE_NEWPID", Py_BuildValue("i", CLONE_NEWPID));
249 PyDict_SetItemString(d, "SCHED_CLONE_NEWNET", Py_BuildValue("i", CLONE_NEWNET));
250 PyDict_SetItemString(d, "SCHED_CLONE_NEWNS", Py_BuildValue("i", CLONE_NEWNS));
251 PyDict_SetItemString(d, "SCHED_CLONE_NEWUTS", Py_BuildValue("i", CLONE_NEWUTS));
252
253 // Add constants for relations
254 PyDict_SetItemString(d, "REL_EQ", Py_BuildValue("i", REL_EQ));
255 PyDict_SetItemString(d, "REL_LT", Py_BuildValue("i", REL_LT));
256 PyDict_SetItemString(d, "REL_GT", Py_BuildValue("i", REL_GT));
257 PyDict_SetItemString(d, "REL_LE", Py_BuildValue("i", REL_LT|REL_EQ));
258 PyDict_SetItemString(d, "REL_GE", Py_BuildValue("i", REL_GT|REL_EQ));
259
260 // Add constants for search
261 PyDict_SetItemString(d, "SEARCH_STRING", Py_BuildValue("i", SEARCH_STRING));
262 PyDict_SetItemString(d, "SEARCH_STRINGSTART", Py_BuildValue("i", SEARCH_STRINGSTART));
263 PyDict_SetItemString(d, "SEARCH_STRINGEND", Py_BuildValue("i", SEARCH_STRINGEND));
264 PyDict_SetItemString(d, "SEARCH_SUBSTRING", Py_BuildValue("i", SEARCH_SUBSTRING));
265 PyDict_SetItemString(d, "SEARCH_GLOB", Py_BuildValue("i", SEARCH_GLOB));
266 PyDict_SetItemString(d, "SEARCH_REGEX", Py_BuildValue("i", SEARCH_REGEX));
267 PyDict_SetItemString(d, "SEARCH_FILES", Py_BuildValue("i", SEARCH_FILES));
268 PyDict_SetItemString(d, "SEARCH_CHECKSUMS", Py_BuildValue("i", SEARCH_CHECKSUMS));
269
270 // Add constants for rules
271 PyDict_SetItemString(d, "SOLVER_RULE_DISTUPGRADE", Py_BuildValue("i", SOLVER_RULE_DISTUPGRADE));
272 PyDict_SetItemString(d, "SOLVER_RULE_INFARCH", Py_BuildValue("i", SOLVER_RULE_INFARCH));
273 PyDict_SetItemString(d, "SOLVER_RULE_UPDATE", Py_BuildValue("i", SOLVER_RULE_UPDATE));
274 PyDict_SetItemString(d, "SOLVER_RULE_JOB", Py_BuildValue("i", SOLVER_RULE_JOB));
275 PyDict_SetItemString(d, "SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP", Py_BuildValue("i", SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP));
276 PyDict_SetItemString(d, "SOLVER_RULE_RPM", Py_BuildValue("i", SOLVER_RULE_RPM));
277 PyDict_SetItemString(d, "SOLVER_RULE_RPM_NOT_INSTALLABLE", Py_BuildValue("i", SOLVER_RULE_RPM_NOT_INSTALLABLE));
278 PyDict_SetItemString(d, "SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP", Py_BuildValue("i", SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP));
279 PyDict_SetItemString(d, "SOLVER_RULE_RPM_SAME_NAME", Py_BuildValue("i", SOLVER_RULE_RPM_SAME_NAME));
280 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_CONFLICT", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_CONFLICT));
281 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_OBSOLETES));
282 PyDict_SetItemString(d, "SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES));
283 PyDict_SetItemString(d, "SOLVER_RULE_RPM_IMPLICIT_OBSOLETES", Py_BuildValue("i", SOLVER_RULE_RPM_IMPLICIT_OBSOLETES));
284 PyDict_SetItemString(d, "SOLVER_RULE_RPM_PACKAGE_REQUIRES", Py_BuildValue("i", SOLVER_RULE_RPM_PACKAGE_REQUIRES));
285 PyDict_SetItemString(d, "SOLVER_RULE_RPM_SELF_CONFLICT", Py_BuildValue("i", SOLVER_RULE_RPM_SELF_CONFLICT));
286 PyDict_SetItemString(d, "SOLVER_RULE_UNKNOWN", Py_BuildValue("i", SOLVER_RULE_UNKNOWN));
287 PyDict_SetItemString(d, "SOLVER_RULE_FEATURE", Py_BuildValue("i", SOLVER_RULE_FEATURE));
288 PyDict_SetItemString(d, "SOLVER_RULE_LEARNT", Py_BuildValue("i", SOLVER_RULE_LEARNT));
289 PyDict_SetItemString(d, "SOLVER_RULE_CHOICE", Py_BuildValue("i", SOLVER_RULE_CHOICE));
290
291 /* Solver flags */
292 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_DOWNGRADE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_DOWNGRADE));
293 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_ARCHCHANGE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_ARCHCHANGE));
294 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_VENDORCHANGE", Py_BuildValue("i", SOLVER_FLAG_ALLOW_VENDORCHANGE));
295 PyDict_SetItemString(d, "SOLVER_FLAG_ALLOW_UNINSTALL", Py_BuildValue("i", SOLVER_FLAG_ALLOW_UNINSTALL));
296 PyDict_SetItemString(d, "SOLVER_FLAG_NO_UPDATEPROVIDE", Py_BuildValue("i", SOLVER_FLAG_NO_UPDATEPROVIDE));
297 PyDict_SetItemString(d, "SOLVER_FLAG_SPLITPROVIDES", Py_BuildValue("i", SOLVER_FLAG_SPLITPROVIDES));
298 PyDict_SetItemString(d, "SOLVER_FLAG_IGNORE_RECOMMENDED", Py_BuildValue("i", SOLVER_FLAG_IGNORE_RECOMMENDED));
299
300 return module;
301 }