]>
git.ipfire.org Git - people/ms/pakfire.git/blob - src/repo.c
5 #include <solv/repo_solv.h>
6 #include <solv/repo_write.h>
12 PyTypeObject RepoType
= {
13 PyObject_HEAD_INIT(NULL
)
14 tp_name
: "_pakfire.Repo",
15 tp_basicsize
: sizeof(RepoObject
),
16 tp_flags
: Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
18 tp_dealloc
: (destructor
) Repo_dealloc
,
19 tp_doc
: "Sat Repo objects",
22 PyObject
* Repo_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
) {
28 if (!PyArg_ParseTuple(args
, "Os", &pool
, &name
)) {
29 /* XXX raise exception */
36 self
= (RepoObject
*)type
->tp_alloc(type
, 0);
38 self
->_repo
= repo_create(pool
->_pool
, name
);
39 if (self
->_repo
== NULL
) {
45 return (PyObject
*)self
;
48 PyObject
*Repo_dealloc(RepoObject
*self
) {
49 // repo_free(self->_repo, 0);
50 self
->ob_type
->tp_free((PyObject
*)self
);
55 PyObject
*Repo_name(RepoObject
*self
) {
56 Repo
*repo
= self
->_repo
;
58 return Py_BuildValue("s", repo
->name
);
61 PyObject
*Repo_size(RepoObject
*self
) {
62 Repo
*repo
= self
->_repo
;
64 return Py_BuildValue("i", repo
->nsolvables
);
67 PyObject
*Repo_get_enabled(RepoObject
*self
) {
68 if (self
->_repo
->disabled
== 0) {
75 PyObject
*Repo_set_enabled(RepoObject
*self
, PyObject
*args
) {
78 if (!PyArg_ParseTuple(args
, "b", &enabled
)) {
79 /* XXX raise exception */
83 if (enabled
== true) {
84 self
->_repo
->disabled
= 0;
86 self
->_repo
->disabled
= 1;
92 PyObject
*Repo_get_priority(RepoObject
*self
) {
93 return Py_BuildValue("i", self
->_repo
->priority
);
96 PyObject
*Repo_set_priority(RepoObject
*self
, PyObject
*args
) {
99 if (!PyArg_ParseTuple(args
, "i", &priority
)) {
100 /* XXX raise exception */
104 self
->_repo
->priority
= priority
;
109 PyObject
*Repo_write(RepoObject
*self
, PyObject
*args
) {
110 const char *filename
;
112 if (!PyArg_ParseTuple(args
, "s", &filename
)) {
113 /* XXX raise exception */
116 // Prepare the pool and internalize all attributes.
117 _Pool_prepare(self
->_repo
->pool
);
119 // XXX catch if file cannot be opened
120 FILE *fp
= fopen(filename
, "wb");
122 repo_write(self
->_repo
, fp
, NULL
, NULL
, 0);
129 PyObject
*Repo_read(RepoObject
*self
, PyObject
*args
) {
130 const char *filename
;
132 if (!PyArg_ParseTuple(args
, "s", &filename
)) {
133 /* XXX raise exception */
136 // XXX catch if file cannot be opened
137 FILE *fp
= fopen(filename
, "rb");
139 repo_add_solv(self
->_repo
, fp
);
146 PyObject
*Repo_clear(RepoObject
*self
) {
147 repo_empty(self
->_repo
, 1);
152 PyObject
*Repo_get_all(RepoObject
*self
) {
155 Repo
*r
= self
->_repo
;
157 PyObject
*list
= PyList_New(0);
159 FOR_REPO_SOLVABLES(r
, p
, s
) {
160 SolvableObject
*solv
;
162 solv
= PyObject_New(SolvableObject
, &SolvableType
);
166 solv
->_pool
= self
->_repo
->pool
;
169 PyList_Append(list
, (PyObject
*)solv
);