Change default image format to SVG
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 May 2015 18:46:20 +0000 (18:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 May 2015 18:46:20 +0000 (18:46 +0000)
SVG is much better scalable and much faster to generate.
It can be resized and exported very well and therefore is
our preferred choice for graph images for now.

The image format can be requested when generating a graph
image.

src/collecty/client.py
src/collecty/constants.py
src/collecty/plugins/base.py

index 4570c69..1f07225 100644 (file)
@@ -56,6 +56,7 @@ class CollectyClient(object):
 
        def generate_graph_cli(self, ns):
                kwargs = {
+                       "format"    : ns.format,
                        "object_id" : ns.object,
                }
 
@@ -85,6 +86,8 @@ class CollectyClient(object):
                parser_generate_graph.set_defaults(func=self.generate_graph_cli)
                parser_generate_graph.add_argument("--filename",
                        help=_("filename"), required=True)
+               parser_generate_graph.add_argument("--format",
+                       help=_("image format"), default=DEFAULT_IMAGE_FORMAT)
                parser_generate_graph.add_argument("--interval", help=_("interval"))
                parser_generate_graph.add_argument("--object",
                        help=_("Object identifier"), default="default")
index 6094808..8580d14 100644 (file)
@@ -25,10 +25,9 @@ DATABASE_DIR = "/var/lib/collecty"
 
 BUS_DOMAIN = "org.ipfire.collecty1"
 
-GRAPH_DEFAULT_ARGUMENTS = (
-       # Always generate graphs in PNG format.
-       "--imgformat", "PNG",
+DEFAULT_IMAGE_FORMAT = "SVG"
 
+GRAPH_DEFAULT_ARGUMENTS = (
        # Disable the border around the image.
        "--border", "0",
 
index 8d38cad..74bc712 100644 (file)
@@ -410,12 +410,14 @@ class GraphTemplate(object):
        def log(self):
                return self.plugin.log
 
-       def _make_command_line(self, interval, width=None, height=None):
+       def _make_command_line(self, interval, format=DEFAULT_IMAGE_FORMAT,
+                       width=None, height=None):
                args = []
 
                args += GRAPH_DEFAULT_ARGUMENTS
 
                args += [
+                       "--imgformat", format,
                        "--height", "%s" % (height or self.height),
                        "--width", "%s" % (width or self.width),
                ]
@@ -462,6 +464,9 @@ class GraphTemplate(object):
                return self.write_graph(*args)
 
        def write_graph(self, *args):
+               # Convert all arguments to string
+               args = [str(e) for e in args]
+
                with tempfile.NamedTemporaryFile() as f:
                        rrdtool.graph(f.name, *args)