]> git.ipfire.org Git - pakfire.git/blame - src/_pakfire/step.c
Use autotools.
[pakfire.git] / src / _pakfire / step.c
CommitLineData
b792d887
MT
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#############################################################################*/
c605d735
MT
20
21#include "solvable.h"
22#include "step.h"
23#include "transaction.h"
24
25PyTypeObject StepType = {
26 PyObject_HEAD_INIT(NULL)
27 tp_name: "_pakfire.Step",
28 tp_basicsize: sizeof(StepObject),
29 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
30 tp_new : Step_new,
31 tp_dealloc: (destructor) Step_dealloc,
32 tp_doc: "Sat Step objects",
33};
34
35PyObject* Step_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
36 StepObject *self;
37 TransactionObject *transaction;
38 int num;
39
40 if (!PyArg_ParseTuple(args, "Oi", &transaction, &num)) {
41 /* XXX raise exception */
42 }
43
44 self = (StepObject *)type->tp_alloc(type, 0);
45 if (self != NULL) {
46 self->_transaction = transaction->_transaction;
47
48 if (num >= transaction->_transaction->steps.count) {
49 Py_DECREF(self);
50 return NULL;
51 }
52
53 self->_id = transaction->_transaction->steps.elements[num];
54 }
55
56 return (PyObject *)self;
57}
58
59PyObject *Step_dealloc(StepObject *self) {
60 self->ob_type->tp_free((PyObject *)self);
4069d10c
MT
61
62 Py_RETURN_NONE;
c605d735
MT
63}
64
65PyObject *Step_get_solvable(StepObject *self, PyObject *args) {
66 SolvableObject *solvable;
67
68 solvable = PyObject_New(SolvableObject, &SolvableType);
69 if (solvable == NULL)
70 return NULL;
71
72 solvable->_pool = self->_transaction->pool;
73 solvable->_id = self->_id;
74
75 return (PyObject *)solvable;
76}
77
78PyObject *Step_get_type(StepObject *self, PyObject *args) {
79 const char *type = "unknown";
80
81 int trans_type = transaction_type(self->_transaction, self->_id,
55a45dcb 82 SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_CHANGE_IS_REINSTALL);
c605d735
MT
83
84 switch(trans_type) {
85 case SOLVER_TRANSACTION_IGNORE:
86 type = "ignore";
87 break;
88
89 case SOLVER_TRANSACTION_ERASE:
90 type = "erase";
91 break;
92
93 case SOLVER_TRANSACTION_REINSTALLED:
94 type = "reinstalled";
95 break;
96
97 case SOLVER_TRANSACTION_DOWNGRADED:
98 type = "downgraded";
99 break;
100
101 case SOLVER_TRANSACTION_CHANGED:
102 type = "changed";
103 break;
104
105 case SOLVER_TRANSACTION_UPGRADED:
106 type = "upgraded";
107 break;
108
109 case SOLVER_TRANSACTION_OBSOLETED:
110 type = "obsoleted";
111 break;
112
113 case SOLVER_TRANSACTION_INSTALL:
114 type = "install";
115 break;
116
117 case SOLVER_TRANSACTION_REINSTALL:
118 type = "reinstall";
119 break;
120
121 case SOLVER_TRANSACTION_DOWNGRADE:
122 type = "downgrade";
123 break;
124
125 case SOLVER_TRANSACTION_CHANGE:
126 type = "change";
127 break;
128
129 case SOLVER_TRANSACTION_UPGRADE:
130 type = "upgrade";
131 break;
132
133 case SOLVER_TRANSACTION_OBSOLETES:
134 type = "obsoletes";
135 break;
136
137 case SOLVER_TRANSACTION_MULTIINSTALL:
138 type = "multiinstall";
139 break;
140
141 case SOLVER_TRANSACTION_MULTIREINSTALL:
142 type = "multireinstall";
143 break;
144
145 default:
146 break;
147 }
148
149 return Py_BuildValue("s", type);
150}