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