rrdweb/rrd.py
changeset 29 c756e522c9ac
parent 5 e716718482c3
child 32 47e977c23ba2
--- a/rrdweb/rrd.py	Wed Nov 03 00:51:06 2010 +0200
+++ b/rrdweb/rrd.py	Sun Jan 23 13:50:13 2011 +0200
@@ -1,9 +1,13 @@
-import rrdtool
-
 """
     Friendly wrapper around the rrdtool python interface
 """
 
+import rrdtool
+
+import logging
+
+log = logging.getLogger('rrdweb.rrd')
+
 def normalize_option_key (key) :
     """
         Normalize the given option key.
@@ -44,7 +48,7 @@
     
     elif isinstance(value, list) :
         # list of option values
-        return normalize_option_multi(key, value)
+        return tuple(normalize_option_multi(key, value))
 
     else :
         # option value
@@ -68,10 +72,10 @@
         Run the given rrdtool.* function, formatting the given positional arguments and options.
     """
     
-    # series of (cmd-arg, cmd-arg, ...) tuples
+    # series of (cmd-arg, cmd-arg, ...) tuples, giving all '--opt' and 'value' arguments for each keyword argument
     opt_items = (normalize_option(key, value) for key, value in opts.iteritems())
 
-    # decomposed series of cmd-args
+    # decomposed series of cmd-args for options
     opt_args = [item for items in opt_items for item in items]
 
     # positional arguments
@@ -79,10 +83,36 @@
     post_args = [str(arg) for arg in post_args]
 
     # full arguments
-    args = pre_args + opt_args + post_args
+    args = pre_args + opt_args + ['--'] + post_args
+
+    log.debug('rrdtool %s %s', func.__name__, args)
 
     return func(*args)
 
 def graph (out_path, *args, **opts) :
+    """
+        Create a graph from data stored in one or several RRDs.
+
+        Graph image output is written to the given path.
+
+        Returns... something to do with the image's dimensions, or even the data itself?
+    """
+
     return run_cmd(rrdtool.graph, (out_path, ), opts, args)
 
+def create (rrd_path, *args, **opts) :
+    """
+        Set up a new Round Robin Database (RRD).
+    """
+
+    return run_cmd(rrdtool.create, (rrd_path, ), opts, args)
+
+def update (rrd_path, *args, **opts) :
+    """
+        Store new data values into an RRD.
+    """
+
+    return run_cmd(rrdtool.update, (rrd_path, ), opts, args)
+
+
+