Merge remote-tracking branch 'wberrier/master'
[mutt-ldap.git] / mutt_ldap.py
index b1ce02860566ed025bf6d645bcd4a4face1b613c..c63c04e5e73abde5507ebc3b01c8580a5a4561fd 100755 (executable)
@@ -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,18 +109,24 @@ 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):
         global _xdg_import_error
         if _xdg_import_error:
-            LOG.error(u'could not import xdg.BaseDirectory')
-            LOG.error(_xdg_import_error)
+            LOG.warning(u'could not import xdg.BaseDirectory '
+                u'or lacking necessary support')
+            LOG.warning(_xdg_import_error)
             _xdg_import_error = None
 
 
@@ -143,7 +150,7 @@ CONFIG.add_section('cache')
 CONFIG.set('cache', 'enable', 'yes') # enable caching by default
 CONFIG.set('cache', 'path', '') # cache results here, defaults to XDG
 CONFIG.set('cache', 'fields', '')  # fields to cache (if empty, setup in the main block)
-CONFIG.set('cache', 'longevity-days', '14') # TODO: cache results for 14 days by default
+CONFIG.set('cache', 'longevity-days', '14') # Days before cache entries are invalidated
 CONFIG.add_section('system')
 # HACK: Python 2.x support, see http://bugs.python.org/issue13329#msg147475
 CONFIG.set('system', 'output-encoding', '')  # match .muttrc's $charset