def _linear_search_log_for_time(log_path, dt, word_count, lbound, ubound, reverse=False):
with open(log_path, '<STR_LIT:r>') as log:<EOL><INDENT>log.seek(lbound)<EOL>prev_line_start = lbound<EOL>line_start = log.tell()<EOL>while log.tell() < ubound:<EOL><INDENT>is_valid_dt = False<EOL>while not is_valid_dt:<EOL><INDENT>line = log.readline()<EOL>timestr = '<STR_LIT:U+0020>'.join(line.split()[:word_count])<EOL>try:<EOL><INDENT>log_dt = parser.parse(timestr)<EOL>is_valid_dt = True<EOL><DEDENT>except:<EOL><INDENT>is_valid_dt = False<EOL>if log.tell() == ubound:<EOL><INDENT>if not reverse:<EOL><INDENT>return prev_line_start<EOL><DEDENT>else:<EOL><INDENT>return log.tell()<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not reverse:<EOL><INDENT>if log_dt >= dt:<EOL><INDENT>return prev_line_start<EOL><DEDENT>else:<EOL><INDENT>prev_line_start = line_start<EOL>line_start = log.tell()<EOL>if line_start == ubound:<EOL><INDENT>return prev_line_start<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if log_dt > dt:<EOL><INDENT>return log.tell()<EOL><DEDENT>else:<EOL><INDENT>if log.tell() == ubound:<EOL><INDENT>return log.tell()<EOL><DEDENT>else:<EOL><INDENT>line_start = log.tell()<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Find the start position of the line containing the datetime nearest to dt.
:param log_path: the absolute path to the log file
:param dt: the datetime to be searched
:param word_count: the number of "words" that represents the datetime in the log
:param lbound: the byte offset to the start of the block to be searched
:param ubound: the byte offset to the end of the block to be searched
:param reverse: if False, finds the line with the largest datetime less than dt
                if True, finds the line with the smallest datetime larger than dt