]> git.ipfire.org Git - people/stevee/pakfire.git/blob - python/src/transaction.c
611afe2079e405205ee3e5f2ae07685f3b5578e3
[people/stevee/pakfire.git] / python / src / transaction.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2011 Pakfire development team #
5 # #
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. #
10 # #
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. #
15 # #
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/>. #
18 # #
19 #############################################################################*/
20
21 #include <Python.h>
22
23 #include <solv/transaction.h>
24
25 #include "solver.h"
26 #include "step.h"
27 #include "transaction.h"
28
29 PyTypeObject TransactionType = {
30 PyObject_HEAD_INIT(NULL)
31 tp_name: "_pakfire.Transaction",
32 tp_basicsize: sizeof(TransactionObject),
33 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
34 tp_new : Transaction_new,
35 tp_dealloc: (destructor) Transaction_dealloc,
36 tp_doc: "Sat Transaction objects",
37 };
38
39 PyObject* Transaction_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
40 TransactionObject *self;
41 SolverObject *solver;
42
43 if (!PyArg_ParseTuple(args, "O", &solver)) {
44 /* XXX raise exception */
45 }
46
47 self = (TransactionObject *)type->tp_alloc(type, 0);
48 if (self != NULL) {
49 self->_pool = solver->_solver->pool;
50 if (self->_pool == NULL) {
51 Py_DECREF(self);
52 return NULL;
53 }
54
55 // Create a new transaction from the solver and order it.
56 self->_transaction = solver_create_transaction(solver->_solver);
57 transaction_order(self->_transaction, 0);
58 }
59
60 return (PyObject *)self;
61 }
62
63 PyObject *Transaction_dealloc(TransactionObject *self) {
64 /* XXX need to free self->_transaction */
65 self->ob_type->tp_free((PyObject *)self);
66
67 Py_RETURN_NONE;
68 }
69
70 PyObject *Transaction_steps(TransactionObject *self, PyObject *args) {
71 PyObject *list = PyList_New(0);
72
73 StepObject *step;
74 int i = 0;
75 for(; i < self->_transaction->steps.count; i++) {
76 step = PyObject_New(StepObject, &StepType);
77 step->_transaction = self->_transaction;
78 step->_id = self->_transaction->steps.elements[i];
79
80 PyList_Append(list, (PyObject *)step);
81 }
82
83 return list;
84 }
85
86 PyObject *Transaction_get_installsizechange(TransactionObject *self) {
87 int installsizechange = transaction_calc_installsizechange(self->_transaction);
88
89 return Py_BuildValue("i", installsizechange * 1024);
90 }