Mercurial > diff-colorize
changeset 17:54a209909531
Make the file importable for debugging purposes by wrapping the main-program-only bits in an if __name__ == "__main__" block.
author | Peter Hosey <hg@boredzo.org> |
---|---|
date | Mon, 03 Jan 2011 20:27:37 -0800 |
parents | 4950e751a7cb |
children | 83d58ccc70bf 948c96784f00 |
files | diff-colorize.py |
diffstat | 1 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/diff-colorize.py +++ b/diff-colorize.py @@ -122,16 +122,17 @@ prefixes['@@'] = ( + '@@' ) -if sys.stdin.isatty(): - # Standard input is a TTY, meaning that the user ran 'diff-colorize' at the shell prompt, without redirecting anything into it. Print usage info and exit. - sys.exit(USAGE) +if __name__ == "__main__": + if sys.stdin.isatty(): + # Standard input is a TTY, meaning that the user ran 'diff-colorize' at the shell prompt, without redirecting anything into it. Print usage info and exit. + sys.exit(USAGE) -for line in fileinput.input(): - for prefix_to_test in prefixes: - if line.startswith(prefix_to_test): - sys.stdout.write(prefixes[prefix_to_test]) - line = line[len(prefix_to_test):] + for line in fileinput.input(): + for prefix_to_test in prefixes: + if line.startswith(prefix_to_test): + sys.stdout.write(prefixes[prefix_to_test]) + line = line[len(prefix_to_test):] - sys.stdout.write(line) + sys.stdout.write(line) - sys.stdout.write(RESET_FORMAT) + sys.stdout.write(RESET_FORMAT)