1 #include "rpmsystem-py.h"
9 * \brief A python rpm.spec object represents an RPM spec file set.
11 * The spec file is at the heart of RPM's packaging building process. Similar
12 * in concept to a makefile, it contains information required by RPM to build
13 * the package, as well as instructions telling RPM how to build it. The spec
14 * file also dictates exactly what files are a part of the package, and where
15 * they should be installed.
17 * The rpm.spec object represents a parsed specfile to aid extraction of data.
22 * rpm.addMacro("_topdir","/path/to/topdir")
23 * s=rpm.spec("foo.spec")
27 * Macros set using add macro will be used allowing testing of conditional builds
33 /*type specific fields */
38 spec_dealloc(specObject * s)
41 s->spec=freeSpec(s->spec);
43 Py_TYPE(s)->tp_free((PyObject *)s);
47 spec_get_buildroot(specObject * s)
49 rpmSpec spec = specFromSpec(s);
50 if (spec->buildRoot) {
51 return Py_BuildValue("s", spec->buildRoot);
57 spec_get_prep(specObject * s)
59 rpmSpec spec = specFromSpec(s);
61 return Py_BuildValue("s",getStringBuf(spec->prep));
67 spec_get_build(specObject * s)
69 rpmSpec spec = specFromSpec(s);
71 return Py_BuildValue("s",getStringBuf(spec->build));
77 spec_get_install(specObject * s)
79 rpmSpec spec = specFromSpec(s);
81 return Py_BuildValue("s",getStringBuf(spec->install));
87 spec_get_clean(specObject * s)
89 rpmSpec spec = specFromSpec(s);
90 if (spec != NULL && spec->clean) {
91 return Py_BuildValue("s",getStringBuf(spec->clean));
97 spec_get_sources(specObject *s)
99 struct Source * source;
100 PyObject *sourceList, *srcUrl;
104 sourceList = PyList_New(0);
105 spec = specFromSpec(s);
107 source = spec->sources;
109 while (source != NULL) {
110 fullSource = source->fullSource;
111 srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
112 PyList_Append(sourceList, srcUrl);
116 return PyList_AsTuple(sourceList);
124 static char spec_doc[] = "RPM Spec file object";
126 static PyMethodDef spec_Spec_methods[] = {
127 {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
128 {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
129 {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
130 {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
131 {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
132 {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
133 {NULL} /* Sentinel */
136 static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
139 const char * specfile;
141 char * buildRoot = NULL;
143 char * passPhrase = "";
147 char * kwlist[] = {"specfile", NULL};
149 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:spec_new", kwlist,
154 * Just how hysterical can you get? We need to create a transaction
155 * set to get back the results from parseSpec()...
158 if (parseSpec(ts, specfile,"/", buildRoot,recursing, passPhrase,
159 cookie, anyarch, force) == 0) {
160 spec = rpmtsSpec(ts);
162 PyErr_SetString(PyExc_ValueError, "can't parse specfile\n");
166 return spec ? spec_Wrap(subtype, spec) : NULL;
169 PyTypeObject spec_Type = {
170 PyVarObject_HEAD_INIT(&PyType_Type, 0)
171 "rpm.spec", /*tp_name*/
172 sizeof(specObject), /*tp_basicsize*/
174 (destructor) spec_dealloc, /*tp_dealloc*/
181 0, /*tp_as_sequence*/
189 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
190 spec_doc, /* tp_doc */
193 0, /* tp_richcompare */
194 0, /* tp_weaklistoffset */
197 spec_Spec_methods, /* tp_methods */
202 0, /* tp_descr_get */
203 0, /* tp_descr_set */
204 0, /* tp_dictoffset */
207 spec_new, /* tp_new */
212 rpmSpec specFromSpec(specObject *s)
218 spec_Wrap(PyTypeObject *subtype, rpmSpec spec)
220 specObject * s = (specObject *)subtype->tp_alloc(subtype, 0);
221 if (s == NULL) return NULL;
224 return (PyObject *) s;