X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=bin%2Fdjbdns-logparse;h=2c88462bd2ec479753ad5030f7e6da0859c1aa4d;hb=f8971980184acdac6243e806e635b420ccef1d3f;hp=7808fbd99a5042a9adc31828933949325561585e;hpb=3611c026366d615fb51e31e62cdedb7d68293c3e;p=djbdns-logparse.git diff --git a/bin/djbdns-logparse b/bin/djbdns-logparse index 7808fbd..2c88462 100755 --- a/bin/djbdns-logparse +++ b/bin/djbdns-logparse @@ -2,6 +2,10 @@ 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 @@ -11,12 +15,11 @@ parser = ArgumentParser(description = __doc__) # 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, @@ -29,5 +32,11 @@ parser.add_argument("logfiles", # # 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)