]> git.ipfire.org Git - collecty.git/commitdiff
Remove or move as many constants as possible
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 16:40:13 +0000 (16:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2020 16:40:13 +0000 (16:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/constants.py
src/collecty/locales.py
src/collecty/plugins/base.py
src/collecty/util.py

index 6b8f97cfab40085478108c842d4927c62b533bee..cfe3c042e5e8a69594459814ea935a22b3727afd 100644 (file)
 #                                                                             #
 ###############################################################################
 
-from .i18n import _
-
 from .__version__ import *
 
 DATABASE_DIR = "/var/lib/collecty"
 
 DEFAULT_IMAGE_FORMAT = "SVG"
-DEFAULT_LOCALE = "en_GB.utf8"
-DEFAULT_TIMEZONE = "UTC"
-
 SUPPORTED_IMAGE_FORMATS = ("SVG", "PNG", "PDF")
 
-GRAPH_DEFAULT_ARGUMENTS = (
-       # Change the background colour
-       "--color", "BACK#FFFFFFFF",
-
-       # Disable the border around the image.
-       "--border", "0",
-
-       # Let's width and height define the size of
-       # the entire image.
-       "--full-size-mode",
-
-       # Gives the curves a more organic look.
-       "--slope-mode",
-
-       # Show nicer labels.
-       "--dynamic-labels",
-
-       # Brand all generated graphs.
-       "--watermark", _("Created by collecty"),
-)
-
-INTERVALS = {
-       None   : "-3h",
-       "hour" : "-1h",
-       "day"  : "-25h",
-       "month": "-30d",
-       "week" : "-360h",
-       "year" : "-365d",
-}
-
-GRAPH_DEFAULT_WIDTH = 960
-GRAPH_DEFAULT_HEIGHT = 480
-
 # Default column widths
 LABEL         = "%-30s"
 EMPTY_LABEL   = "%32s" % ""
@@ -81,5 +43,3 @@ MS            = "%11.2lf ms"
 EMPTY_LINE    = "COMMENT: \\n"
 HEADLINE      = "COMMENT:---- %s ----\\c"
 
-THUMBNAIL_DEFAULT_WIDTH = 80
-THUMBNAIL_DEFAULT_HEIGHT = 20
index d656e5a8fca698226a6582d35a6de4bae1ddedb3..c6051db844591005e6c587caf5ca9ddc57ffc221 100644 (file)
@@ -28,6 +28,8 @@ from .i18n import TEXTDOMAIN
 
 log = logging.getLogger("collecty.locale")
 
+DEFAULT_LOCALE = "en_US.utf-8"
+
 class Locale(object):
        def __init__(self, lang):
                self.lang = lang
index 04180027520ffc0c512592db672bf2559ea2bf43..7c97aef54ebf97a44769975dda3ae68b0716d14a 100644 (file)
@@ -41,15 +41,16 @@ class Environment(object):
        def __init__(self, timezone, locale):
                # Build the new environment
                self.new_environment = {
-                       "TZ" : timezone or DEFAULT_TIMEZONE,
+                       "TZ" : timezone or "UTC",
                }
 
                for k in ("LANG", "LC_ALL"):
-                       self.new_environment[k] = locale or DEFAULT_LOCALE
+                       self.new_environment[k] = locale or "en_US.utf-8"
 
        def __enter__(self):
                # Save the current environment
                self.old_environment = {}
+
                for k in self.new_environment:
                        self.old_environment[k] = os.environ.get(k, None)
 
@@ -528,10 +529,6 @@ class GraphTemplate(object):
        # Extra arguments passed to rrdgraph.
        rrd_graph_args = []
 
-       # Default dimensions for this graph
-       height = GRAPH_DEFAULT_HEIGHT
-       width  = GRAPH_DEFAULT_WIDTH
-
        def __init__(self, plugin, object_id, locale=None, timezone=None):
                self.plugin = plugin
 
@@ -567,17 +564,34 @@ class GraphTemplate(object):
 
        def _make_command_line(self, interval, format=DEFAULT_IMAGE_FORMAT,
                        width=None, height=None, with_title=True, thumbnail=False):
-               args = [e for e in GRAPH_DEFAULT_ARGUMENTS]
+               args = [
+                       # Change the background colour
+                       "--color", "BACK#FFFFFFFF",
+
+                       # Disable the border around the image
+                       "--border", "0",
+
+                       # Let's width and height define the size of the entire image
+                       "--full-size-mode",
+
+                       # Gives the curves a more organic look
+                       "--slope-mode",
+
+                       # Show nicer labels
+                       "--dynamic-labels",
+
+                       # Brand all generated graphs
+                       "--watermark", _("Created by collecty"),
+               ]
 
                # Set the default dimensions
-               default_height, default_width = GRAPH_DEFAULT_HEIGHT, GRAPH_DEFAULT_WIDTH
+               default_height, default_width = 960, 480
 
                # A thumbnail doesn't have a legend and other labels
                if thumbnail:
                        args.append("--only-graph")
 
-                       default_height = THUMBNAIL_DEFAULT_HEIGHT
-                       default_width = THUMBNAIL_DEFAULT_WIDTH
+                       default_height, default_width = 80, 20
 
                args += [
                        "--imgformat", format,
index ecb39b54b4ecb7d46fada4a552a67a63cadf2ff4..acb3f5fc19980ecc60fd0e4778316f0451d09b2c 100644 (file)
@@ -42,8 +42,17 @@ def get_network_interfaces():
                yield interface
 
 def make_interval(interval):
+       intervals = {
+               None   : "-3h",
+               "hour" : "-1h",
+               "day"  : "-25h",
+               "month": "-30d",
+               "week" : "-360h",
+               "year" : "-365d",
+       }
+
        try:
-               return INTERVALS[interval]
+               return intervals[interval]
        except KeyError:
                return "end-%s" % interval