Decouple python spec objects from transaction objects
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 23 Sep 2009 11:21:13 +0000 (14:21 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 23 Sep 2009 11:21:13 +0000 (14:21 +0300)
- 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
python/header-py.h
python/rpmts-py.c
python/spec-py.c

index 50c1819..66e9532 100644 (file)
  * \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;
index 534e038..7ce1dd8 100644 (file)
@@ -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);
index a80bbb9..ab4f5b9 100644 (file)
@@ -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 *
index 510d6d7..6f73aa3 100644 (file)
@@ -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 */
 };