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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/** \ingroup py_c
* \file python/spec-py.c
*/
#include "system.h"
#include "spec-py.h"
/** \ingroup python
* \name Class: Rpmspec
* \class Rpmspec
* \brief A python rpm.spec object represents an RPM spec file set.
*
* The spec file is at the heart of RPM's packaging building process. Similar
* in concept to a makefile, it contains information required by RPM to build
* the package, as well as instructions telling RPM how to build it. The spec
* file also dictates exactly what files are a part of the package, and where
* they should be installed.
*
* The rpm.spec object represents a parsed specfile to aid extraction of data.
*
* For example
* \code
* import rpm
* rpm.addMacro("_topdir","/path/to/topdir")
* ts=rpm.ts()
* s=ts.parseSpec("foo.spec")
* print s.prep()
* \endcode
*
* Macros set using add macro will be used allowing testing of conditional builds
*
*/
struct specObject_s {
PyObject_HEAD
/*type specific fields */
rpmSpec spec;
};
static void
spec_dealloc(specObject * s)
{
if (s->spec) {
s->spec=freeSpec(s->spec);
}
PyObject_Del(s);
}
static int
spec_print(specObject * s)
{
return 0;
}
/* XXX TODO return something sensible if spec exists but component (eg %clean)
* does not. Possibly "" or None */
static PyObject *
spec_get_buildroot(specObject * s)
{
rpmSpec spec = specFromSpec(s);
if (spec != NULL && spec->buildRoot) {
return Py_BuildValue("s", spec->buildRoot);
}
else {
return NULL;
}
}
static PyObject *
spec_get_prep(specObject * s)
{
rpmSpec spec = specFromSpec(s);
PyObject *res = NULL;
if (spec != NULL && spec->prep) {
res = Py_BuildValue("s",getStringBuf(spec->prep));
}
return res;
}
static PyObject *
spec_get_build(specObject * s)
{
rpmSpec spec = specFromSpec(s);
PyObject *res = NULL;
if (spec != NULL && spec->build) {
res = Py_BuildValue("s",getStringBuf(spec->build));
}
return res;
}
static PyObject *
spec_get_install(specObject * s)
{
rpmSpec spec = specFromSpec(s);
PyObject *res = NULL;
if (spec != NULL && spec->install) {
res = Py_BuildValue("s",getStringBuf(spec->install));
}
return res;
}
static PyObject *
spec_get_clean(specObject * s)
{
rpmSpec spec = specFromSpec(s);
PyObject *res = NULL;
if (spec != NULL && spec->clean) {
res = Py_BuildValue("s",getStringBuf(spec->clean));
}
return res;
}
static PyObject *
spec_get_sources(specObject *s)
{
struct Source * source;
PyObject *sourceList, *srcUrl;
rpmSpec spec;
char * fullSource;
sourceList = PyList_New(0);
spec = specFromSpec(s);
if ( spec != NULL) {
source = spec->sources;
while (source != NULL) {
fullSource = source->fullSource;
srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
PyList_Append(sourceList, srcUrl);
source=source->next;
}
return PyList_AsTuple(sourceList);
}
else {
return NULL;
}
}
/**
*/
static char spec_doc[] = "RPM Spec file object";
static PyMethodDef spec_Spec_methods[] = {
{"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
{"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
{"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
{"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
{"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
{"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
{NULL} /* Sentinel */
};
PyTypeObject spec_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"rpm.spec", /*tp_name*/
sizeof(specObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) spec_dealloc, /*tp_dealloc*/
(printfunc) spec_print, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
spec_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
spec_Spec_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
};
rpmSpec specFromSpec(specObject *s)
{
return s->spec;
}
PyObject *
spec_Wrap(rpmSpec spec)
{
specObject * s = PyObject_New(specObject, &spec_Type);
if (s == NULL)
return NULL;
s->spec = spec;
return (PyObject *) s;
}
|