diff --git a/modoboa/extensions/stats/graphics.py b/modoboa/extensions/stats/graphics.py index d7f657ba9..80ca0af88 100644 --- a/modoboa/extensions/stats/graphics.py +++ b/modoboa/extensions/stats/graphics.py @@ -7,10 +7,12 @@ from modoboa.lib.sysutils import exec_cmd class Curve(object): + """Graphic curve. Simple way to represent a graphic curve. """ + def __init__(self, dsname, color, legend, cfunc="AVERAGE"): """Constructor. """ @@ -37,9 +39,11 @@ class Curve(object): class Graphic(object): + """Graphic. """ + def __init__(self): """Constructor. """ @@ -76,7 +80,7 @@ class Graphic(object): cmdargs += curve.to_rrd_command_args(rrdfile) cmd = "rrdtool xport --start %s --end %s " % (str(start), str(end)) cmd += " ".join(cmdargs) - if type(cmd) is unicode: + if isinstance(cmd, unicode): cmd = cmd.encode("utf-8") code, output = exec_cmd(cmd) if code: @@ -95,6 +99,7 @@ class Graphic(object): class AverageTraffic(Graphic): + """Average traffic. """ title = ugettext_lazy('Average traffic (msgs/min)') @@ -109,6 +114,7 @@ class AverageTraffic(Graphic): class AverageTrafficSize(Graphic): + """Average traffic size. """ title = ugettext_lazy('Average normal traffic size (bytes/min)') diff --git a/modoboa/extensions/stats/lib.py b/modoboa/extensions/stats/lib.py index c71e5b59d..9d78c039f 100644 --- a/modoboa/extensions/stats/lib.py +++ b/modoboa/extensions/stats/lib.py @@ -12,7 +12,7 @@ def date_to_timestamp(timetuple): :return: an integer """ date = " ".join( - [("%d" % elem) if type(elem) is int else elem for elem in timetuple] + [("%d" % elem) if isinstance(elem, int) else elem for elem in timetuple] ) fmt = "%Y %m %d %H %M %S" \ if timetuple[1].isdigit() else "%Y %b %d %H %M %S" diff --git a/modoboa/extensions/stats/management/commands/logparser.py b/modoboa/extensions/stats/management/commands/logparser.py index c622c5e05..3613f056b 100644 --- a/modoboa/extensions/stats/management/commands/logparser.py +++ b/modoboa/extensions/stats/management/commands/logparser.py @@ -21,10 +21,11 @@ import time import sys import os import re -import rrdtool import string from optparse import make_option +import rrdtool + from django.core.management.base import BaseCommand from modoboa.core.extensions import exts_pool @@ -71,9 +72,11 @@ class LogParser(object): self.workdict = {} self.lupdates = {} self._s_date_expr = \ - re.compile(r"(?P\w+)\s+(?P\d+)\s+(?P\d+):(?P\d+):(?P\d+)(?P.*)") + re.compile( + r"(?P\w+)\s+(?P\d+)\s+(?P\d+):(?P\d+):(?P\d+)(?P.*)") self._hp_date_expr = \ - re.compile(r"(?P\d+)-(?P\d+)-(?P\d+)T(?P\d+):(?P\d+):(?P\d+)\.\d+\+\d+:\d+(?P.*)") + re.compile( + r"(?P\d+)-(?P\d+)-(?P\d+)T(?P\d+):(?P\d+):(?P\d+)\.\d+\+\d+:\d+(?P.*)") self.date_expr = None self.line_expr = \ re.compile(r"\s+([-\w]+)\s+(\w+)/?\w*[[](\d+)[]]:\s+(.*)") @@ -200,7 +203,7 @@ class LogParser(object): self.lupdates[fname] = self.init_rrd(fname, m) self._dprint("[rrd] create new RRD file %s" % fname) else: - if not fname in self.lupdates: + if fname not in self.lupdates: self.lupdates[fname] = rrdtool.last(str(fname)) if m <= self.lupdates[fname]: @@ -250,11 +253,11 @@ class LogParser(object): def inc_counter(self, dom, counter, val=1): if dom is not None and dom in self.domains: - if not self.cur_t in self.data[dom]: + if self.cur_t not in self.data[dom]: self.initcounters(dom) self.data[dom][self.cur_t][counter] += val - if not self.cur_t in self.data["global"]: + if self.cur_t not in self.data["global"]: self.initcounters("global") self.data["global"][self.cur_t][counter] += val @@ -299,7 +302,9 @@ class LogParser(object): return (line_id, line_log) = m.groups() if line_id == "NOQUEUE": - addrto = re.match("reject: .*from=<.*> to=<[^@]+@([^>]+)>", line_log) + addrto = re.match( + "reject: .*from=<.*> to=<[^@]+@([^>]+)>", + line_log) if addrto and addrto.group(1) in self.domains: self.inc_counter(addrto.group(1), 'reject') return @@ -316,9 +321,9 @@ class LogParser(object): m = re.search("to=<([^>]*)>.*status=(\S+)", line_log) if m is not None: - if not line_id in self.workdict: - self._dprint("Inconsistent mail (%s: %s), skipping" \ - % (line_id, m.group(1))) + if line_id not in self.workdict: + self._dprint("Inconsistent mail (%s: %s), skipping" + % (line_id, m.group(1))) return if not m.group(2) in variables: self._dprint("Unsupported status %s, skipping" % m.group(2)) diff --git a/modoboa/extensions/stats/views.py b/modoboa/extensions/stats/views.py index 49e1570d9..b16756408 100644 --- a/modoboa/extensions/stats/views.py +++ b/modoboa/extensions/stats/views.py @@ -1,4 +1,7 @@ # coding: utf-8 + +"""Custom views.""" + import re import time from django.shortcuts import render @@ -83,7 +86,7 @@ def check_domain_access(user, pattern): def graphs(request): gset = request.GET.get("gset", None) gsets = events.raiseDictEvent("GetGraphSets") - if not gset in gsets: + if gset not in gsets: raise NotFound(_("Unknown graphic set")) searchq = request.GET.get("searchquery", None) period = request.GET.get("period", "day") @@ -94,7 +97,7 @@ def graphs(request): tplvars["domain"] = domain if period == "custom": - if not "start" in request.GET or not "end" in request.GET: + if "start" not in request.GET or "end" not in request.GET: raise BadRequest(_("Bad custom period")) start = request.GET["start"] end = request.GET["end"]