summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e33406d)
raw | patch | inline | side by side (parent: e33406d)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 6 Apr 2009 14:49:03 +0000 (14:49 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 6 Apr 2009 14:49:03 +0000 (14:49 +0000) |
parameters to python bindings as a list (array) of strings. -- Vytautas Zdanavicius vytaszd at yahoo.com
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1771 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1771 a5681a0c-68f1-0310-ab6d-d61299d08faa
CONTRIBUTORS | patch | blob | history | |
bindings/python/rrdtoolmodule.c | patch | blob | history | |
doc/rrdpython.pod | patch | blob | history |
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 29bbcae6d95fad221e84a8c32075407c5d83f9ef..9fcddbdc2c7f3fd06c3e4fabe0463bda3593faf1 100644 (file)
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
Wolfgang Schrimm <wschrimm with uni-hd.de> xport function
Wrolf Courtney <wrolf with wrolf.net> (HP-UX)
hendrik visage <hvisage with is.co.za>
+Vytautas Zdanavicius <vytaszd@yahoo.com> -- python argument list exander
Martin Sperl <rrdtool martin.sperl.org> (CDEF prediction functions, libdbi)
Philippe Simonet <philippe.simonet with swisscom.ch> (Windows Binaries)
-Alexander Lucke (lucke with dns-net.de)
- of DNS:NET Internet Services (www.dns-net.de) http://rrdtool.org
+Alexander Lucke (lucke with dns-net.de) of DNS:NET Internet Services (www.dns-net.de) http://rrdtool.org
Hedley Simons <heds@metahusky.net>
Nicola Worthington <nicolaw@cpan.org>
Wegmann, Christof <Christof.Wegmann@exitgames.com> 1.3/trunk win32 port
index bd16da17e69ffee7f30c29210dc7569c4001caa6..6cc22ad632eabaf17dbaad6f8040f3ac3960db3c 100644 (file)
int *argc,
char ***argv)
{
- PyObject *o;
- int size, i;
-
- size = PyTuple_Size(args);
+ PyObject *o, *lo;
+ int args_count,
+ argv_count,
+ element_count,
+ i, j;
+
+ args_count = PyTuple_Size(args);
+ element_count = 0;
+ for (i = 0; i < args_count; i++) {
+ o = PyTuple_GET_ITEM(args, i);
+ if (PyString_Check(o))
+ element_count++;
+ else if (PyList_CheckExact(o))
+ element_count += PyList_Size(o);
+ else {
+ PyErr_Format(PyExc_TypeError, "argument %d must be string or list of strings", i);
+ return -1;
+ }
+ }
+
*argv = PyMem_New(char *,
- size + 1);
+ element_count + 1);
if (*argv == NULL)
return -1;
- for (i = 0; i < size; i++) {
+ argv_count = 0;
+ for (i = 0; i < args_count; i++) {
o = PyTuple_GET_ITEM(args, i);
- if (PyString_Check(o))
- (*argv)[i + 1] = PyString_AS_STRING(o);
- else {
- PyMem_Del(*argv);
- PyErr_Format(PyExc_TypeError, "argument %d must be string", i);
- return -1;
- }
+ if (PyString_Check(o)) {
+ argv_count++;
+ (*argv)[argv_count] = PyString_AS_STRING(o);
+ } else if (PyList_CheckExact(o))
+ for (j = 0; j < PyList_Size(o); j++) {
+ lo = PyList_GetItem(o, j);
+ if (PyString_Check(lo)) {
+ argv_count++;
+ (*argv)[argv_count] = PyString_AS_STRING(lo);
+ } else {
+ PyMem_Del(*argv);
+ PyErr_Format(PyExc_TypeError, "element %d in argument %d must be string", j, i);
+ return -1;
+ }
+ }
+ else {
+ PyMem_Del(*argv);
+ PyErr_Format(PyExc_TypeError, "argument %d must be string or list of strings", i);
+ return -1;
+ }
}
+
(*argv)[0] = command;
- *argc = size + 1;
+ *argc = element_count + 1;
/* reset getopt state */
opterr = optind = 0;
diff --git a/doc/rrdpython.pod b/doc/rrdpython.pod
index f041b0b59b0eed011bb592a1c6d48f3de0cf9879..b6f90756a944c7ea2834d6cb04907a8637350ba1 100644 (file)
--- a/doc/rrdpython.pod
+++ b/doc/rrdpython.pod
language. This wrapper implementation has been written from the scratch
(without SWIG)
-The API's simply expects string parameters to the functions. Please refer
-to the other B<rrdtool> documentation for functions and valid arguments.
+The API's expects strings and/or list of strings as parameters to the functions.
+Please refer to the other B<rrdtool> documentation for functions and valid arguments.
-=head1 EXAMPLE
+=head1 EXAMPLES
+
+=head2 Example 1
import sys
- sys.path.append('/path/to/rrdtool/lib/python2.3/site-packages/')
+ sys.path.append('/path/to/rrdtool/lib/python2.6/site-packages/')
import rrdtool, tempfile
DAY = 86400
print info['last_update']
print info['ds']['downloads']['minimal_heartbeat']
+=head2 Example 2
+
+ import sys
+ sys.path.append('/path/to/rrdtool/lib/python2.6/site-packages/')
+ import rrdtool
+
+ # in real life data_sources would be populated in loop or something similar
+ data_sources=[ 'DS:speed1:COUNTER:600:U:U',
+ 'DS:speed2:COUNTER:600:U:U',
+ 'DS:speed3:COUNTER:600:U:U' ]
+
+ rrdtool.create( 'speed.rrd',
+ '--start', '920804400',
+ data_sources,
+ 'RRA:AVERAGE:0.5:1:24',
+ 'RRA:AVERAGE:0.5:6:10' )
+
If you use the B<site-python-install> make target you can drop to first sys.path.append
line since the rrdtool module will be available everywhere.
Hye-Shik Chang E<lt>perky@i18n.orgE<gt>
Alan Milligan E<lt>alan.milligan@last-bastion.netE<gt>
-