From 61d55a9f692b260993228d6cf0a66fe8553b5a76 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Fri, 11 Mar 2016 14:21:56 -0800 Subject: [PATCH] CLI-tool friendly handling of EPIPE and INT And, correcting from the name of the Python class to the format name processed by the Python class (class.__name__ vs. class.formatname). --- tldp/driver.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tldp/driver.py b/tldp/driver.py index 2f10e24..03c167c 100644 --- a/tldp/driver.py +++ b/tldp/driver.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function import os import sys import errno +import signal import shutil import logging import inspect @@ -21,6 +22,13 @@ from tldp.utils import arg_isloglevel, arg_isdirectory from tldp.utils import swapdirs, sameFilesystem from tldp.doctypes.common import preamble, postamble +# -- Don't freak out with IOError when our STDOUT, handled with +# head, sed, awk, grep, etc; and, also deal with a user's ctrl-C +# the same way (i.e. no traceback, just stop) +# +signal.signal(signal.SIGPIPE, signal.SIG_DFL) +signal.signal(signal.SIGINT, signal.SIG_DFL) + logformat = '%(levelname)-9s %(name)s %(filename)s#%(lineno)s ' \ + '%(funcName)s %(message)s' logging.basicConfig(stream=sys.stderr, format=logformat, level=logging.ERROR) @@ -122,7 +130,7 @@ def summary(config, *args, **kwargs): print('', 'By Document Type', '----------------', sep='\n', file=file) summarybytype = collections.defaultdict(list) for doc in inv.source.values(): - name = doc.doctype.__name__ + name = doc.doctype.formatname summarybytype[name].append(doc.stem) for doctype, docs in summarybytype.items(): count = len(docs)