00001
00005 #include "system.h"
00006
00007 #include "structmember.h"
00008
00009 #include "rpmdebug-py.c"
00010
00011 #include <rpmcli.h>
00012
00013 #include "rpmrc-py.h"
00014
00015 #include "debug.h"
00016
00017
00018 static int _rc_debug = 0;
00019
00029
00032 PyObject *
00033 rpmrc_AddMacro( PyObject * self, PyObject * args, PyObject * kwds)
00034 {
00035 char * name, * val;
00036 char * kwlist[] = {"name", "value", NULL};
00037
00038 if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss:AddMacro", kwlist,
00039 &name, &val))
00040 return NULL;
00041
00042 addMacro(NULL, name, NULL, val, -1);
00043
00044 Py_INCREF(Py_None);
00045 return Py_None;
00046 }
00047
00050 PyObject *
00051 rpmrc_DelMacro( PyObject * self, PyObject * args, PyObject * kwds)
00052 {
00053 char * name;
00054 char * kwlist[] = {"name", NULL};
00055
00056 if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:DelMacro", kwlist, &name))
00057 return NULL;
00058
00059 delMacro(NULL, name);
00060
00061 Py_INCREF(Py_None);
00062 return Py_None;
00063 }
00064
00065 #if Py_TPFLAGS_HAVE_ITER
00066
00068 static void rpmrc_dealloc(PyObject * s)
00069
00070 {
00071 if (_rc_debug)
00072 fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
00073 PyDict_Type.tp_dealloc(s);
00074 }
00075
00078 static int rpmrc_print(PyObject * s, FILE *fp, int flags)
00079
00080 {
00081
00082 if (_rc_debug)
00083 fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
00084
00085 return PyDict_Type.tp_print(s, fp, flags);
00086 }
00087
00090 static int rpmrc_compare(PyObject * a, PyObject * b)
00091
00092 {
00093 if (_rc_debug)
00094 fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
00095 return PyDict_Type.tp_compare(a, b);
00096 }
00097
00100 static PyObject * rpmrc_repr(PyObject * s)
00101
00102 {
00103 if (_rc_debug)
00104 fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
00105 return PyDict_Type.tp_repr(s);
00106 }
00107
00110 static long rpmrc_hash(PyObject * s)
00111
00112 {
00113
00114 if (_rc_debug)
00115 fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
00116 return PyDict_Type.tp_hash(s);
00117 }
00118
00121 static int
00122 rpmrc_length(PyObject * s)
00123
00124 {
00125 if (_rc_debug)
00126 fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
00127 return PyDict_Type.tp_as_mapping->mp_length(s);
00128 }
00129
00132 static PyObject *
00133 rpmrc_subscript(PyObject * s, PyObject * key)
00134
00135 {
00136 if (_rc_debug)
00137 fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
00138 return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
00139 }
00140
00143 static int
00144 rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
00145
00146 {
00147 if (_rc_debug)
00148 fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
00149 return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
00150 }
00151
00152
00153 static PyMappingMethods rpmrc_as_mapping = {
00154 rpmrc_length,
00155 rpmrc_subscript,
00156 rpmrc_ass_subscript,
00157 };
00158
00161 static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
00162
00163 {
00164 if (_rc_debug)
00165 fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
00166 return PyObject_GenericGetAttr(s, name);
00167 }
00168
00171 static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
00172
00173 {
00174 if (_rc_debug)
00175 fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
00176 return PyDict_Type.tp_setattro(s, name, value);
00177 }
00178
00181
00182 static char rpmrc_doc[] =
00183 "";
00184
00187 static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
00188
00189 {
00190 if (_rc_debug)
00191 fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
00192 return PyDict_Type.tp_traverse(s, visit, arg);
00193 }
00194
00197 static int rpmrc_clear(PyObject * s)
00198
00199 {
00200 if (_rc_debug)
00201 fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
00202 return PyDict_Type.tp_clear(s);
00203 }
00204
00207 static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
00208
00209 {
00210 if (_rc_debug)
00211 fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
00212 return PyDict_Type.tp_richcompare(v, w, op);
00213 }
00214
00215 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00216
00218 static PyObject * rpmrc_iter(PyObject * s)
00219
00220 {
00221 if (_rc_debug)
00222 fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
00223 if (s->ob_type == &PyDictIter_Type)
00224 return PyDictIter_Type.tp_iter(s);
00225 return PyDict_Type.tp_iter(s);
00226 }
00227
00230
00231 static PyObject * rpmrc_iternext(PyObject * s)
00232
00233 {
00234 if (_rc_debug)
00235 fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
00236 if (s->ob_type == &PyDictIter_Type)
00237 return PyDictIter_Type.tp_iternext(s);
00238 return NULL;
00239 }
00240
00243
00244
00245 static PyObject * rpmrc_next(PyObject * s, PyObject *args)
00246
00247 {
00248 if (_rc_debug)
00249 fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
00250 if (s->ob_type == &PyDictIter_Type)
00251 return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
00252 return NULL;
00253 }
00254 #else
00255 #define rpmrc_iter 0
00256 #define rpmrc_iternext 0
00257 #endif
00258
00261 static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
00262
00263 {
00264 if (_rc_debug)
00265 fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
00266 if (PyDict_Type.tp_init(s, args, kwds) < 0)
00267 return -1;
00268 return 0;
00269 }
00270
00273 static void rpmrc_free(PyObject * s)
00274
00275 {
00276 if (_rc_debug)
00277 fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
00278 _PyObject_GC_Del(s);
00279 }
00280
00283 static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
00284
00285 {
00286 PyObject * ns = PyType_GenericAlloc(subtype, nitems);
00287
00288 if (_rc_debug)
00289 fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
00290 return (PyObject *) ns;
00291 }
00292
00295
00296 static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00297
00298 {
00299 PyObject * ns;
00300
00301
00302 ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
00303
00304
00305 if (rpmrc_init(ns, args, kwds) < 0) {
00306 rpmrc_free(ns);
00307 return NULL;
00308 }
00309
00310 if (_rc_debug)
00311 fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
00312 return ns;
00313 }
00314 #endif
00315
00318
00319
00320 static struct PyMethodDef rpmrc_methods[] = {
00321 { "addMacro", (PyCFunction) rpmrc_AddMacro, METH_VARARGS|METH_KEYWORDS,
00322 NULL },
00323 { "delMacro", (PyCFunction) rpmrc_DelMacro, METH_VARARGS|METH_KEYWORDS,
00324 NULL },
00325 #if Py_TPFLAGS_HAVE_ITER && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00326 { "next", (PyCFunction) rpmrc_next, METH_VARARGS,
00327 "next() -- get the next value, or raise StopIteration"},
00328 #endif
00329 {NULL, NULL}
00330 };
00331
00332
00335
00336 #if Py_TPFLAGS_HAVE_ITER
00337 PyTypeObject rpmrc_Type = {
00338 PyObject_HEAD_INIT(&PyType_Type)
00339 0,
00340 "rpm.rc",
00341 sizeof(rpmrcObject),
00342 0,
00343 (destructor) rpmrc_dealloc,
00344 rpmrc_print,
00345 0,
00346 0,
00347 rpmrc_compare,
00348 rpmrc_repr,
00349 0,
00350 0,
00351 &rpmrc_as_mapping,
00352 rpmrc_hash,
00353 0,
00354 0,
00355 (getattrofunc) rpmrc_getattro,
00356 (setattrofunc) rpmrc_setattro,
00357 0,
00358 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
00359 rpmrc_doc,
00360 rpmrc_traverse,
00361 rpmrc_clear,
00362 rpmrc_richcompare,
00363 0,
00364 rpmrc_iter,
00365 rpmrc_iternext,
00366 rpmrc_methods,
00367 0,
00368 0,
00369 &PyDict_Type,
00370 0,
00371 0,
00372 0,
00373 0,
00374 rpmrc_init,
00375 rpmrc_alloc,
00376 rpmrc_new,
00377 rpmrc_free,
00378 0,
00379 };
00380 #else
00381 PyTypeObject rpmrc_Type = {
00382 PyObject_HEAD_INIT(&PyType_Type)
00383 0,
00384 "rpm.rc",
00385 sizeof(rpmrcObject),
00386 0,
00387 0,
00388 0,
00389 0,
00390 0,
00391 0,
00392 0,
00393 0,
00394 0,
00395 0,
00396 0,
00397 0,
00398 0,
00399 0,
00400 0,
00401 0,
00402 0,
00403 0
00404 };
00405 #endif
00406
00407
00408 #if Py_TPFLAGS_HAVE_ITER
00409 PyObject * rpmrc_Create( PyObject * self, PyObject *args, PyObject *kwds)
00410 {
00411 return rpmrc_new(&rpmrc_Type, args, kwds);
00412 }
00413 #endif
00414