paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from simplex import * |
paul@0 | 4 | import sys, time |
paul@0 | 5 | |
paul@3 | 6 | try: |
paul@3 | 7 | separator = sys.argv.index("--") |
paul@3 | 8 | filename = sys.argv[1] |
paul@3 | 9 | keys = map(int, sys.argv[2:separator]) |
paul@3 | 10 | terms = groups(sys.argv[separator+1:], len(keys)) |
paul@3 | 11 | except (IndexError, ValueError): |
paul@3 | 12 | print >>sys.stderr, "Usage: %s <filename> <key>... -- <term value>..." % sys.argv[0] |
paul@3 | 13 | sys.exit(1) |
paul@0 | 14 | |
paul@0 | 15 | f = open(filename) |
paul@3 | 16 | tf = TextFile(f, keys) |
paul@0 | 17 | try: |
paul@0 | 18 | for term in terms: |
paul@1 | 19 | tf.seek(0) |
paul@0 | 20 | |
paul@0 | 21 | t = time.time() |
paul@1 | 22 | line = find_in_file(tf, term) |
paul@0 | 23 | if line: |
paul@0 | 24 | print "Found (at %s seconds)...\n%s" % (time.time() - t, line) |
paul@0 | 25 | finally: |
paul@0 | 26 | f.close() |
paul@0 | 27 | |
paul@0 | 28 | # vim: tabstop=4 expandtab shiftwidth=4 |