Browse Source

Minor refactorisation of cache_retrieved

pull/165/head
Oliverpool 9 years ago
parent
commit
9a31a21c01
  1. 5
      patacrep/songs/__init__.py

5
patacrep/songs/__init__.py

@ -98,10 +98,10 @@ class Song:
def __init__(self, subpath, config, *, datadir=None):
if datadir is None:
self.datadir = ""
# Only songs in datadirs may be cached
self.use_cache = False
else:
self.datadir = datadir
# Only songs in datadirs are cached
self.use_cache = ('_cache' in config)
self.fullpath = os.path.join(self.datadir, subpath)
@ -145,11 +145,10 @@ class Song:
def _cache_retrieved(self):
"""If relevant, retrieve self from the cache."""
if self.use_cache:
if self.use_cache and os.path.exists(self.cached_name):
self._filehash = hashlib.md5(
open(self.fullpath, 'rb').read()
).hexdigest()
if os.path.exists(self.cached_name):
try:
cached = pickle.load(open(
self.cached_name,

Loading…
Cancel
Save