Linux environment: Use atemporary dir as the config directory if write access to the normal config directory is unavailable. Can be overriden by using the CALIBRE_CONFIG_DIRECTORY environment variable

This commit is contained in:
Kovid Goyal 2010-08-19 11:35:32 -06:00
parent 0472411aea
commit 2e42090a0d

View File

@ -98,5 +98,16 @@ elif isosx:
else: else:
bdir = os.path.abspath(os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', '~/.config'))) bdir = os.path.abspath(os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', '~/.config')))
config_dir = os.path.join(bdir, 'calibre') config_dir = os.path.join(bdir, 'calibre')
if not os.access(config_dir, os.W_OK):
print 'No write acces to', config_dir, 'using a temporary dir instead'
import tempfile, atexit
config_dir = tempfile.mkdtemp(prefix='calibre-config-')
def cleanup_cdir():
try:
import shutil
shutil.rmtree(config_dir)
except:
pass
atexit.register(cleanup_cdir)
# }}} # }}}