]>
git.ipfire.org Git - people/stevee/pakfire.git/blob - python/src/repo.c
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 <solv/repo.h>
25 #include <solv/repo_solv.h>
26 #include <solv/repo_write.h>
33 PyTypeObject RepoType
= {
34 PyObject_HEAD_INIT(NULL
)
35 tp_name
: "_pakfire.Repo",
36 tp_basicsize
: sizeof(RepoObject
),
37 tp_flags
: Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
39 tp_dealloc
: (destructor
) Repo_dealloc
,
40 tp_doc
: "Sat Repo objects",
43 PyObject
* Repo_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
49 if (!PyArg_ParseTuple(args
, "Os", &pool
, &name
)) {
56 self
= (RepoObject
*)type
->tp_alloc(type
, 0);
58 self
->_repo
= repo_create(pool
->_pool
, name
);
59 if (self
->_repo
== NULL
) {
65 return (PyObject
*)self
;
68 PyObject
*Repo_dealloc(RepoObject
*self
) {
69 self
->ob_type
->tp_free((PyObject
*)self
);
74 PyObject
*Repo_name(RepoObject
*self
) {
75 Repo
*repo
= self
->_repo
;
77 return Py_BuildValue("s", repo
->name
);
80 PyObject
*Repo_size(RepoObject
*self
) {
81 Repo
*repo
= self
->_repo
;
83 return Py_BuildValue("i", repo
->nsolvables
);
86 PyObject
*Repo_get_enabled(RepoObject
*self
) {
87 if (self
->_repo
->disabled
== 0) {
94 PyObject
*Repo_set_enabled(RepoObject
*self
, PyObject
*args
) {
97 if (!PyArg_ParseTuple(args
, "b", &enabled
)) {
101 if (enabled
== true) {
102 self
->_repo
->disabled
= 0;
104 self
->_repo
->disabled
= 1;
110 PyObject
*Repo_get_priority(RepoObject
*self
) {
111 return Py_BuildValue("i", self
->_repo
->priority
);
114 PyObject
*Repo_set_priority(RepoObject
*self
, PyObject
*args
) {
117 if (!PyArg_ParseTuple(args
, "i", &priority
)) {
118 /* XXX raise exception */
122 self
->_repo
->priority
= priority
;
127 PyObject
*Repo_write(RepoObject
*self
, PyObject
*args
) {
128 const char *filename
;
129 char exception
[STRING_SIZE
];
131 if (!PyArg_ParseTuple(args
, "s", &filename
)) {
135 // Prepare the pool and internalize all attributes.
136 //_Pool_prepare(self->_repo->pool);
139 if ((fp
= fopen(filename
, "wb")) == NULL
) {
140 snprintf(exception
, STRING_SIZE
- 1, "Could not open file for writing: %s (%s).",
141 filename
, strerror(errno
));
142 PyErr_SetString(PyExc_RuntimeError
, exception
);
146 repo_write(self
->_repo
, fp
);
152 PyObject
*Repo_read(RepoObject
*self
, PyObject
*args
) {
153 const char *filename
;
155 if (!PyArg_ParseTuple(args
, "s", &filename
)) {
159 // XXX catch if file cannot be opened
160 FILE *fp
= fopen(filename
, "rb");
161 repo_add_solv(self
->_repo
, fp
, 0);
167 PyObject
*Repo_internalize(RepoObject
*self
) {
168 repo_internalize(self
->_repo
);
173 PyObject
*Repo_clear(RepoObject
*self
) {
174 repo_empty(self
->_repo
, 1);
179 PyObject
*Repo_get_all(RepoObject
*self
) {
182 Repo
*r
= self
->_repo
;
185 assert(r
->pool
!= NULL
);
187 PyObject
*list
= PyList_New(0);
189 FOR_REPO_SOLVABLES(r
, p
, s
) {
190 SolvableObject
*solv
;
192 solv
= PyObject_New(SolvableObject
, &SolvableType
);
196 solv
->_pool
= r
->pool
;
199 PyList_Append(list
, (PyObject
*)solv
);