rpm  5.4.15
spec-py.c
Go to the documentation of this file.
1 
5 #include "system-py.h"
6 
7 #include <rpmiotypes.h>
8 #include <rpmio.h>
9 #define _MACRO_INTERNAL
10 #include <rpmmacro.h>
11 #define _RPMTAG_INTERNAL
12 #include "header_internal.h" /* XXX HEADERFLAG_ALLOCATED */
13 #include "header-py.h"
14 #include "spec-py.h"
15 
42 static void
44  /*@modifies s @*/
45 {
46  if (s->spec)
47  s->spec = freeSpec(s->spec);
48  PyObject_Del(s);
49 }
50 
51 static int
53 {
54  return 0;
55 }
56 
57 /* XXX TODO return something sensible if spec exists but component (eg %clean)
58  * does not. Possibly "" or None */
59 
60 static PyObject *
62  /*@*/
63 {
64  Spec spec = specFromSpec(s);
65  PyObject * result = NULL;
66  const char * buildRootURL = rpmExpand("%{?buildroot}", NULL);
67  if (spec != NULL && *buildRootURL)
68  result = Py_BuildValue("s", buildRootURL);
69  buildRootURL = _free(buildRootURL);
70  return result;
71 }
72 
73 static PyObject *
75  /*@*/
76 {
77  Spec spec = specFromSpec(s);
78  return (spec != NULL && spec->prep != NULL)
79  ? Py_BuildValue("s", rpmiobStr(spec->prep)) : NULL;
80 }
81 
82 static PyObject *
84  /*@*/
85 {
86  Spec spec = specFromSpec(s);
87  return (spec != NULL && spec->build != NULL)
88  ? Py_BuildValue("s", rpmiobStr(spec->build)) : NULL;
89 }
90 
91 static PyObject *
93  /*@*/
94 {
95  Spec spec = specFromSpec(s);
96  return (spec != NULL && spec->install != NULL)
97  ? Py_BuildValue("s", rpmiobStr(spec->install)) : NULL;
98 }
99 
100 static PyObject *
102  /*@*/
103 {
104  Spec spec = specFromSpec(s);
105  return (spec != NULL && spec->check != NULL)
106  ? Py_BuildValue("s", rpmiobStr(spec->check)) : NULL;
107 }
108 
109 static PyObject *
111  /*@*/
112 {
113  Spec spec = specFromSpec(s);
114  return (spec != NULL && spec->clean != NULL)
115  ? Py_BuildValue("s", rpmiobStr(spec->clean)) : NULL;
116 }
117 
118 static PyObject *
120  /*@*/
121 {
122  struct Source * source;
123  PyObject *sourceList, *srcUrl;
124  Spec spec;
125  const char * fullSource;
126 
127  sourceList = PyList_New(0);
128  if (!sourceList) {
129  return NULL;
130  }
131  spec = specFromSpec(s);
132  if ( spec != NULL) {
133  source = spec->sources;
134 
135  while (source != NULL) {
136  fullSource = source->fullSource;
137  srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
138  if (!srcUrl) {
139  Py_XDECREF(sourceList);
140  return NULL;
141  }
142  PyList_Append(sourceList, srcUrl);
143  source = source->next;
144  }
145 
146  return PyList_AsTuple(sourceList);
147  }
148  else {
149  return NULL;
150  }
151 
152 }
153 
154 static PyObject *
156  /*@*/
157 {
158  MacroContext mc;
159  PyObject *macroDict;
160  Spec spec;
161 
162  macroDict = PyDict_New();
163  if (!macroDict) {
164  return NULL;
165  }
166  spec = specFromSpec(s);
167  if ( spec != NULL) {
168  mc = spec->macros;
169  if (mc->macroTable != NULL) {
170  int i;
171  for (i = 0; i < mc->firstFree; i++) {
172  MacroEntry me;
173  PyObject *macro;
174  if ((me = mc->macroTable[i]) == NULL) {
175  /* XXX this should never happen */
176  continue;
177  }
178  macro = PyDict_New();
179 
180  PyMapping_SetItemString(macro, "used", PyInt_FromLong(me->used));
181  PyMapping_SetItemString(macro, "level", PyInt_FromLong(me->level));
182  if (me->opts && *me->opts)
183  PyMapping_SetItemString(macro, "opts", PyString_FromString(me->opts));
184  if (me->body && *me->body)
185  PyMapping_SetItemString(macro, "body", PyString_FromString(me->body));
186  PyMapping_SetItemString(macroDict, strdup(me->name), macro);
187  }
188  }
189 
190  return macroDict;
191  }
192  else {
193  return NULL;
194  }
195 
196 }
197 
198 static PyObject *
200  /*@*/
201 {
202  PyObject *headerList;
203  Spec spec;
204  Package package;
205  Header header;
206 
207  headerList = PyList_New(0);
208  if (!headerList) {
209  return NULL;
210  }
211  spec = specFromSpec(s);
212  if ( spec != NULL) {
213  package = spec->packages;
214 
215  while (package != NULL) {
216  header = package->header;
217  if (header != NULL)
218  PyList_Append(headerList, (PyObject *) hdr_Wrap(header));
219  package = package->next;
220  }
221  }
222 
223  return PyList_AsTuple(headerList);
224 }
225 
228  /*@unchecked@*/ /*@observer@*/
229 static char spec_doc[] = "RPM Spec file object";
230 
231 /*@-fullinitblock@*/
232 /*@unchecked@*/ /*@observer@*/
233 static PyMethodDef spec_Spec_methods[] = {
234  {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
235  {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
236  {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
237  {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
238  {"check", (PyCFunction) spec_get_check, METH_VARARGS, NULL },
239  {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
240  {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
241  {"macros", (PyCFunction) spec_get_macros, METH_VARARGS, NULL },
242  {"headers", (PyCFunction) spec_get_headers, METH_VARARGS, NULL },
243  {NULL} /* Sentinel */
244 };
245 /*@=fullinitblock@*/
246 
247 /*@-fullinitblock@*/
248 PyTypeObject spec_Type = {
249  PyVarObject_HEAD_INIT(&PyType_Type, 0)
250  "rpm.spec", /*tp_name*/
251  sizeof(specObject), /*tp_basicsize*/
252  0, /*tp_itemsize*/
253  (destructor) spec_dealloc, /*tp_dealloc*/
254  (printfunc) spec_print, /*tp_print*/
255  0, /*tp_getattr*/
256  0, /*tp_setattr*/
257  0, /*tp_compare*/
258  0, /*tp_repr*/
259  0, /*tp_as_number*/
260  0, /*tp_as_sequence*/
261  0, /*tp_as_mapping*/
262  0, /*tp_hash */
263  0, /*tp_call*/
264  0, /*tp_str*/
265  0, /*tp_getattro*/
266  0, /*tp_setattro*/
267  0, /*tp_as_buffer*/
268  Py_TPFLAGS_DEFAULT, /*tp_flags*/
269  spec_doc, /* tp_doc */
270  0, /* tp_traverse */
271  0, /* tp_clear */
272  0, /* tp_richcompare */
273  0, /* tp_weaklistoffset */
274  0, /* tp_iter */
275  0, /* tp_iternext */
276  spec_Spec_methods, /* tp_methods */
277  0, /* tp_members */
278  0, /* tp_getset */
279  0, /* tp_base */
280  0, /* tp_dict */
281  0, /* tp_descr_get */
282  0, /* tp_descr_set */
283  0, /* tp_dictoffset */
284  0, /* tp_init */
285  0, /* tp_alloc */
286  0, /* tp_new */
287  0, /* tp_free */
288  0, /* tp_is_gc */
289 };
290 /*@=fullinitblock@*/
291 
293 {
294  return s->spec;
295 }
296 
297 specObject *
299 {
300  specObject * s = PyObject_New(specObject, &spec_Type);
301  if (s == NULL)
302  return NULL;
303  s->spec = spec;
304  return s;
305 }
rpmiob build
Definition: rpmspec.h:188
PyObject_HEAD Spec spec
Definition: spec-py.h:16
hdrObject * hdr_Wrap(Header h)
Definition: header-py.c:678
static PyObject * spec_get_headers(specObject *s)
Definition: spec-py.c:199
specObject * spec_Wrap(Spec spec)
Definition: spec-py.c:298
rpmiob clean
Definition: rpmspec.h:194
static int spec_print(specObject *s)
Definition: spec-py.c:52
struct specObject_s specObject
The Header data structure.
rpmuint32_t num
Definition: rpmspec.h:50
rpmiob check
Definition: rpmspec.h:192
struct Source * sources
Definition: rpmspec.h:162
static PyObject * spec_get_install(specObject *s)
Definition: spec-py.c:92
struct Source * next
Definition: rpmspec.h:52
static PyMethodDef spec_Spec_methods[]
Definition: spec-py.c:233
const char * fullSource
Definition: rpmspec.h:46
rpmiob prep
Definition: rpmspec.h:186
const char * source
Definition: rpmspec.h:48
Definition: rpmspec.h:44
Header header
Definition: rpmspec.h:217
static PyObject * spec_get_buildroot(specObject *s)
Definition: spec-py.c:61
Spec specFromSpec(specObject *s)
Definition: spec-py.c:292
MacroContext macros
Definition: rpmspec.h:177
static PyObject * spec_get_clean(specObject *s)
Definition: spec-py.c:110
static PyObject * spec_get_build(specObject *s)
Definition: spec-py.c:83
static PyObject * spec_get_macros(specObject *s)
Definition: spec-py.c:155
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Definition: macro.c:3252
Spec freeSpec(Spec spec)
Destroy a spec file control structure.
static PyObject * spec_get_check(specObject *s)
Definition: spec-py.c:101
static PyObject * spec_get_sources(specObject *s)
Definition: spec-py.c:119
static void spec_dealloc(specObject *s)
Definition: spec-py.c:43
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
Definition: rpmiob.c:112
const char const int i
Definition: bson.h:778
struct MacroContext_s * MacroContext
Definition: rpmmacro.h:13
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
static char spec_doc[]
Definition: spec-py.c:229
PyTypeObject spec_Type
Definition: spec-py.c:248
static PyObject * spec_get_prep(specObject *s)
Definition: spec-py.c:74
The structure used to store values for a package.
Definition: rpmspec.h:214
rpmiob install
Definition: rpmspec.h:190
struct MacroEntry_s * MacroEntry
Definition: rpmmacro.h:12
int flags
Definition: rpmspec.h:49