]> gitweb.michael.orlitzky.com - djbdns-logparse.git/blobdiff - bin/djbdns-logparse
bin/djbdns-logparse: only import sys.stdin within main().
[djbdns-logparse.git] / bin / djbdns-logparse
index 32c7ba106139916df2cd0241c2e50956e824e815..998f5475c6127306a7ff3a5b5e32e1837a768aa0 100755 (executable)
@@ -24,7 +24,7 @@ Convert tinydns and dnscache logs to human-readable form
 #   ** http://www.hungry.com/~fn/dnscache-log.pl.txt
 #
 
-import sys, re
+import re
 from struct import pack
 from time import strftime, gmtime
 from subprocess import Popen, PIPE
@@ -67,9 +67,6 @@ query_drop_reason = {
     }
 
 
-def warn(filename, msg):
-    sys.stderr.write("warning: %s: %s\n" % (filename, msg))
-
 def convert_ip(ip):
     """Convert a hex string representing an IP address to conventional
     human-readable form, ie. dotted-quad decimal for IPv4, and
@@ -194,7 +191,7 @@ def handle_tinydns_log(line, match):
     type = int(type, 16)                # "001c" -> 28
     type = query_type.get(type, type)   # 28 -> "aaaa"
 
-    print(timestamp,)
+    print(timestamp, end=' ')
 
     if code == "+":
         print ("sent response to %s:%s (id %s): %s %s"
@@ -231,7 +228,7 @@ def parse_logfile(file):
             handle_dnscache_log(line, match)
             continue
 
-        sys.stdout.write(line)
+        print(line)
 
 def main():
     # Create an argument parser using the file's docsctring as its
@@ -241,11 +238,12 @@ def main():
 
     # Parse zero or more positional arguments into a list of
     # "logfiles". If none are given, read from stdin instead.
+    from sys import stdin
     parser.add_argument("logfiles",
                         metavar="LOGFILE",
                         type=FileType("r"),
                         nargs="*",
-                        default=[sys.stdin],
+                        default=[stdin],
                         help="djbdns logfile to process (default: stdin)")
 
     args = parser.parse_args()