From: Wade Berrier Date: Sat, 26 Jan 2013 03:43:10 +0000 (-0700) Subject: Support older versions of pyxdg X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a55bec19e4f88bf38d7fb957bf12f9bd63862992;p=mutt-ldap.git Support older versions of pyxdg save_cache_path was added in 0.21 See: https://bugs.freedesktop.org/show_bug.cgi?id=26458 Fall back to ~/.cache and make sure the directory exists (that's what save_cache_path does) --- diff --git a/mutt_ldap.py b/mutt_ldap.py index d343082..c63c04e 100755 --- a/mutt_ldap.py +++ b/mutt_ldap.py @@ -26,6 +26,7 @@ import json as _json import locale as _locale import logging as _logging import os.path as _os_path +import os as _os import pickle as _pickle import sys as _sys import time as _time @@ -108,11 +109,16 @@ class Config (_configparser.SafeConfigParser): def _get_cache_path(self): "Get the cache file path" - if _xdg_basedirectory: + + # Some versions of pyxdg don't have save_cache_path (0.20 and older) + # See: https://bugs.freedesktop.org/show_bug.cgi?id=26458 + if _xdg_basedirectory and 'save_cache_path' in dir(_xdg_basedirectory): path = _xdg_basedirectory.save_cache_path('') else: self._log_xdg_import_error() path = _os_path.expanduser(_os_path.join('~', '.cache')) + if not _os_path.isdir(path): + _os.makedirs(path) return _os_path.join(path, 'mutt-ldap.json') def _log_xdg_import_error(self):