From 9640b13f701c7c28cc4d02e3801a52aaf8c184da Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 7 Nov 2015 15:58:05 +0100 Subject: [PATCH] Make cached_name a Song property --- patacrep/songs/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 6eb3b89d..b267ab0a 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -138,16 +138,21 @@ class Song: self._version = self.CACHE_VERSION self._write_cache() + @property + def cached_name(self): + """Name of the file used for the cache""" + return cached_name(self.datadir, self.subpath) + def _cache_retrieved(self): """If relevant, retrieve self from the cache.""" if self.use_cache: self._filehash = hashlib.md5( open(self.fullpath, 'rb').read() ).hexdigest() - if os.path.exists(cached_name(self.datadir, self.subpath)): + if os.path.exists(self.cached_name): try: cached = pickle.load(open( - cached_name(self.datadir, self.subpath), + self.cached_name, 'rb', )) if ( @@ -172,7 +177,7 @@ class Song: cached[attribute] = getattr(self, attribute) pickle.dump( cached, - open(cached_name(self.datadir, self.subpath), 'wb'), + open(self.cached_name, 'wb'), protocol=-1 )