Deprecation tweaks
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 1 Oct 2009 12:12:06 +0000 (15:12 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 1 Oct 2009 12:12:06 +0000 (15:12 +0300)
- use PyErr_WarnEx() for better control and leave the tracking up to python
- use PendingDeprecationWarning for now
- document the replacing functionality in the deprecation messages
- make hdr.sprintf() just an alias to hdr.format() without deprecating,
  at least for now it'd be only a gratuitous incompatible change on python side

python/header-py.c
python/header-py.h
python/rpmds-py.c
python/rpmmi-py.c
python/rpmts-py.c

index 31d5edd..0081940 100644 (file)
@@ -180,7 +180,7 @@ static PyObject * hdrUnload(hdrObject * s, PyObject * args, PyObject *keywords)
 
 static PyObject * hdrExpandFilelist(hdrObject * s)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use hdr.convert() instead");
     headerConvert(s->h, HEADERCONV_EXPANDFILELIST);
 
     Py_RETURN_NONE;
@@ -188,7 +188,7 @@ static PyObject * hdrExpandFilelist(hdrObject * s)
 
 static PyObject * hdrCompressFilelist(hdrObject * s)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use hdr.convert() instead");
     headerConvert(s->h, HEADERCONV_COMPRESSFILELIST);
 
     Py_RETURN_NONE;
@@ -200,7 +200,7 @@ static PyObject * hdrFullFilelist(hdrObject * s)
     rpmtd fileNames = rpmtdNew();
     Header h = s->h;
 
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("obsolete method");
     if (!headerIsEntry (h, RPMTAG_BASENAMES)
        || !headerIsEntry (h, RPMTAG_DIRNAMES)
        || !headerIsEntry (h, RPMTAG_DIRINDEXES))
@@ -239,12 +239,6 @@ static PyObject * hdrFormat(hdrObject * s, PyObject * args, PyObject * kwds)
     return result;
 }
 
-static PyObject * hdrSprintf(hdrObject * s, PyObject * args, PyObject * kwds)
-{
-    DEPRECATED_METHOD;
-    return hdrFormat(s, args, kwds);
-}
-
 static PyObject *hdrIsSource(hdrObject *s)
 {
     return PyBool_FromLong(headerIsSource(s->h));
@@ -293,7 +287,7 @@ static PyObject * hdrWrite(hdrObject *s, PyObject *args, PyObject *kwds)
 
 static PyObject * hdr_fiFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use convert() instead");
     return PyObject_Call((PyObject *) &rpmfi_Type,
                         Py_BuildValue("(O)", s), kwds);
 }
@@ -325,7 +319,7 @@ static struct PyMethodDef hdr_methods[] = {
        NULL },
     {"has_key",                (PyCFunction) hdrHasKey,        METH_O,
        NULL },
-    {"sprintf",                (PyCFunction) hdrSprintf,       METH_VARARGS|METH_KEYWORDS,
+    {"sprintf",                (PyCFunction) hdrFormat,        METH_VARARGS|METH_KEYWORDS,
        NULL },
     {"isSource",       (PyCFunction)hdrIsSource,       METH_NOARGS, 
        NULL },
index ad16e01..8c9dd68 100644 (file)
@@ -9,10 +9,8 @@ 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;
+#define DEPRECATED_METHOD(_msg) \
+    PyErr_WarnEx(PyExc_PendingDeprecationWarning, (_msg), 2);
 
 extern PyObject * pyrpmError;
 
index d4456e9..3818a90 100644 (file)
@@ -63,7 +63,7 @@ void rpmds_ParseEVR(char * evr,
 static PyObject *
 rpmds_Count(rpmdsObject * s)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use len(ds) instead");
     return Py_BuildValue("i", PyMapping_Size((PyObject *)s));
 }
 
index e023891..1d06b5e 100644 (file)
@@ -93,7 +93,7 @@ rpmmi_Instance(rpmmiObject * s)
 static PyObject *
 rpmmi_Count(rpmmiObject * s)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use len(mi) instead");
     return Py_BuildValue("i", PyMapping_Size((PyObject *)s));
 }
 
index 82be375..3f44060 100644 (file)
@@ -781,7 +781,7 @@ rpmts_iternext(rpmtsObject * s)
 static PyObject *
 spec_Parse(rpmtsObject * s, PyObject * args, PyObject * kwds)
 {
-    DEPRECATED_METHOD;
+    DEPRECATED_METHOD("use 'spec = rpm.spec(<specfile>)' instead");
     /* we could pass in the ts from here but hardly worth the trouble */
     return PyObject_Call((PyObject *) &spec_Type, args, kwds);
 }