rpm  5.4.10
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 #define _MACRO_INTERNAL
10 #include <rpmmacro.h>
11 #include "spec-py.h"
12 
39 static void
41  /*@modifies s @*/
42 {
43  if (s->spec)
44  s->spec = freeSpec(s->spec);
45  PyObject_Del(s);
46 }
47 
48 static int
50 {
51  return 0;
52 }
53 
54 /* XXX TODO return something sensible if spec exists but component (eg %clean)
55  * does not. Possibly "" or None */
56 
57 static PyObject *
59  /*@*/
60 {
61  Spec spec = specFromSpec(s);
62  PyObject * result = NULL;
63  const char * buildRootURL = rpmExpand("%{?buildroot}", NULL);
64  if (spec != NULL && *buildRootURL)
65  result = Py_BuildValue("s", buildRootURL);
66  buildRootURL = _free(buildRootURL);
67  return result;
68 }
69 
70 static PyObject *
72  /*@*/
73 {
74  Spec spec = specFromSpec(s);
75  return (spec != NULL && spec->prep != NULL)
76  ? Py_BuildValue("s", rpmiobStr(spec->prep)) : NULL;
77 }
78 
79 static PyObject *
81  /*@*/
82 {
83  Spec spec = specFromSpec(s);
84  return (spec != NULL && spec->build != NULL)
85  ? Py_BuildValue("s", rpmiobStr(spec->build)) : NULL;
86 }
87 
88 static PyObject *
90  /*@*/
91 {
92  Spec spec = specFromSpec(s);
93  return (spec != NULL && spec->install != NULL)
94  ? Py_BuildValue("s", rpmiobStr(spec->install)) : NULL;
95 }
96 
97 static PyObject *
99  /*@*/
100 {
101  Spec spec = specFromSpec(s);
102  return (spec != NULL && spec->check != NULL)
103  ? Py_BuildValue("s", rpmiobStr(spec->check)) : NULL;
104 }
105 
106 static PyObject *
108  /*@*/
109 {
110  Spec spec = specFromSpec(s);
111  return (spec != NULL && spec->clean != NULL)
112  ? Py_BuildValue("s", rpmiobStr(spec->clean)) : NULL;
113 }
114 
115 static PyObject *
117  /*@*/
118 {
119  struct Source * source;
120  PyObject *sourceList, *srcUrl;
121  Spec spec;
122  const char * fullSource;
123 
124  sourceList = PyList_New(0);
125  if (!sourceList) {
126  return NULL;
127  }
128  spec = specFromSpec(s);
129  if ( spec != NULL) {
130  source = spec->sources;
131 
132  while (source != NULL) {
133  fullSource = source->fullSource;
134  srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
135  if (!srcUrl) {
136  Py_XDECREF(sourceList);
137  return NULL;
138  }
139  PyList_Append(sourceList, srcUrl);
140  source = source->next;
141  }
142 
143  return PyList_AsTuple(sourceList);
144  }
145  else {
146  return NULL;
147  }
148 
149 }
150 
151 static PyObject *
153  /*@*/
154 {
155  MacroContext mc;
156  PyObject *macroDict;
157  Spec spec;
158 
159  macroDict = PyDict_New();
160  if (!macroDict) {
161  return NULL;
162  }
163  spec = specFromSpec(s);
164  if ( spec != NULL) {
165  mc = spec->macros;
166  if (mc->macroTable != NULL) {
167  int i;
168  for (i = 0; i < mc->firstFree; i++) {
169  MacroEntry me;
170  PyObject *macro;
171  if ((me = mc->macroTable[i]) == NULL) {
172  /* XXX this should never happen */
173  continue;
174  }
175  macro = PyDict_New();
176 
177  PyMapping_SetItemString(macro, "used", PyInt_FromLong(me->used));
178  PyMapping_SetItemString(macro, "level", PyInt_FromLong(me->level));
179  if (me->opts && *me->opts)
180  PyMapping_SetItemString(macro, "opts", PyString_FromString(me->opts));
181  if (me->body && *me->body)
182  PyMapping_SetItemString(macro, "body", PyString_FromString(me->body));
183  PyMapping_SetItemString(macroDict, strdup(me->name), macro);
184  }
185  }
186 
187  return macroDict;
188  }
189  else {
190  return NULL;
191  }
192 
193 }
194 
197  /*@unchecked@*/ /*@observer@*/
198 static char spec_doc[] = "RPM Spec file object";
199 
200 /*@-fullinitblock@*/
201 /*@unchecked@*/ /*@observer@*/
202 static PyMethodDef spec_Spec_methods[] = {
203  {"sources", (PyCFunction) spec_get_sources, METH_VARARGS, NULL },
204  {"prep", (PyCFunction) spec_get_prep, METH_VARARGS, NULL },
205  {"build", (PyCFunction) spec_get_build, METH_VARARGS, NULL },
206  {"install", (PyCFunction) spec_get_install, METH_VARARGS, NULL },
207  {"check", (PyCFunction) spec_get_check, METH_VARARGS, NULL },
208  {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL },
209  {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL },
210  {"macros", (PyCFunction) spec_get_macros, METH_VARARGS, NULL },
211  {NULL} /* Sentinel */
212 };
213 /*@=fullinitblock@*/
214 
215 /*@-fullinitblock@*/
216 PyTypeObject spec_Type = {
217  PyObject_HEAD_INIT(&PyType_Type)
218  0, /*ob_size*/
219  "rpm.spec", /*tp_name*/
220  sizeof(specObject), /*tp_basicsize*/
221  0, /*tp_itemsize*/
222  (destructor) spec_dealloc, /*tp_dealloc*/
223  (printfunc) spec_print, /*tp_print*/
224  0, /*tp_getattr*/
225  0, /*tp_setattr*/
226  0, /*tp_compare*/
227  0, /*tp_repr*/
228  0, /*tp_as_number*/
229  0, /*tp_as_sequence*/
230  0, /*tp_as_mapping*/
231  0, /*tp_hash */
232  0, /*tp_call*/
233  0, /*tp_str*/
234  0, /*tp_getattro*/
235  0, /*tp_setattro*/
236  0, /*tp_as_buffer*/
237  Py_TPFLAGS_DEFAULT, /*tp_flags*/
238  spec_doc, /* tp_doc */
239  0, /* tp_traverse */
240  0, /* tp_clear */
241  0, /* tp_richcompare */
242  0, /* tp_weaklistoffset */
243  0, /* tp_iter */
244  0, /* tp_iternext */
245  spec_Spec_methods, /* tp_methods */
246  0, /* tp_members */
247  0, /* tp_getset */
248  0, /* tp_base */
249  0, /* tp_dict */
250  0, /* tp_descr_get */
251  0, /* tp_descr_set */
252  0, /* tp_dictoffset */
253  0, /* tp_init */
254  0, /* tp_alloc */
255  0, /* tp_new */
256  0, /* tp_free */
257  0, /* tp_is_gc */
258 };
259 /*@=fullinitblock@*/
260 
262 {
263  return s->spec;
264 }
265 
266 specObject *
268 {
269  specObject * s = PyObject_New(specObject, &spec_Type);
270  if (s == NULL)
271  return NULL;
272  s->spec = spec;
273  return s;
274 }