rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

spec-py.c
Go to the documentation of this file.
1
5 #include "system.h"
6
7 #include <rpmiotypes.h>
8 #include <rpmio.h>
9 #include "spec-py.h"
10
37 static void
38 spec_dealloc(specObject * s)
39 /*@modifies s @*/
40 {
41 if (s->spec)
42 s->spec = freeSpec(s->spec);
43 PyObject_Del(s);
44 }
45
46 static int
47 spec_print(specObject * s)
48 {
49 return 0;
50 }
51
52 /* XXX TODO return something sensible if spec exists but component (eg %clean)
53 * does not. Possibly "" or None */
54
55 static PyObject *
56 spec_get_buildroot(specObject * s)
57 /*@*/
58 {
59 Spec spec = specFromSpec(s);
60 PyObject * result = NULL;
61 const char * buildRootURL = rpmExpand("%{?buildroot}", NULL);
62 if (spec != NULL && *buildRootURL)
63 result = Py_BuildValue("s", buildRootURL);
64 buildRootURL = _free(buildRootURL);
65 return result;
66 }
67
68 static PyObject *
69 spec_get_prep(specObject * s)
70 /*@*/
71 {
72 Spec spec = specFromSpec(s);
73 return (spec != NULL && spec->prep != NULL)
74 ? Py_BuildValue("s", rpmiobStr(spec->prep)) : NULL;
75 }
76
77 static PyObject *
78 spec_get_build(specObject * s)
79 /*@*/
80 {
81 Spec spec = specFromSpec(s);
82 return (spec != NULL && spec->build != NULL)
83 ? Py_BuildValue("s", rpmiobStr(spec->build)) : NULL;
84 }
85
86 static PyObject *
87 spec_get_install(specObject * s)
88 /*@*/
89 {
90 Spec spec = specFromSpec(s);
91 return (spec != NULL && spec->install != NULL)
92 ? Py_BuildValue("s", rpmiobStr(spec->install)) : NULL;
93 }
94
95 static PyObject *
96 spec_get_check(specObject * s)
97 /*@*/
98 {
99 Spec spec = specFromSpec(s);
100 return (spec != NULL && spec->check != NULL)
101 ? Py_BuildValue("s", rpmiobStr(spec->check)) : NULL;
102 }
103
104 static PyObject *
105 spec_get_clean(specObject * s)
106 /*@*/
107 {
108 Spec spec = specFromSpec(s);
109 return (spec != NULL && spec->clean != NULL)
110 ? Py_BuildValue("s", rpmiobStr(spec->clean)) : NULL;
111 }
112
113 static PyObject *
114 spec_get_sources(specObject *s)
115 /*@*/
116 {
117 struct Source * source;
118 PyObject *sourceList, *srcUrl;
119 Spec spec;
120 const char * fullSource;
121
122 sourceList = PyList_New(0);
123 spec = specFromSpec(s);
124 if ( spec != NULL) {
125 source = spec->sources;
126
127 while (source != NULL) {
128 fullSource = source->fullSource;
129 srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
130 PyList_Append(sourceList, srcUrl);
131 source = source->next;
132 }
133
134 return PyList_AsTuple(sourceList);
135 }
136 else {
137 return NULL;
138 }
139
140 }
141
144 /*@unchecked@*/ /*@observer@*/
145 static char spec_doc[] = "RPM Spec file object";
146
147 /*@-fullinitblock@*/
148 /*@unchecked@*/ /*@observer@*/
149 static PyMethodDef spec_Spec_methods[] = {
150 {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
151 {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
152 {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
153 {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
154 {"check", (PyCFunction) spec_get_check, METH_VARARGS, NULL },
155 {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
156 {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
157 {NULL} /* Sentinel */
158 };
159 /*@=fullinitblock@*/
160
161 /*@-fullinitblock@*/
162 PyTypeObject spec_Type = {
163 PyObject_HEAD_INIT(&PyType_Type)
164 0, /*ob_size*/
165 "rpm.spec", /*tp_name*/
166 sizeof(specObject), /*tp_basicsize*/
167 0, /*tp_itemsize*/
168 (destructor) spec_dealloc, /*tp_dealloc*/
169 (printfunc) spec_print, /*tp_print*/
170 0, /*tp_getattr*/
171 0, /*tp_setattr*/
172 0, /*tp_compare*/
173 0, /*tp_repr*/
174 0, /*tp_as_number*/
175 0, /*tp_as_sequence*/
176 0, /*tp_as_mapping*/
177 0, /*tp_hash */
178 0, /*tp_call*/
179 0, /*tp_str*/
180 0, /*tp_getattro*/
181 0, /*tp_setattro*/
182 0, /*tp_as_buffer*/
183 Py_TPFLAGS_DEFAULT, /*tp_flags*/
184 spec_doc, /* tp_doc */
185 0, /* tp_traverse */
186 0, /* tp_clear */
187 0, /* tp_richcompare */
188 0, /* tp_weaklistoffset */
189 0, /* tp_iter */
190 0, /* tp_iternext */
191 spec_Spec_methods, /* tp_methods */
192 0, /* tp_members */
193 0, /* tp_getset */
194 0, /* tp_base */
195 0, /* tp_dict */
196 0, /* tp_descr_get */
197 0, /* tp_descr_set */
198 0, /* tp_dictoffset */
199 0, /* tp_init */
200 0, /* tp_alloc */
201 0, /* tp_new */
202 0, /* tp_free */
203 0, /* tp_is_gc */
204 };
205 /*@=fullinitblock@*/
206
207 Spec specFromSpec(specObject *s)
208 {
209 return s->spec;
210 }
211
212 specObject *
213 spec_Wrap(Spec spec)
214 {
215 specObject * s = PyObject_New(specObject, &spec_Type);
216 if (s == NULL)
217 return NULL;
218 s->spec = spec;
219 return s;
220 }