summaryrefslogtreecommitdiff
path: root/python/rpmmacro-py.c
blob: a056998d201fb9bde17ec9e7f135e020435acec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** \ingroup py_c
 * \file python/rpmmacro-py.c
 */

#include "system.h"

#include <structmember.h>

#include <rpm/rpmmacro.h>

#include "rpmmacro-py.h"

#include "debug.h"

/**
 */
PyObject *
rpmmacro_AddMacro(PyObject * self, PyObject * args, PyObject * kwds)
{
    char * name, * val;
    char * kwlist[] = {"name", "value", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss:AddMacro", kwlist,
	    &name, &val))
	return NULL;

    addMacro(NULL, name, NULL, val, -1);

    Py_INCREF(Py_None);
    return Py_None;
}

/**
 */
PyObject *
rpmmacro_DelMacro(PyObject * self, PyObject * args, PyObject * kwds)
{
    char * name;
    char * kwlist[] = {"name", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:DelMacro", kwlist, &name))
	return NULL;

    delMacro(NULL, name);

    Py_INCREF(Py_None);
    return Py_None;
}

/**
 */
PyObject * 
rpmmacro_ExpandMacro(PyObject * self, PyObject * args, PyObject * kwds)
{
    char *macro, *str;
    PyObject *res;

    if (!PyArg_ParseTuple(args, "s", &macro))
        return NULL;

    str = rpmExpand(macro, NULL);
    res = Py_BuildValue("s", str);
    free(str);
    return res;
}