Simplify cache code..

This commit is contained in:
Alexandre Aubin 2019-11-19 16:49:45 +01:00
parent e14d156650
commit 06e72c0e86

View file

@ -25,7 +25,7 @@ def get_cachedir(subdir='', make_dir=True):
return path return path
def open_cachefile(filename, mode='r', **kwargs): def open_cachefile(filename, mode='r', subdir=''):
"""Open a cache file and return a stream """Open a cache file and return a stream
Attempt to open in 'mode' the cache file 'filename' from the Attempt to open in 'mode' the cache file 'filename' from the
@ -39,9 +39,6 @@ def open_cachefile(filename, mode='r', **kwargs):
- **kwargs -- Optional arguments for get_cachedir - **kwargs -- Optional arguments for get_cachedir
""" """
# Set make_dir if not given cache_dir = get_cachedir(subdir, make_dir=True if mode[0] == 'w' else False)
kwargs['make_dir'] = kwargs.get('make_dir',
True if mode[0] == 'w' else False)
cache_dir = get_cachedir(**kwargs)
file_path = os.path.join(cache_dir, filename) file_path = os.path.join(cache_dir, filename)
return open(file_path, mode) return open(file_path, mode)