libsaria: Fill cache in new function

This keeps things easy to read
This commit is contained in:
Bryan Schumaker 2011-05-07 09:46:59 -04:00
parent a7c7b85fdb
commit 797063c492
1 changed files with 10 additions and 6 deletions

View File

@ -22,13 +22,17 @@ def make_cache_path(artist, album, file):
os.makedirs(cache_path)
return join(cache_path, file)
def read_cache(artist, album, title, cache_func, cache_path):
f = open(cache_path, 'w')
cache_func(f, artist, album, title)
f.close()
if not file_exists(cache_path):
os.remove(cache_path)
return None
return cache_path
def get_item(artist, album, title, file, cache_func):
cache_path = make_cache_path(artist, album, file)
if not file_exists(cache_path):
f = open(cache_path, 'w')
cache_func(f, artist, album, title)
f.close()
if not file_exists(cache_path):
os.remove(cache_path)
print "File doesn't exist!"
cache_path = fill_cache(artist, album, title, cache_func, cache_path)
return cache_path