From d3ec0afadaae70b64c80c55155b8cdf45b5ac2ef Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 5 Jan 2015 10:05:51 +0000 Subject: Move cache data to XDG_CACHE_HOME So the cache file will now typically be ~/.cache/git-bz-cache. https://bugzilla.gnome.org/show_bug.cgi?id=674020 --- git-bz | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/git-bz b/git-bz index 3b4afa3..ce6f0b0 100755 --- a/git-bz +++ b/git-bz @@ -83,6 +83,7 @@ git_config = { import base64 import cPickle as pickle from ConfigParser import RawConfigParser, NoOptionError +import errno import httplib import io import optparse @@ -747,15 +748,29 @@ def encode_multipart_formdata(fields, files=None): # =============================================== CACHE_EXPIRY_TIME = 3600 * 24 # one day +xdg_cache_home = os.environ.get('XDG_CACHE_HOME', + os.path.join(os.path.expanduser('~'), + '.cache')) +cache_filename = os.path.join(xdg_cache_home, 'git-bz-cache') class Cache(object): def __init__(self): self.cfp = None def __ensure(self, host): + # Ensure the cache directory exists. + cache_dir = os.path.dirname(cache_filename) + try: + os.makedirs(cache_dir, 0700) + except OSError as exc: + if exc.errno == errno.EEXIST and os.path.isdir(cache_dir): + pass + else: + raise + if self.cfp == None: self.cfp = RawConfigParser() - self.cfp.read(os.path.expanduser("~/.git-bz-cache")) + self.cfp.read(cache_filename) if self.cfp.has_section(host): if time.time() > self.cfp.getfloat(host, "expires"): @@ -775,7 +790,7 @@ class Cache(object): def set(self, host, key, value): self.__ensure(host) self.cfp.set(host, key, pickle.dumps(value)) - f = open(os.path.expanduser("~/.git-bz-cache"), "w") + f = open(cache_filename, "w") self.cfp.write(f) f.close() -- cgit