1 #!/usr/bin/env python 2 3 from simplex import * 4 import sys, time 5 6 try: 7 separator = sys.argv.index("--") 8 filename, numeric = sys.argv[1:3] 9 fields = map(int, sys.argv[3:separator]) 10 terms = groups(sys.argv[separator+1:], len(fields)) 11 except (IndexError, ValueError): 12 print >>sys.stderr, "Usage: %s <filename> <numeric> <field>... -- <term value>..." % sys.argv[0] 13 sys.exit(1) 14 15 f = open(filename) 16 accessor = DelimitedRecord(fields, numeric=(numeric == "true")) 17 18 try: 19 for term in terms: 20 21 # Convert the term to the appropriate type. 22 23 term = accessor.convert(term) 24 25 # Perform the search. 26 27 f.seek(0) 28 29 t = time.time() 30 line = find_in_file(f, accessor.get_key, term) 31 if line: 32 print "Found (at %s seconds)...\n%s" % (time.time() - t, line) 33 finally: 34 f.close() 35 36 # vim: tabstop=4 expandtab shiftwidth=4