def lookup_lastlines(lastlines_dirpath, path):
 underscored = path.replace('/', '_')
 try:
  lastlines_file = open(os.path.join(lastlines_dirpath, underscored))
 except (OSError, IOError):
  return
 lastlines = lastlines_file.read()
 lastlines_file.close()
 os.remove(lastlines_file.name)
 if (not lastlines):
  return
 try:
  target_file = open(path)
 except (OSError, IOError):
  return
 target_data = target_file.read()
 target_file.close()
 loc = target_data.rfind(lastlines)
 if (loc == (-1)):
  return
 reverse_lineno = target_data.count('\n', (loc + len(lastlines)))
 return reverse_lineno

def lookup_lastlines ( lastlines_dirpath , path ) : underscored = path . replace ( '/' , '_' ) try : lastlines_file = open ( os . path . join ( lastlines_dirpath , underscored ) ) except ( OSError , IOError ) : return lastlines = lastlines_file . read ( ) lastlines_file . close ( ) os . remove ( lastlines_file . name ) if ( not lastlines ) : return try : target_file = open ( path ) except ( OSError , IOError ) : return target_data = target_file . read ( ) target_file . close ( ) loc = target_data . rfind ( lastlines ) if ( loc == ( - 1 ) ) : return reverse_lineno = target_data . count ( '\n' , ( loc + len ( lastlines ) ) ) return reverse_lineno
retrieve last lines seen for path .