def read_index(self, fh, indexed_fh, rec_iterator=None,<EOL>rec_hash_func=None, parse_hash=str, flush=True,<EOL>no_reindex=True, verbose=False):
<EOL>if rec_iterator is not None:<EOL><INDENT>self.record_iterator = rec_iterator<EOL><DEDENT>if rec_hash_func is not None:<EOL><INDENT>self.record_hash_function = rec_hash_func<EOL><DEDENT>self._no_reindex = no_reindex<EOL>handle = fh<EOL>try:<EOL><INDENT>handle = open(fh)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>if flush:<EOL><INDENT>self._index = {}<EOL>self._indexed_file_handle = None<EOL>self._indexed_file_name = None<EOL><DEDENT>indexed_fn = None<EOL>try:<EOL><INDENT>self.indexed_file = (indexed_fh, None)<EOL>indexed_fn = indexed_fh<EOL><DEDENT>except TypeError:<EOL><INDENT>try:<EOL><INDENT>self.indexed_file = (None, indexed_fh)<EOL><DEDENT>except TypeError:<EOL><INDENT>fn = "<STR_LIT>" + str(fh) if indexed_fn is not None else "<STR_LIT>"<EOL>raise IndexError("<STR_LIT>" + fn + "<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" + str(type(indexed_fh)))<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>try:<EOL><INDENT>total = os.path.getsize(handle.name)<EOL>pind = ProgressIndicator(totalToDo=total, messagePrefix="<STR_LIT>",<EOL>messageSuffix="<STR_LIT>" + handle.name)<EOL><DEDENT>except AttributeError as e:<EOL><INDENT>sys.stderr.write(str(e))<EOL>sys.stderr.write("<STR_LIT>")<EOL>verbose = False<EOL><DEDENT><DEDENT>for line in handle:<EOL><INDENT>line = line.rstrip()<EOL>if verbose:<EOL><INDENT>pind.done = handle.tell()<EOL>pind.showProgress()<EOL><DEDENT>if line.isspace():<EOL><INDENT>continue<EOL><DEDENT>parts = line.split("<STR_LIT:\t>")<EOL>if len(parts) < <NUM_LIT:2>:<EOL><INDENT>raise IndexError("<STR_LIT>" + line + "<STR_LIT:'>")<EOL><DEDENT>key = parse_hash("<STR_LIT:\t>".join(parts[:-<NUM_LIT:1>]))<EOL>value = parts[-<NUM_LIT:1>]<EOL>self._index[key] = int(value)<EOL><DEDENT>
Populate this index from a file. Input format is just a tab-separated file,
one record per line. The last column is the file location for the record
and all columns before that are collectively considered to be the hash key
for that record (which is probably only 1 column, but this allows us to
permit tabs in hash keys). Lines consisting only of whitespace are skipped.

:param fh:            filename or stream-like object to read from.
:param indexed_fh:    either the filename of the indexed file or handle to
                      it.
:param rec_iterator:  a function that will return an interator for the
                      indexed file type (not the iterator for the file
                      itself). This function must take a single argument
                      which is the name the file to iterate over, or a
                      stream like object similar to a filestream.
:param rec_hash_func: a function that accepts the record type produced by
                      the iterator and produces a unique hash for each
                      record.
:param parse_hash:    a function to convert the string representation of
                      the hash into whatever type is needed. By default,
                      we just leave these as strings.
:param flush:         remove everything currently in the index and discard
                      any details about a file that is already
                      fully/partially indexed by this object. This is the
                      default behavior. If False, then data from <fh> is
                      just added to the existing index data (potentially
                      overwriting some of it) and the existing index can
                      continue to be used as before.
:param no_reindex:    if True, after loading the index, a missing key will
                      cause an exception, rather than trigger re-scanning
                      the indexed file for the associated record. The only
                      reason to set this to False would be if your index
                      was incomplete.
:param verbose:       output status message to STDERR about progress
                      reading the index (if possible).

:raise IndexError: on malformed line in input file/stream