From d55c5f6c3005858903eca1a5e98915f0c27cfb8b Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 23 Sep 2009 14:21:13 +0300 Subject: [PATCH] Decouple python spec objects from transaction objects - ts structure is only necessary for hysterically passing back the parse result from parseSpec(), hide this in the bindings - deprecate ts.parseSpec() for later ripping --- python/header-py.c | 5 ----- python/header-py.h | 5 +++++ python/rpmts-py.c | 24 +++--------------------- python/spec-py.c | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/python/header-py.c b/python/header-py.c index 50c1819..66e9532 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -126,11 +126,6 @@ * \name Class: rpm.hdr */ -#define DEPRECATED_METHOD \ - static int _warn = 0; \ - if (!_warn) PyErr_Warn(PyExc_DeprecationWarning, "method is deprecated"); \ - _warn = 1; - struct hdrObject_s { PyObject_HEAD Header h; diff --git a/python/header-py.h b/python/header-py.h index 534e038..7ce1dd8 100644 --- a/python/header-py.h +++ b/python/header-py.h @@ -9,6 +9,11 @@ extern PyTypeObject hdr_Type; #define hdrObject_Check(v) ((v)->ob_type == &hdr_Type) +#define DEPRECATED_METHOD \ + static int _warn = 0; \ + if (!_warn) PyErr_Warn(PyExc_DeprecationWarning, "method is deprecated"); \ + _warn = 1; + extern PyObject * pyrpmError; PyObject * hdr_Wrap(Header h); diff --git a/python/rpmts-py.c b/python/rpmts-py.c index a80bbb9..ab4f5b9 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -848,27 +848,9 @@ rpmts_iternext(rpmtsObject * s) static PyObject * spec_Parse(rpmtsObject * s, PyObject * args, PyObject * kwds) { - const char * specfile; - rpmSpec spec; - char * buildRoot = NULL; - int recursing = 0; - char * passPhrase = ""; - char *cookie = NULL; - int anyarch = 1; - int force = 1; - char * kwlist[] = {"specfile", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:Parse", kwlist, &specfile)) - return NULL; - - if (parseSpec(s->ts, specfile,"/", buildRoot,recursing, passPhrase, - cookie, anyarch, force)!=0) { - PyErr_SetString(pyrpmError, "can't parse specfile\n"); - return NULL; - } - - spec = rpmtsSpec(s->ts); - return spec_Wrap(spec); + DEPRECATED_METHOD; + /* we could pass in the ts from here but hardly worth the trouble */ + return PyObject_Call((PyObject *) &spec_Type, args, kwds); } static PyObject * diff --git a/python/spec-py.c b/python/spec-py.c index 510d6d7..6f73aa3 100644 --- a/python/spec-py.c +++ b/python/spec-py.c @@ -1,5 +1,6 @@ #include "rpmsystem-py.h" +#include "header-py.h" #include "spec-py.h" /** \ingroup python @@ -19,8 +20,7 @@ * \code * import rpm * rpm.addMacro("_topdir","/path/to/topdir") - * ts=rpm.ts() - * s=ts.parseSpec("foo.spec") + * s=rpm.spec("foo.spec") * print s.prep() * \endcode * @@ -148,6 +148,39 @@ static PyMethodDef spec_Spec_methods[] = { {NULL} /* Sentinel */ }; +static PyObject *spec_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) +{ + rpmts ts = NULL; + const char * specfile; + rpmSpec spec = NULL; + char * buildRoot = NULL; + int recursing = 0; + char * passPhrase = ""; + char *cookie = NULL; + int anyarch = 1; + int force = 1; + char * kwlist[] = {"specfile", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:spec_new", kwlist, + &specfile)) + return NULL; + + /* + * Just how hysterical can you get? We need to create a transaction + * set to get back the results from parseSpec()... + */ + ts = rpmtsCreate(); + if (parseSpec(ts, specfile,"/", buildRoot,recursing, passPhrase, + cookie, anyarch, force) == 0) { + spec = rpmtsSpec(ts); + } else { + PyErr_SetString(pyrpmError, "can't parse specfile\n"); + } + rpmtsFree(ts); + + return spec ? spec_Wrap(spec) : NULL; +} + PyTypeObject spec_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ @@ -187,7 +220,7 @@ PyTypeObject spec_Type = { 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - 0, /* tp_new */ + spec_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ }; -- 2.7.4