From 1adc97452f699314a5b615e4cd8a953ee6c19309 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 3 Feb 2013 22:17:19 +0100 Subject: [PATCH] Update getCache to take name. Add getReadCaches --- morituri/common/directory.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/morituri/common/directory.py b/morituri/common/directory.py index 1ad4765..66fb510 100644 --- a/morituri/common/directory.py +++ b/morituri/common/directory.py @@ -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 +