nixspamsum
author Pascal Volk <user@localhost.localdomain.org>
Mon, 08 Jun 2009 16:10:07 +0000
changeset 2 a72ea07394cc
parent 1 7d5cee19c20a
child 3 6b0d09cdfbdb
permissions -rwxr-xr-x
NiXSapmSum.getTotal(): deleted buildTable(): implemented showResult(): generate output via cStringIO.StringIO moved table stuff to the new function buildTable() main(): check if output format is supported before any action
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     1
#!/usr/bin/env python
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     3
# Copyright 2009 Pascal Volk
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     4
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     5
__author__ = 'Pascal Volk'
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
     6
__version__ = '0.1.1'
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
     7
__date__ = '2009-06-08'
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     8
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     9
import os
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    10
import re
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    11
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    12
class NiXSapmSum:
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    13
    """Do sth ..."""
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    14
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    15
    """Regular expression pattern for mail logs from Postfix"""
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    16
    RE_PF = '''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{3,5}\]: NOQUEUE: reject:.*blocked using ix.dnsbl.manitu.net; Spam sent to the mailhost ((?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}) was detected by NiX Spam.*$'''
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    17
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    18
    def __init__(self):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    19
        self._doms = {}
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    20
        self._mxs  = {}
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    21
        self._repo = None
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    22
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    23
    def setLogFormat(self, format='postfix'):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    24
        if format == 'postfix':
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    25
            self._repo = re.compile(NiXSapmSum.RE_PF)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    26
        else:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    27
            raise Exception('MTA/Logformat not supported yet.')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    28
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    29
    def parseLog(self, filehandle):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    30
        for l in filehandle:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    31
            mo = self._repo.match(l)
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    32
            if mo:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    33
                mx = mo.group(1)
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    34
                try:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    35
                    self._mxs[mx] += 1
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    36
                except KeyError:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    37
                    self._mxs[mx]  = 1
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    38
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    39
    def countByDom(self):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    40
        for mx in self._mxs.keys():
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    41
            dom = '.'.join(mx.split('.')[-2:])
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    42
            try:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    43
                self._doms[dom] += self._mxs[mx]
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    44
            except KeyError:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    45
                self._doms[dom]  = self._mxs[mx]
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    46
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    47
    def getDomains(self):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    48
        return self._doms
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    49
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    50
    def getMXs(self):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    51
        return self._mxs
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    52
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    53
def getOptionParser():
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    54
    from optparse import OptionParser
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    55
    description = 'do something ...'
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    56
    usage  = 'usage: %prog [options] maillog [maillog [...]]'
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    57
    version = '%prog '+__version__
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    58
    parser = OptionParser(description=description,usage=usage,version=version)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    59
    parser.add_option('-d', action='store_true', dest='countByDom',
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    60
            default=False, help='summarize all MX by domain')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    61
    parser.add_option('-m', action='store_false', dest='countByDom',
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    62
            help='count per MX host [default]')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    63
    parser.add_option('-o', dest='oFormat', default='table',metavar='FORMAT',
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    64
            help='the output format: table or csv [default: %default]')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    65
    parser.add_option('-p', action='store_true', dest='percent', default=False,
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    66
            help='show also percentages in table output [default: %default]')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    67
    parser.add_option('-s', dest='order', default='name', metavar='SORTBY',
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    68
            help='arrange output by: name or count [default: %default]')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    69
    parser.add_option('-t', dest='format', default='postfix',metavar='MTA',
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    70
            help='MTA that generated the maillog [default: %default]')
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    71
    return parser
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    72
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    73
def openLogFile(fname):
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    74
    try:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    75
        fh = open(fname)
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    76
        return fh
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    77
    except IOError, e:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    78
        os.sys.stderr.write('Warning: %s\nskipped file: %s\n' % (e.strerror,
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    79
            fname))
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    80
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    81
def getDomLen(domainnames):
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    82
    dlen = 0
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    83
    for d in domainnames:
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    84
        l = len(d)
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    85
        if l > dlen:
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    86
            dlen = l
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    87
    return dlen
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
    88
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    89
def buildTable(output, domains, percent, orderBy):
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    90
    k = 0 if orderBy == 'name' else 1
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    91
    doms = sorted(domains.items(), lambda d,c: cmp(d[k],c[k]), reverse=k)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    92
    dlen = getDomLen(domains.keys())+1
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    93
    clen = len(str(max(domains.values())))
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    94
    total = sum(domains.values())
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    95
    if percent:
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    96
        format = '%%%ds  %%%dd  %%5.2f %%%%\n' % (dlen, clen)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    97
        for d, c in doms:
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    98
            dfrac = 100./total*c
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
    99
            output.write(format % (d, c, dfrac))
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   100
    else:
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   101
        format = '%%%ds  %%%dd\n' % (dlen, clen)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   102
        for d in doms:
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   103
            output.write(format % d)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   104
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   105
def showResult(nixspamsum, options):
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   106
    from cStringIO import StringIO
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   107
    output = StringIO()
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   108
    if options.countByDom:
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   109
        nixspamsum.countByDom()
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   110
        domains = nixspamsum.getDomains()
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   111
    else:
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   112
        domains = nixspamsum.getMXs()
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   113
    # build the table
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   114
    if options.oFormat == 'table':
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   115
        buildTable(output, domains, options.percent, options.order)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   116
    # generate comma separated values
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   117
    elif options.oFormat == 'csv':
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   118
        for d in domains.items():
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   119
            output.write("'%s',%d\n" % d)
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   120
    # should never be reached
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   121
    else:
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   122
        print "Oops, error in function showResult() happend"
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   123
    # show the result
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   124
    print output.getvalue()
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   125
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   126
def main():
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   127
    parser = getOptionParser()
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   128
    opts, args = parser.parse_args()
2
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   129
    if opts.oFormat not in ('csv', 'table'):
a72ea07394cc NiXSapmSum.getTotal(): deleted
Pascal Volk <user@localhost.localdomain.org>
parents: 1
diff changeset
   130
        parser.error("Output format '%s' is not supported" % opts.oFormat)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   131
    if len(args) < 1:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   132
        parser.error('No logfiles specified')
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   133
    nixss = NiXSapmSum()
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   134
    nixss.setLogFormat(opts.format)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   135
    for fn in args:
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   136
        fh = openLogFile(fn)
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   137
        if fh is not None:
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   138
            nixss.parseLog(fh)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   139
            fh.close()
1
7d5cee19c20a Renamed class NiXSpamPlot to NiXSapmSum. Added getDomLen(). Rewrote showResult()
Pascal Volk <user@localhost.localdomain.org>
parents: 0
diff changeset
   140
    showResult(nixss, opts)
0
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   141
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   142
if __name__ == '__main__':
2d97e75f16cf initial commit: »don't fear the nervous delete finger«
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   143
    main()