# HG changeset patch # User Peter Hosey # Date 1294115257 28800 # Node ID 54a209909531232f688a0f05ed9e4c41bed9985a # Parent 4950e751a7cbd427ef1b37eb8c08faab76322dc8 Make the file importable for debugging purposes by wrapping the main-program-only bits in an if __name__ == "__main__" block. diff --git a/diff-colorize.py b/diff-colorize.py --- 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)