1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
26 #include <sys/personality.h>
29 #include "capabilities.h"
30 #include "constants.h"
43 #include "transaction.h"
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
}
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
}
105 static struct PyModuleDef moduledef
= {
106 .m_base
= PyModuleDef_HEAD_INIT
,
107 .m_name
= "_pakfire",
109 .m_methods
= pakfireModuleMethods
,
112 PyMODINIT_FUNC
PyInit__pakfire(void) {
113 /* Initialize locale */
114 setlocale(LC_ALL
, "");
115 bindtextdomain(PACKAGE_TARNAME
, "/usr/share/locale");
116 textdomain(PACKAGE_TARNAME
);
118 // Initialize the pakfire library
119 int r
= pakfire_init();
124 PyObject
* module
= PyModule_Create(&moduledef
);
128 PyExc_BadSignatureError
= PyErr_NewException("_pakfire.BadSignatureError", NULL
, NULL
);
129 Py_INCREF(PyExc_BadSignatureError
);
130 PyModule_AddObject(module
, "BadSignatureError", PyExc_BadSignatureError
);
132 PyExc_DependencyError
= PyErr_NewException("_pakfire.DependencyError", NULL
, NULL
);
133 Py_INCREF(PyExc_DependencyError
);
134 PyModule_AddObject(module
, "DependencyError", PyExc_DependencyError
);
137 if (PyType_Ready(&PakfireType
) < 0)
140 Py_INCREF(&PakfireType
);
141 PyModule_AddObject(module
, "Pakfire", (PyObject
*)&PakfireType
);
144 if (PyType_Ready(&ArchiveType
) < 0)
147 Py_INCREF(&ArchiveType
);
148 PyModule_AddObject(module
, "Archive", (PyObject
*)&ArchiveType
);
151 if (PyType_Ready(&ArchiveSignatureType
) < 0)
154 Py_INCREF(&ArchiveSignatureType
);
155 PyModule_AddObject(module
, "ArchiveSignature", (PyObject
*)&ArchiveSignatureType
);
158 if (PyType_Ready(&KeyType
) < 0)
162 PyModule_AddObject(module
, "Key", (PyObject
*)&KeyType
);
165 if (PyType_Ready(&PackageType
) < 0)
168 Py_INCREF(&PackageType
);
169 PyModule_AddObject(module
, "Package", (PyObject
*)&PackageType
);
172 if (PyType_Ready(&PoolType
) < 0)
174 Py_INCREF(&PoolType
);
175 PyModule_AddObject(module
, "Pool", (PyObject
*)&PoolType
);
178 if (PyType_Ready(&ProblemType
) < 0)
180 Py_INCREF(&ProblemType
);
181 PyModule_AddObject(module
, "Problem", (PyObject
*)&ProblemType
);
184 if (PyType_Ready(&RepoType
) < 0)
187 Py_INCREF(&RepoType
);
188 PyModule_AddObject(module
, "Repo", (PyObject
*)&RepoType
);
191 SolvableType
.tp_methods
= Solvable_methods
;
192 if (PyType_Ready(&SolvableType
) < 0)
194 Py_INCREF(&SolvableType
);
195 PyModule_AddObject(module
, "Solvable", (PyObject
*)&SolvableType
);
198 if (PyType_Ready(&RelationType
) < 0)
201 Py_INCREF(&RelationType
);
202 PyModule_AddObject(module
, "Relation", (PyObject
*)&RelationType
);
205 if (PyType_Ready(&RequestType
) < 0)
208 Py_INCREF(&RequestType
);
209 PyModule_AddObject(module
, "Request", (PyObject
*)&RequestType
);
212 if (PyType_Ready(&SolutionType
) < 0)
215 Py_INCREF(&SolutionType
);
216 PyModule_AddObject(module
, "Solution", (PyObject
*)&SolutionType
);
219 if (PyType_Ready(&StepType
) < 0)
222 Py_INCREF(&StepType
);
223 PyModule_AddObject(module
, "Step", (PyObject
*)&StepType
);
226 if (PyType_Ready(&TransactionType
) < 0)
229 Py_INCREF(&TransactionType
);
230 PyModule_AddObject(module
, "Transaction", (PyObject
*)&TransactionType
);
232 // Transaction Iterator
233 if (PyType_Ready(&TransactionIteratorType
) < 0)
236 Py_INCREF(&TransactionIteratorType
);
237 PyModule_AddObject(module
, "TransactionIterator", (PyObject
*)&TransactionIteratorType
);
240 PyObject
* d
= PyModule_GetDict(module
);
243 PyDict_SetItemString(d
, "PERSONALITY_LINUX", Py_BuildValue("i", PER_LINUX
));
244 PyDict_SetItemString(d
, "PERSONALITY_LINUX32", Py_BuildValue("i", PER_LINUX32
));
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
));
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
));
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
));
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
));
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
));