Merge "Remove unused read_cached_file method from utils"
This commit is contained in:
commit
6efc3c8317
@ -86,26 +86,6 @@ def flatten_dict(d, parent_key=''):
|
||||
return dict(items)
|
||||
|
||||
|
||||
def read_cached_file(filename, cache_info, reload_func=None):
|
||||
"""Read from a file if it has been modified.
|
||||
|
||||
:param cache_info: dictionary to hold opaque cache.
|
||||
:param reload_func: optional function to be called with data when
|
||||
file is reloaded due to a modification.
|
||||
|
||||
:returns: data from file.
|
||||
|
||||
"""
|
||||
mtime = os.path.getmtime(filename)
|
||||
if not cache_info or mtime != cache_info.get('mtime'):
|
||||
with open(filename) as fap:
|
||||
cache_info['data'] = fap.read()
|
||||
cache_info['mtime'] = mtime
|
||||
if reload_func:
|
||||
reload_func(cache_info['data'])
|
||||
return cache_info['data']
|
||||
|
||||
|
||||
class SmarterEncoder(jsonutils.json.JSONEncoder):
|
||||
"""Help for JSON encoding dict-like objects."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user