]>
Commit | Line | Data |
---|---|---|
c605d735 | 1 | |
ee6715aa MT |
2 | #include <Python.h> |
3 | ||
45f5a3d9 | 4 | #include <solv/transaction.h> |
ee6715aa | 5 | |
c605d735 MT |
6 | #include "solver.h" |
7 | #include "step.h" | |
8 | #include "transaction.h" | |
9 | ||
10 | PyTypeObject TransactionType = { | |
11 | PyObject_HEAD_INIT(NULL) | |
12 | tp_name: "_pakfire.Transaction", | |
13 | tp_basicsize: sizeof(TransactionObject), | |
14 | tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | |
15 | tp_new : Transaction_new, | |
16 | tp_dealloc: (destructor) Transaction_dealloc, | |
17 | tp_doc: "Sat Transaction objects", | |
18 | }; | |
19 | ||
20 | PyObject* Transaction_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { | |
21 | TransactionObject *self; | |
22 | SolverObject *solver; | |
23 | ||
24 | if (!PyArg_ParseTuple(args, "O", &solver)) { | |
25 | /* XXX raise exception */ | |
26 | } | |
27 | ||
28 | self = (TransactionObject *)type->tp_alloc(type, 0); | |
29 | if (self != NULL) { | |
30 | self->_pool = solver->_solver->pool; | |
31 | if (self->_pool == NULL) { | |
32 | Py_DECREF(self); | |
33 | return NULL; | |
34 | } | |
35 | ||
45f5a3d9 MT |
36 | // Create a new transaction from the solver and order it. |
37 | self->_transaction = solver_create_transaction(solver->_solver); | |
c605d735 MT |
38 | transaction_order(self->_transaction, 0); |
39 | } | |
40 | ||
41 | return (PyObject *)self; | |
42 | } | |
43 | ||
44 | PyObject *Transaction_dealloc(TransactionObject *self) { | |
45 | /* XXX need to free self->_transaction */ | |
46 | self->ob_type->tp_free((PyObject *)self); | |
4069d10c MT |
47 | |
48 | Py_RETURN_NONE; | |
c605d735 MT |
49 | } |
50 | ||
51 | PyObject *Transaction_steps(TransactionObject *self, PyObject *args) { | |
52 | PyObject *list = PyList_New(0); | |
53 | ||
54 | StepObject *step; | |
55 | int i = 0; | |
56 | for(; i < self->_transaction->steps.count; i++) { | |
57 | step = PyObject_New(StepObject, &StepType); | |
58 | step->_transaction = self->_transaction; | |
59 | step->_id = self->_transaction->steps.elements[i]; | |
60 | ||
61 | PyList_Append(list, (PyObject *)step); | |
62 | } | |
63 | ||
64 | Py_INCREF(list); // XXX do we need this here? | |
65 | return list; | |
66 | } | |
ee6715aa MT |
67 | |
68 | PyObject *Transaction_get_installsizechange(TransactionObject *self) { | |
69 | int installsizechange = transaction_calc_installsizechange(self->_transaction); | |
70 | ||
71 | return Py_BuildValue("i", installsizechange); | |
72 | } |