summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 33e59bb)
raw | patch | inline | side by side (parent: 33e59bb)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sat, 28 Jul 2012 13:54:59 +0000 (13:54 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sat, 28 Jul 2012 13:54:59 +0000 (13:54 +0000) |
program/bindings/python/rrdtoolmodule.c | patch | blob | history | |
program/bindings/python/setup.py | patch | blob | history |
index a2647b50f788f908e44571625581e617ce3a6ef3..fdf4121ce9027206c4c8cdcc083b4611e3ddb9a8 100644 (file)
return r;
}
+static char PyRRD_xport__doc__[] =
+ "xport(args..): dictionary representation of data stored in RRDs\n"
+ " [-s|--start seconds] [-e|--end seconds] [-m|--maxrows rows]"
+ "[--step value] [--daemon address] [DEF:vname=rrd:ds-name:CF]"
+ "[CDEF:vname=rpn-expression] [XPORT:vname[:legend]]";
+
+
+static PyObject *PyRRD_xport(
+ PyObject UNUSED(*self),
+ PyObject * args)
+{
+ PyObject *r;
+ int argc, xsize;
+ char **argv, **legend_v;
+ time_t start, end;
+ unsigned long step, col_cnt;
+ rrd_value_t *data, *datai;
+
+ if (create_args("xport", args, &argc, &argv) < 0)
+ return NULL;
+
+ if (rrd_xport(argc, argv, &xsize, &start, &end,
+ &step, &col_cnt, &legend_v, &data) == -1) {
+ PyErr_SetString(ErrorObject, rrd_get_error());
+ rrd_clear_error();
+ r = NULL;
+ } else {
+ PyObject *meta_dict, *data_list, *legend_list, *t;
+ unsigned long i, j;
+ rrd_value_t dv;
+
+ unsigned long row_cnt = (end - start) / step;
+
+ r = PyDict_New();
+ meta_dict = PyDict_New();
+ legend_list = PyList_New(col_cnt);
+ data_list = PyList_New(row_cnt);
+ PyDict_SetItem(r, PyString_FromString("meta"), meta_dict);
+ PyDict_SetItem(r, PyString_FromString("data"), data_list);
+
+ datai = data;
+
+ PyDict_SetItem(meta_dict, PyString_FromString("start"), PyInt_FromLong((long) start));
+ PyDict_SetItem(meta_dict, PyString_FromString("end"), PyInt_FromLong((long) end));
+ PyDict_SetItem(meta_dict, PyString_FromString("step"), PyInt_FromLong((long) step));
+ PyDict_SetItem(meta_dict, PyString_FromString("rows"), PyInt_FromLong((long) row_cnt));
+ PyDict_SetItem(meta_dict, PyString_FromString("columns"), PyInt_FromLong((long) col_cnt));
+ PyDict_SetItem(meta_dict, PyString_FromString("legend"), legend_list);
+
+ for (i = 0; i < col_cnt; i++) {
+ PyList_SET_ITEM(legend_list, i, PyString_FromString(legend_v[i]));
+ }
+
+ for (i = 0; i < row_cnt; i++) {
+ t = PyTuple_New(col_cnt);
+ PyList_SET_ITEM(data_list, i, t);
+
+ for (j = 0; j < col_cnt; j++) {
+ dv = *(datai++);
+ if (isnan(dv)) {
+ PyTuple_SET_ITEM(t, j, Py_None);
+ Py_INCREF(Py_None);
+ } else {
+ PyTuple_SET_ITEM(t, j, PyFloat_FromDouble((double) dv));
+ }
+ }
+ }
+
+ for (i = 0; i < col_cnt; i++) {
+ rrd_freemem(legend_v[i]);
+ }
+ rrd_freemem(legend_v);
+ rrd_freemem(data);
+ }
+ destroy_args(&argv);
+ return r;
+}
+
/* List of methods defined in the module */
#define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc}
meth("graphv", PyRRD_graphv, PyRRD_graphv__doc__),
meth("updatev", PyRRD_updatev, PyRRD_updatev__doc__),
meth("flushcached", PyRRD_flushcached, PyRRD_flushcached__doc__),
+ meth("xport", PyRRD_xport, PyRRD_xport__doc__),
{NULL, NULL, 0, NULL}
};
index 83f35b6caff85cdc1492d6fcffba62bfe6029f29..1b024144be99a041a74159e9f11a54acbebb42c1 100644 (file)
include_dir = os.environ.get('INCDIR', RRDBASE)
setup(name = "py-rrdtool",
- version = "0.2.1",
+ version = "0.2.2",
description = "Python Interface to RRDTool",
author = "Hye-Shik Chang",
author_email = "perky@fallin.lv",