r"""
Convert tinydns and dnscache logs to human-readable form
"""
+# Avoid clobbering the top-level exit() built-in.
+import sys
+
+from signal import signal, SIGINT
from argparse import ArgumentParser, FileType
from djbdns.io import parse_logfile
# 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=[stdin],
+ default=[sys.stdin],
help="djbdns logfile to process (default: stdin)")
# Warning: argparse automatically opens its file arguments here,
#
# So anyway, don't run this on several million logfiles.
args = parser.parse_args()
+
+# Install a SIGINT handler so thst we don't spit out a stack trace when
+# the user accidentally starts the program with no arguments and then
+# hits Ctrl-C to kill it.
+signal(SIGINT, lambda s,f: sys.exit(0))
+
for f in args.logfiles:
parse_logfile(f)