Update getCache to take name. Add getReadCaches

This commit is contained in:
Thomas Vander Stichele
2013-02-03 22:17:19 +01:00
parent 1e9afffde6
commit 1adc97452f

View File

@@ -39,7 +39,7 @@ class Directory(log.Loggable):
return path
def getCache(self):
def getCache(self, name=None):
try:
from xdg import BaseDirectory
path = BaseDirectory.save_cache_path('morituri')
@@ -49,6 +49,33 @@ class Directory(log.Loggable):
if not os.path.exists(path):
os.makedirs(path)
self.info('Not using XDG, cache directory is %s' % path)
if name:
path = os.path.join(path, name)
if not os.path.exists(path):
os.makedirs(path)
return path
def getReadCaches(self, name=None):
paths = []
try:
from xdg import BaseDirectory
path = BaseDirectory.save_cache_path('morituri')
self.info('For XDG, read cache directory is %s' % path)
paths.append(path)
except ImportError:
pass
path = os.path.expanduser('~/.morituri/cache')
if os.path.exists(path):
self.info('From before XDG, read cache directory is %s' % path)
paths.append(path)
if name:
paths = [os.path.join(p, name) for p in paths]
return paths