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