fixed python bindings:
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 19 May 2008 21:14:36 +0000 (21:14 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 19 May 2008 21:14:36 +0000 (21:14 +0000)
* info call isnnow aequivalent to rrdtool info (the same as in the perl and ruby bindings)
* graphv and updatev calls added

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1372 a5681a0c-68f1-0310-ab6d-d61299d08faa

NEWS
bindings/python/README
bindings/python/rrd_extra.h [deleted file]
bindings/python/rrdtoolmodule.c
doc/rrdpython.pod

diff --git a/NEWS b/NEWS
index 2d2abf7..f4b5111 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
 RRDTOOL NEWS
 ============
 RRDTOOL NEWS
 ============
+
+#####################################
 Major Changes between 1.2.x and 1.3.x
 Major Changes between 1.2.x and 1.3.x
+-------------------------------------
 
 RRdtool dump / restore Incompatibilities
 ----------------------------------------
 
 RRdtool dump / restore Incompatibilities
 ----------------------------------------
@@ -66,20 +69,27 @@ Internationalization (Takao Fujiwara and Tobi Oetiker)
   available on your system. Use the configure option --disable-libintl if
   you want to disable this feature
 
   available on your system. Use the configure option --disable-libintl if
   you want to disable this feature
 
-Misc
-----
+Language Bindings
+-----------------
 * ruby rrd_fetch will return step as a last property -- Mike Perham
 
 * ruby rrd_fetch will return step as a last property -- Mike Perham
 
+* python rrdtool.info does now conform with the data structure returned
+  by the other language bindings. This is incompatible with the
+  previous (broken) version --tobi
+
+* python bindings got updatev support --tobi
+
+* ruby, perl, python bindings support the new graphv interface --tobi
+
 Locale Independent Numeric Input
 --------------------------------
 * Regardles of locale you are in, rrdtool always expects input to be numbers
   (LC_NUMERIC) in C or POSIX locale for numbers. (not 1,1 but 1.1) this is
   necessary to make things like RPN work as it uses , as a separator.
 
 Locale Independent Numeric Input
 --------------------------------
 * Regardles of locale you are in, rrdtool always expects input to be numbers
   (LC_NUMERIC) in C or POSIX locale for numbers. (not 1,1 but 1.1) this is
   necessary to make things like RPN work as it uses , as a separator.
 
-RRDTOOL NEWS
-============
+######################################################################################
 Major Changes between 1.0.x and 1.2.x
 Major Changes between 1.0.x and 1.2.x
-
+======================================================================================
 Graphing
 --------
 
 Graphing
 --------
 
index 265244f..c234a6b 100644 (file)
@@ -1,5 +1,5 @@
-Python-RRDtool 0.2.1
---------------------
+Based on Python-RRDtool 0.2.1
+-----------------------------
 
 The python-rrdtool provides a interface to rrdtool, the wonderful
 graphing and logging utility. This wrapper implementation has
 
 The python-rrdtool provides a interface to rrdtool, the wonderful
 graphing and logging utility. This wrapper implementation has
@@ -19,10 +19,16 @@ Mailing Lists:
   Users & Hackers  py-rrdtool-users@nongnu.org
 
 
   Users & Hackers  py-rrdtool-users@nongnu.org
 
 
-Author
-------
+Original Author
+---------------
 
 Hye-Shik Chang <perky@FreeBSD.org>
 
 Any comments, suggestions, and/or patches are very welcome.
 Thank you for using py-rrdtool!
 
 Hye-Shik Chang <perky@FreeBSD.org>
 
 Any comments, suggestions, and/or patches are very welcome.
 Thank you for using py-rrdtool!
+
+
+CHANGES
+-------
+2008-05-19 - tobi
+* rewrote the info method to conform to rrdtool info standard
diff --git a/bindings/python/rrd_extra.h b/bindings/python/rrd_extra.h
deleted file mode 100644 (file)
index 2af673b..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *  This file is part of RRDtool.
- *
- *  RRDtool is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published
- *  by the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  RRDtool is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with Foobar; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*****************************************************************************
- * RRDtool 1.0.37  Copyright Tobias Oetiker, 1997 - 2000
- *****************************************************************************
- * rrd_tool.h   Common Header File
- *****************************************************************************
- * Id: rrd_tool.h,v 1.1.1.1 2002/02/26 10:21:37 oetiker Exp
- * Log: rrd_tool.h,v
- * Revision 1.1.1.1  2002/02/26 10:21:37  oetiker
- * Intial Import
- *
- *****************************************************************************/
-#ifdef  __cplusplus
-extern    "C" {
-#endif
-
-#ifndef _RRD_EXTRA_H
-#define _RRD_EXTRA_H
-
-#include "rrd_format.h"
-
-#ifndef WIN32
-#ifndef isnan           /* POSIX */
-    int       isnan(
-    double value);
-#endif
-#else                   /* Windows only */
-#include <float.h>
-#define isnan _isnan
-#endif
-
-    void      rrd_free(
-    rrd_t *rrd);
-    void      rrd_init(
-    rrd_t *rrd);
-
-    int       rrd_open(
-    char *file_name,
-    rrd_t *rrd,
-    int rdwr);
-    int       readfile(
-    char *file,
-    char **buffer,
-    int skipfirst);
-
-#define RRD_READONLY    0
-#define RRD_READWRITE   1
-
-#endif
-
-#ifdef  __cplusplus
-}
-#endif
index f829734..37810f7 100644 (file)
@@ -40,8 +40,9 @@
 static const char *__version__ = "$Revision: 1.14 $";
 
 #include "Python.h"
 static const char *__version__ = "$Revision: 1.14 $";
 
 #include "Python.h"
-#include "rrd.h"
-#include "rrd_extra.h"
+#include "../../src/rrd_tool.h"
+//#include "rrd.h"
+//#include "rrd_extra.h"
 
 static PyObject *ErrorObject;
 extern int optind;
 
 static PyObject *ErrorObject;
 extern int optind;
@@ -402,6 +403,40 @@ static PyObject *PyRRD_resize(
     return r;
 }
 
     return r;
 }
 
