#NEWLINE# def read_cached_file( filename , force_reload = False ) : #NEWLINE# #INDENT# 'Read from a file if it has been modified.\n\n    :param force_reload: Whether to reload the file.\n    :returns: A tuple with a boolean specifying if the data is fresh\n              or not.\n    ' #NEWLINE# global _FILE_CACHE #NEWLINE# if force_reload : #NEWLINE# #INDENT# delete_cached_file ( filename ) #NEWLINE# #UNINDENT# reloaded = False #NEWLINE# mtime = os . path . getmtime ( filename ) #NEWLINE# cache_info = _FILE_CACHE . setdefault ( filename , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( ( not cache_info ) or ( mtime > cache_info . get ( 'mtime' , 0 ) ) ) : #NEWLINE# #INDENT# LOG . debug ( 'Reloading cached file %s' , filename ) #NEWLINE# with open ( filename ) as fap : #NEWLINE# #INDENT# cache_info [ 'data' ] = fap . read ( ) #NEWLINE# #UNINDENT# cache_info [ 'mtime' ] = mtime #NEWLINE# reloaded = True #NEWLINE# #UNINDENT# return ( reloaded , cache_info [ 'data' ] )