]> git.ipfire.org Git - collecty.git/blobdiff - src/collecty/plugins/base.py
psi: Add graph template
[collecty.git] / src / collecty / plugins / base.py
index 8f122555dcd8e74751c2cb89d5a105168d3cf3c3..e8f8f308c0e2d6a842d3b112c1be1a8693e886cf 100644 (file)
@@ -40,9 +40,9 @@ class Environment(object):
        def __init__(self, timezone="UTC", locale="en_US.utf-8"):
                # Build the new environment
                self.new_environment = {
-                       "LANG"   : locale,
-                       "LC_ALL" : locale,
-                       "TZ"     : timezone,
+                       "LANGUAGE" : locale,
+                       "LC_ALL"   : locale,
+                       "TZ"       : timezone,
                }
 
        def __enter__(self):
@@ -50,10 +50,12 @@ class Environment(object):
                self.old_environment = {}
 
                for k in self.new_environment:
+                       # Store the old value
                        self.old_environment[k] = os.environ.get(k, None)
 
-               # Apply the new one
-               os.environ.update(self.new_environment)
+                       # Apply the new one
+                       if self.new_environment[k]:
+                               os.environ[k] = self.new_environment[k]
 
        def __exit__(self, type, value, traceback):
                # Roll back to the previous environment
@@ -446,8 +448,11 @@ class Object(object):
                """
                filename = os.path.join(*args)
 
-               with open(filename) as f:
-                       value = f.read()
+               try:
+                       with open(filename) as f:
+                               value = f.read()
+               except FileNotFoundError as e:
+                       return None
 
                # Strip any excess whitespace
                if strip:
@@ -463,7 +468,7 @@ class Object(object):
 
                try:
                        return int(value)
-               except ValueError:
+               except (TypeError, ValueError):
                        return None
 
        def read_proc_stat(self):
@@ -584,13 +589,13 @@ class GraphTemplate(object):
                ]
 
                # Set the default dimensions
-               default_height, default_width = 960, 480
+               default_width, default_height = 960, 480
 
                # A thumbnail doesn't have a legend and other labels
                if thumbnail:
                        args.append("--only-graph")
 
-                       default_height, default_width = 80, 20
+                       default_width, default_height = 80, 20
 
                args += [
                        "--imgformat", format,