2 * \file python/spec-py.c
10 * \name Class: Rpmspec
12 * \brief A python rpm.spec object represents an RPM spec file set.
14 * The spec file is at the heart of RPM's packaging building process. Similar
15 * in concept to a makefile, it contains information required by RPM to build
16 * the package, as well as instructions telling RPM how to build it. The spec
17 * file also dictates exactly what files are a part of the package, and where
18 * they should be installed.
20 * The rpm.spec object represents a parsed specfile to aid extraction of data.
25 * rpm.addMacro("_topdir","/path/to/topdir")
27 * s=ts.parseSpec("foo.spec")
31 * Macros set using add macro will be used allowing testing of conditional builds
37 spec_dealloc(specObject * s)
40 s->spec=freeSpec(s->spec);
46 spec_print(specObject * s)
51 /* XXX TODO return something sensible if spec exists but component (eg %clean)
52 * does not. Possibly "" or None */
55 spec_get_buildroot(specObject * s)
57 rpmSpec spec = specFromSpec(s);
58 if (spec != NULL && spec->buildRootURL) {
59 return Py_BuildValue("s", spec->buildRootURL);
67 spec_get_prep(specObject * s)
69 rpmSpec spec = specFromSpec(s);
70 if (spec != NULL && spec->prep) {
71 StringBuf sb = newStringBuf();
73 return Py_BuildValue("s",getStringBuf(sb));
81 spec_get_build(specObject * s)
83 rpmSpec spec = specFromSpec(s);
84 if (spec != NULL && spec->build) {
85 StringBuf sb = newStringBuf();
87 return Py_BuildValue("s",getStringBuf(sb));
95 spec_get_install(specObject * s)
97 rpmSpec spec = specFromSpec(s);
98 if (spec != NULL && spec->install) {
99 StringBuf sb = newStringBuf();
101 return Py_BuildValue("s",getStringBuf(sb));
109 spec_get_clean(specObject * s)
111 rpmSpec spec = specFromSpec(s);
112 if (spec != NULL && spec->clean) {
113 StringBuf sb = newStringBuf();
115 return Py_BuildValue("s",getStringBuf(sb));
123 spec_get_sources(specObject *s)
125 struct Source * source;
126 PyObject *sourceList, *srcUrl;
130 sourceList = PyList_New(0);
131 spec = specFromSpec(s);
133 source = spec->sources;
135 while (source != NULL) {
136 fullSource = source->fullSource;
137 srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
138 PyList_Append(sourceList, srcUrl);
142 return PyList_AsTuple(sourceList);
153 static char spec_doc[] = "RPM Spec file object";
155 static PyMethodDef spec_Spec_methods[] = {
156 {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
157 {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
158 {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
159 {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
160 {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
161 {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
162 {NULL} /* Sentinel */
165 PyTypeObject spec_Type = {
166 PyObject_HEAD_INIT(&PyType_Type)
168 "rpm.spec", /*tp_name*/
169 sizeof(specObject), /*tp_basicsize*/
171 (destructor) spec_dealloc, /*tp_dealloc*/
172 (printfunc) spec_print, /*tp_print*/
178 0, /*tp_as_sequence*/
186 Py_TPFLAGS_DEFAULT, /*tp_flags*/
187 spec_doc, /* tp_doc */
190 0, /* tp_richcompare */
191 0, /* tp_weaklistoffset */
194 spec_Spec_methods, /* tp_methods */
199 0, /* tp_descr_get */
200 0, /* tp_descr_set */
201 0, /* tp_dictoffset */
209 rpmSpec specFromSpec(specObject *s)
215 spec_Wrap(rpmSpec spec)
217 specObject * s = PyObject_New(specObject, &spec_Type);