showResult(): count matches; break if no matches were found
authorPascal Volk <user@localhost.localdomain.org>
Fri, 03 Jul 2009 21:12:03 +0000
changeset 4 ae58d9881be5
parent 3 6b0d09cdfbdb
child 5 65590f05bb97
showResult(): count matches; break if no matches were found sort by domain name if the output format is CSV
nixspamsum
--- a/nixspamsum	Mon Jun 08 20:33:58 2009 +0000
+++ b/nixspamsum	Fri Jul 03 21:12:03 2009 +0000
@@ -3,8 +3,8 @@
 # Copyright 2009 Pascal Volk
 
 __author__ = 'Pascal Volk'
-__version__ = '0.1.1'
-__date__ = '2009-06-08'
+__version__ = '0.1.2'
+__date__ = '2009-07-03'
 
 import os
 import re
@@ -107,20 +107,26 @@
         output.write(format % ('total', total))
 
 def showResult(nixspamsum, options):
-    from cStringIO import StringIO
-    output = StringIO()
     if options.countByDom:
         nixspamsum.countByDom()
         domains = nixspamsum.getDomains()
     else:
         domains = nixspamsum.getMXs()
+    if not len(domains):
+        print "No Nix Spam RBL rejects found"
+        return
+
+    from cStringIO import StringIO
+    output = StringIO()
     # build the table
     if options.oFormat == 'table':
         buildTable(output, domains, options.percent, options.order)
     # generate comma separated values
     elif options.oFormat == 'csv':
-        for d in domains.items():
-            output.write("'%s',%d\n" % d)
+        order = domains.keys()
+        order.sort()
+        for d in order:
+            output.write("'%s',%d\n" % (d, domains[d]))
     # should never be reached
     else:
         print "Oops, error in function showResult() happend"