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> <field>... -- <term value>..." % sys.argv[0] 13 sys.exit(1) 14 15 f = open(filename) 16 converters = [(numeric == "true" and int or None) for field in fields] 17 accessor = Converted(DelimitedRecord(fields), converters) 18 reader = TextFile(f, Iterator(accessor)) 19 20 try: 21 for term in terms: 22 reader.seek(0) 23 24 t = time.time() 25 line = find_in_file(reader, accessor.convert(term)) 26 if line: 27 print "Found (at %s seconds)...\n%s" % (time.time() - t, line) 28 finally: 29 f.close() 30 31 # vim: tabstop=4 expandtab shiftwidth=4