diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-06-09 21:09:27 +0200 |
---|---|---|
committer | Dieter Verfaillie <dieterv@optionexplicit.be> | 2015-06-20 00:32:19 +0200 |
commit | ec91f9d11b40de198b2faf8a80b49dbd71107750 (patch) | |
tree | b1a1c1d14800bac46da2ed3f7994f0426f71453a /giscanner/cachestore.py | |
parent | 047244537c8ad5725cc3f8e4f9ea0d5e226fe7e0 (diff) | |
download | gobject-introspection-ec91f9d11b40de198b2faf8a80b49dbd71107750.tar.gz |
scanner: add "XDG Base Directory" functions
Extract cache and data dir lookup code into documented
get_user_cache_dir() and get_system_data_dirs() functions.
Note that previously, the data dirs code did not fall
back to '/usr/local/share:/usr/share' when the XDG_DATA_DIRS
environment variable was either not set or empty, as required
by the XDG Base Directory Specification.
https://bugzilla.gnome.org/show_bug.cgi?id=747770
Diffstat (limited to 'giscanner/cachestore.py')
-rw-r--r-- | giscanner/cachestore.py | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index 351bac38..c588792d 100644 --- a/giscanner/cachestore.py +++ b/giscanner/cachestore.py @@ -29,6 +29,9 @@ import tempfile import giscanner +from . import utils + + _CACHE_VERSION_FILENAME = '.cache-version' @@ -42,51 +45,19 @@ def _get_versionhash(): return hashlib.sha1(''.join(mtimes)).hexdigest() -def _get_cachedir(): - if 'GI_SCANNER_DISABLE_CACHE' in os.environ: - return None - - xdg_cache_home = os.environ.get('XDG_CACHE_HOME') - if xdg_cache_home is not None and os.path.exists(xdg_cache_home): - return xdg_cache_home - - homedir = os.path.expanduser('~') - if homedir is None: - return None - if not os.path.exists(homedir): - return None - - cachedir = os.path.join(homedir, '.cache') - if not os.path.exists(cachedir): - try: - os.mkdir(cachedir, 0o755) - except OSError: - return None - - scannerdir = os.path.join(cachedir, 'g-ir-scanner') - if not os.path.exists(scannerdir): - try: - os.mkdir(scannerdir, 0o755) - except OSError: - return None - # If it exists and is a file, don't cache at all - elif not os.path.isdir(scannerdir): - return None - return scannerdir - - class CacheStore(object): def __init__(self): - try: - self._directory = _get_cachedir() - except OSError as e: - if e.errno != errno.EPERM: - raise - self._directory = None - + self._directory = self._get_cachedir() self._check_cache_version() + def _get_cachedir(self): + if 'GI_SCANNER_DISABLE_CACHE' in os.environ: + return None + else: + cachedir = utils.get_user_cache_dir('g-ir-scanner') + return cachedir + def _check_cache_version(self): if self._directory is None: return |