+static PyObject *PyDict_FromInfo(
+    info_t *data)
+{
+    PyObject *r;
+    r = PyDict_New();
+    while (data){
+        PyObject *val = NULL;
+        switch (data->type) {
+        case RD_I_VAL:
+            val = isnan(data->value.u_val)     
+                    ? (Py_INCREF(Py_None), Py_None)     
+                    : PyFloat_FromDouble(data->value.u_val);
+            break;
+        case RD_I_CNT:
+            val = PyLong_FromUnsignedLong(data->value.u_cnt);
+            break;
+        case RD_I_INT:
+            val = PyLong_FromLong(data->value.u_int);
+            break;
+        case RD_I_STR:
+            val = PyString_FromString(data->value.u_str);
+            break;
+        case RD_I_BLO:
+            val = PyString_FromStringAndSize((char*)data->value.u_blo.ptr, data->value.u_blo.size);
+            break;
+        }
+        if (val){
+            PyDict_SetItemString(r,data->key,val);
+        }
+        data = data->next;
+    }
+    return r;
+}
+
 static char PyRRD_info__doc__[] =
     "info(filename): extract header information from an rrd";
 
 static char PyRRD_info__doc__[] =
     "info(filename): extract header information from an rrd";
 
@@ -409,101 +444,71 @@ static PyObject *PyRRD_info(
     PyObject UNUSED(*self),
     PyObject * args)
 {
     PyObject UNUSED(*self),
     PyObject * args)
 {
-    PyObject *r, *t, *ds;
-    rrd_t     rrd;
-    char     *filename;
-    unsigned long i, j;
+    PyObject *r;
+    int       argc;
+    char    **argv;
+    info_t   *data;
 
 
-    if (!PyArg_ParseTuple(args, "s:info", &filename))
+    if (create_args("info", args, &argc, &argv) < 0)  
         return NULL;
         return NULL;
-
-    if (!rrd_open(filename, &rrd, RRD_READONLY) == -1) {
+     
+    if ((data = rrd_info(argc, argv)) == NULL) {
         PyErr_SetString(ErrorObject, rrd_get_error());
         rrd_clear_error();
         return NULL;
     }
         PyErr_SetString(ErrorObject, rrd_get_error());
         rrd_clear_error();
         return NULL;
     }
-#define DICTSET_STR(dict, name, value) \
-    t = PyString_FromString(value); \
-    PyDict_SetItemString(dict, name, t); \
-    Py_DECREF(t);
-
-#define DICTSET_CNT(dict, name, value) \
-    t = PyInt_FromLong((long)value); \
-    PyDict_SetItemString(dict, name, t); \
-    Py_DECREF(t);
-
-#define DICTSET_VAL(dict, name, value) \
-    t = isnan(value) ? (Py_INCREF(Py_None), Py_None) :  \
-        PyFloat_FromDouble((double)value); \
-    PyDict_SetItemString(dict, name, t); \
-    Py_DECREF(t);
-
-    r = PyDict_New();
-
-    DICTSET_STR(r, "filename", filename);
-    DICTSET_STR(r, "rrd_version", rrd.stat_head->version);
-    DICTSET_CNT(r, "step", rrd.stat_head->pdp_step);
-    DICTSET_CNT(r, "last_update", rrd.live_head->last_up);
-
-    ds = PyDict_New();
-    PyDict_SetItemString(r, "ds", ds);
-    Py_DECREF(ds);
-
-    for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
-        PyObject *d;
-
-        d = PyDict_New();
-        PyDict_SetItemString(ds, rrd.ds_def[i].ds_nam, d);
-        Py_DECREF(d);
-
-        DICTSET_STR(d, "ds_name", rrd.ds_def[i].ds_nam);
-        DICTSET_STR(d, "type", rrd.ds_def[i].dst);
-        DICTSET_CNT(d, "minimal_heartbeat",
-                    rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt);
-        DICTSET_VAL(d, "min", rrd.ds_def[i].par[DS_min_val].u_val);
-        DICTSET_VAL(d, "max", rrd.ds_def[i].par[DS_max_val].u_val);
-        DICTSET_STR(d, "last_ds", rrd.pdp_prep[i].last_ds);
-        DICTSET_VAL(d, "value", rrd.pdp_prep[i].scratch[PDP_val].u_val);
-        DICTSET_CNT(d, "unknown_sec",
-                    rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt);
-    }
-
-    ds = PyList_New(rrd.stat_head->rra_cnt);
-    PyDict_SetItemString(r, "rra", ds);
-    Py_DECREF(ds);
-
-    for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
-        PyObject *d, *cdp;
+    r = PyDict_FromInfo(data);
+    info_free(data);
+    return r;
+}
 
 
-        d = PyDict_New();
-        PyList_SET_ITEM(ds, i, d);
+static char PyRRD_graphv__doc__[] =
+    "graphv is called in the same manner as graph";
 
 
-        DICTSET_STR(d, "cf", rrd.rra_def[i].cf_nam);
-        DICTSET_CNT(d, "rows", rrd.rra_def[i].row_cnt);
-        DICTSET_CNT(d, "pdp_per_row", rrd.rra_def[i].pdp_cnt);
-        DICTSET_VAL(d, "xff", rrd.rra_def[i].par[RRA_cdp_xff_val].u_val);
+static PyObject *PyRRD_graphv(
+    PyObject UNUSED(*self),
+    PyObject * args)
+{
+    PyObject *r;
+    int       argc;
+    char    **argv;
+    info_t   *data;
 
 
-        cdp = PyList_New(rrd.stat_head->ds_cnt);
-        PyDict_SetItemString(d, "cdp_prep", cdp);
-        Py_DECREF(cdp);
+    if (create_args("graphv", args, &argc, &argv) < 0)  
+        return NULL;
+     
+    if ((data = rrd_graph_v(argc, argv)) == NULL) {
+        PyErr_SetString(ErrorObject, rrd_get_error());
+        rrd_clear_error();
+        return NULL;
+    }
+    r = PyDict_FromInfo(data);
+    info_free(data);
+    return r;
+}
 
 
-        for (j = 0; j < rrd.stat_head->ds_cnt; j++) {
-            PyObject *cdd;
+static char PyRRD_updatev__doc__[] =
+    "updatev is called in the same manner as update";
 
 
-            cdd = PyDict_New();
-            PyList_SET_ITEM(cdp, j, cdd);
+static PyObject *PyRRD_updatev(
+    PyObject UNUSED(*self),
+    PyObject * args)
+{
+    PyObject *r;
+    int       argc;
+    char    **argv;
+    info_t   *data;
 
 
-            DICTSET_VAL(cdd, "value",
-                        rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
-                                     j].scratch[CDP_val].u_val);
-            DICTSET_CNT(cdd, "unknown_datapoints",
-                        rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
-                                     j].scratch[CDP_unkn_pdp_cnt].u_cnt);
-        }
+    if (create_args("updatev", args, &argc, &argv) < 0)  
+        return NULL;
+     
+    if ((data = rrd_update_v(argc, argv)) == NULL) {
+        PyErr_SetString(ErrorObject, rrd_get_error());
+        rrd_clear_error();
+        return NULL;
     }
     }
