nixspamsum
changeset 4 ae58d9881be5
parent 3 6b0d09cdfbdb
child 5 65590f05bb97
equal deleted inserted replaced
3:6b0d09cdfbdb 4:ae58d9881be5
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 # Copyright 2009 Pascal Volk
     3 # Copyright 2009 Pascal Volk
     4 
     4 
     5 __author__ = 'Pascal Volk'
     5 __author__ = 'Pascal Volk'
     6 __version__ = '0.1.1'
     6 __version__ = '0.1.2'
     7 __date__ = '2009-06-08'
     7 __date__ = '2009-07-03'
     8 
     8 
     9 import os
     9 import os
    10 import re
    10 import re
    11 
    11 
    12 class NiXSapmSum:
    12 class NiXSapmSum:
   105             output.write(format % d)
   105             output.write(format % d)
   106         output.write('%s\n' % ((clen+dlen+4)*'-'))
   106         output.write('%s\n' % ((clen+dlen+4)*'-'))
   107         output.write(format % ('total', total))
   107         output.write(format % ('total', total))
   108 
   108 
   109 def showResult(nixspamsum, options):
   109 def showResult(nixspamsum, options):
   110     from cStringIO import StringIO
       
   111     output = StringIO()
       
   112     if options.countByDom:
   110     if options.countByDom:
   113         nixspamsum.countByDom()
   111         nixspamsum.countByDom()
   114         domains = nixspamsum.getDomains()
   112         domains = nixspamsum.getDomains()
   115     else:
   113     else:
   116         domains = nixspamsum.getMXs()
   114         domains = nixspamsum.getMXs()
       
   115     if not len(domains):
       
   116         print "No Nix Spam RBL rejects found"
       
   117         return
       
   118 
       
   119     from cStringIO import StringIO
       
   120     output = StringIO()
   117     # build the table
   121     # build the table
   118     if options.oFormat == 'table':
   122     if options.oFormat == 'table':
   119         buildTable(output, domains, options.percent, options.order)
   123         buildTable(output, domains, options.percent, options.order)
   120     # generate comma separated values
   124     # generate comma separated values
   121     elif options.oFormat == 'csv':
   125     elif options.oFormat == 'csv':
   122         for d in domains.items():
   126         order = domains.keys()
   123             output.write("'%s',%d\n" % d)
   127         order.sort()
       
   128         for d in order:
       
   129             output.write("'%s',%d\n" % (d, domains[d]))
   124     # should never be reached
   130     # should never be reached
   125     else:
   131     else:
   126         print "Oops, error in function showResult() happend"
   132         print "Oops, error in function showResult() happend"
   127     # show the result
   133     # show the result
   128     print output.getvalue()
   134     print output.getvalue()