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 /*type specific fields */
42 spec_dealloc(specObject * s)
45 s->spec=freeSpec(s->spec);
51 spec_print(specObject * s)
56 /* XXX TODO return something sensible if spec exists but component (eg %clean)
57 * does not. Possibly "" or None */
60 spec_get_buildroot(specObject * s)
62 rpmSpec spec = specFromSpec(s);
63 if (spec != NULL && spec->buildRoot) {
64 return Py_BuildValue("s", spec->buildRoot);
72 spec_get_prep(specObject * s)
74 rpmSpec spec = specFromSpec(s);
76 if (spec != NULL && spec->prep) {
77 res = Py_BuildValue("s",getStringBuf(spec->prep));
83 spec_get_build(specObject * s)
85 rpmSpec spec = specFromSpec(s);
87 if (spec != NULL && spec->build) {
88 res = Py_BuildValue("s",getStringBuf(spec->build));
94 spec_get_install(specObject * s)
96 rpmSpec spec = specFromSpec(s);
98 if (spec != NULL && spec->install) {
99 res = Py_BuildValue("s",getStringBuf(spec->install));
105 spec_get_clean(specObject * s)
107 rpmSpec spec = specFromSpec(s);
108 PyObject *res = NULL;
109 if (spec != NULL && spec->clean) {
110 res = Py_BuildValue("s",getStringBuf(spec->clean));
116 spec_get_sources(specObject *s)
118 struct Source * source;
119 PyObject *sourceList, *srcUrl;
123 sourceList = PyList_New(0);
124 spec = specFromSpec(s);
126 source = spec->sources;
128 while (source != NULL) {
129 fullSource = source->fullSource;
130 srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
131 PyList_Append(sourceList, srcUrl);
135 return PyList_AsTuple(sourceList);
146 static char spec_doc[] = "RPM Spec file object";
148 static PyMethodDef spec_Spec_methods[] = {
149 {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
150 {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
151 {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
152 {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
153 {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
154 {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
155 {NULL} /* Sentinel */
158 PyTypeObject spec_Type = {
159 PyObject_HEAD_INIT(&PyType_Type)
161 "rpm.spec", /*tp_name*/
162 sizeof(specObject), /*tp_basicsize*/
164 (destructor) spec_dealloc, /*tp_dealloc*/
165 (printfunc) spec_print, /*tp_print*/
171 0, /*tp_as_sequence*/
179 Py_TPFLAGS_DEFAULT, /*tp_flags*/
180 spec_doc, /* tp_doc */
183 0, /* tp_richcompare */
184 0, /* tp_weaklistoffset */
187 spec_Spec_methods, /* tp_methods */
192 0, /* tp_descr_get */
193 0, /* tp_descr_set */
194 0, /* tp_dictoffset */
202 rpmSpec specFromSpec(specObject *s)
208 spec_Wrap(rpmSpec spec)
210 specObject * s = PyObject_New(specObject, &spec_Type);