From: Michael Tremer Date: Wed, 27 May 2015 23:07:55 +0000 (+0000) Subject: Generate graphs in memory X-Git-Tag: 003~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=699e99fb2b79584279fac170f7926165f09495fc;p=collecty.git Generate graphs in memory 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. --- diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index 476c134..004b2a1 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -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")