]> git.ipfire.org Git - people/stevee/pakfire.git/blame - src/_pakfire/relation.c
Use autotools.
[people/stevee/pakfire.git] / src / _pakfire / relation.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 "pool.h"
22#include "relation.h"
23
24#define REL_NONE 0
25
26PyTypeObject RelationType = {
27 PyObject_HEAD_INIT(NULL)
28 tp_name: "_pakfire.Relation",
29 tp_basicsize: sizeof(RelationObject),
30 tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
31 tp_new : Relation_new,
32 tp_dealloc: (destructor) Relation_dealloc,
33 tp_doc: "Sat Relation objects",
5168e648 34 tp_str: (reprfunc)Relation_string,
c605d735
MT
35};
36
37PyObject* Relation_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
38 RelationObject *self;
39 PoolObject *pool;
40 const char *name;
714392de 41 const char *evr = NULL;
c605d735
MT
42 int flags = 0;
43
44 if (!PyArg_ParseTuple(args, "Os|si", &pool, &name, &evr, &flags)) {
45 /* XXX raise exception */
714392de 46 return NULL;
c605d735
MT
47 }
48
49 Id _name = pool_str2id(pool->_pool, name, 1);
50
51 self = (RelationObject *)type->tp_alloc(type, 0);
52 if (self != NULL) {
53 if (flags == REL_NONE) {
54 self->_id = _name;
55 } else {
56 Id _evr = pool_str2id(pool->_pool, evr, 1);
57 self->_id = pool_rel2id(pool->_pool, _name, _evr, flags, 1);
58 }
59
60 self->_pool = pool->_pool;
61 }
62
63 return (PyObject *)self;
64}
65
66PyObject *Relation_dealloc(RelationObject *self) {
67 self->ob_type->tp_free((PyObject *)self);
714392de
MT
68
69 Py_RETURN_NONE;
c605d735 70}
5168e648
MT
71
72PyObject *Relation_string(RelationObject *self) {
73 return Py_BuildValue("s", pool_dep2str(self->_pool, self->_id));
74}