-
-    rrd_free(&rrd);
-
+    r = PyDict_FromInfo(data);
+    info_free(data);
     return r;
 }
 
     return r;
 }
 
@@ -520,6 +525,8 @@ static PyMethodDef _rrdtool_methods[] = {
     meth("last", PyRRD_last, PyRRD_last__doc__),
     meth("resize", PyRRD_resize, PyRRD_resize__doc__),
     meth("info", PyRRD_info, PyRRD_info__doc__),
     meth("last", PyRRD_last, PyRRD_last__doc__),
     meth("resize", PyRRD_resize, PyRRD_resize__doc__),
     meth("info", PyRRD_info, PyRRD_info__doc__),
+    meth("graphv", PyRRD_graphv, PyRRD_graphv__doc__),
+    meth("updatev", PyRRD_updatev, PyRRD_updatev__doc__),
     {NULL, NULL, 0, NULL}
 };
 
     {NULL, NULL, 0, NULL}
 };
 
index dc329ec..d504deb 100644 (file)
@@ -18,6 +18,7 @@ to the other B<rrdtool> documentation for functions and valid arguments.
 
 =head1 EXAMPLE
 
 
 =head1 EXAMPLE
 
+ import sys
  sys.path.append('/path/to/rrdtool/lib/python2.3/site-packages/')
  import rrdtool, tempfile
 
  sys.path.append('/path/to/rrdtool/lib/python2.3/site-packages/')
  import rrdtool, tempfile