libsaria: Set cache basedir when storage imported

I want to set this once, so I don't need to keep looking it up.
This commit is contained in:
Bryan Schumaker 2011-05-07 17:10:36 -04:00
parent e2233e4106
commit 3fd94e4ddd
2 changed files with 7 additions and 5 deletions

View File

@ -15,7 +15,7 @@ if version.__dev__ == True:
SARIA_DIR = path.join(USER_DIR, saria)
if path.exists(SARIA_DIR) == False:
os.mkdir(SARIA_DIR)
cache.set_basedir(SARIA_DIR)
def full_path(filename):
return path.join(SARIA_DIR, filename)

View File

@ -1,13 +1,16 @@
# Bryan Schumaker (5 / 6 / 2011)
import os
import libsaria
join = os.path.join
sep = os.path.sep
isfile = os.path.isfile
isdir = os.path.isdir
getsize = os.path.getsize
CACHE_DIR = None
def set_basedir(saria_dir):
global CACHE_DIR
CACHE_DIR = join(saria_dir, "cache")
def file_exists(cache_path):
if not isfile(cache_path):
@ -15,9 +18,8 @@ def file_exists(cache_path):
return getsize(cache_path) != 0
def make_cache_path(artist, album, file):
cache_dir = libsaria.storage.full_path("cache")
cache_file = "%s%s%s%s" % (artist, sep, album, sep)
cache_path = join(cache_dir, cache_file)
cache_path = join(CACHE_DIR, cache_file)
if not isdir(cache_path):
os.makedirs(cache_path)
return join(cache_path, file)