]> git.ipfire.org Git - collecty.git/commitdiff
Generate graphs in memory
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 May 2015 23:07:55 +0000 (23:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 May 2015 23:07:55 +0000 (23:07 +0000)
Remove Python 2 hack that created a temporary file on disk
in which the graph was written and then read the file content
back in. The Python 3 module allows us to write the graph
directly into a buffer.

src/collecty/plugins/base.py

index 476c134785a7d1dc95e3a4de0f4db646babedecc..004b2a16779476631e5108a15214ec8350c3d23e 100644 (file)
@@ -483,17 +483,9 @@ class GraphTemplate(object):
 
                        self.log.debug("  %s" % args[-1])
 
-               return self.write_graph(*args)
-
-       def write_graph(self, *args):
-               # Convert all arguments to string
+               # Convert arguments to string
                args = [str(e) for e in args]
 
-               with tempfile.NamedTemporaryFile() as f:
-                       rrdtool.graph(f.name, *args)
-
-                       # Get back to the beginning of the file
-                       f.seek(0)
+               graph = rrdtool.graphv("-", *args)
 
-                       # Return all the content
-                       return f.read()
+               return graph.get("image")