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
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;
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>
-