diff options
Diffstat (limited to 'Tools/scripts/rgrep.py')
-rwxr-xr-x | Tools/scripts/rgrep.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Tools/scripts/rgrep.py b/Tools/scripts/rgrep.py index eee6a07..1917e05 100755 --- a/Tools/scripts/rgrep.py +++ b/Tools/scripts/rgrep.py @@ -9,8 +9,9 @@ import sys import re import getopt + def main(): - bufsize = 64*1024 + bufsize = 64 * 1024 reflags = 0 opts, args = getopt.getopt(sys.argv[1:], "i") for o, a in opts: @@ -24,11 +25,11 @@ def main(): try: prog = re.compile(pattern, reflags) except re.error as msg: - usage("error in regular expression: %s" % str(msg)) + usage("error in regular expression: %s" % msg) try: f = open(filename) except IOError as msg: - usage("can't open %s: %s" % (repr(filename), str(msg)), 1) + usage("can't open %r: %s" % (filename, msg), 1) f.seek(0, 2) pos = f.tell() leftover = None @@ -49,16 +50,17 @@ def main(): del lines[0] else: leftover = None - lines.reverse() - for line in lines: + for line in reversed(lines): if prog.search(line): print(line) + def usage(msg, code=2): sys.stdout = sys.stderr print(msg) print(__doc__) sys.exit(code) + if __name__ == '__main__': main() |