Normalise the filenames of the RRDs
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 May 2015 20:57:49 +0000 (20:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 May 2015 20:57:49 +0000 (20:57 +0000)
src/collecty/plugins/base.py

index 6c31ede..32afb02 100644 (file)
@@ -275,7 +275,19 @@ class Object(object):
                """
                        The absolute path to the RRD file of this plugin.
                """
-               return os.path.join(DATABASE_DIR, self.plugin.path, "%s.rrd" % self.id)
+               filename = self._normalise_filename("%s.rrd" % self.id)
+
+               return os.path.join(DATABASE_DIR, self.plugin.path, filename)
+
+       @staticmethod
+       def _normalise_filename(filename):
+               # Convert the filename into ASCII characters only
+               filename = filename.encode("ascii", "ignore")
+
+               # Replace any spaces by dashes
+               filename = filename.replace(" ", "-")
+
+               return filename
 
        ### Basic methods