mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Store caches outside the config directory for non-portable calibre installs
This commit is contained in:
parent
9b6613c192
commit
0ce501fa0d
@ -79,6 +79,42 @@ def debug():
|
|||||||
global DEBUG
|
global DEBUG
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
|
_cache_dir = None
|
||||||
|
|
||||||
|
def _get_cache_dir():
|
||||||
|
confcache = os.path.join(config_dir, u'caches')
|
||||||
|
if isportable:
|
||||||
|
return confcache
|
||||||
|
if os.environ.has_key('CALIBRE_CACHE_DIRECTORY'):
|
||||||
|
return os.path.abspath(os.environ['CALIBRE_CACHE_DIRECTORY'])
|
||||||
|
|
||||||
|
if iswindows:
|
||||||
|
w = plugins['winutil'][0]
|
||||||
|
candidate = os.path.join(w.special_folder_path(w.CSIDL_LOCAL_APPDATA), u'%s-cache'%__appname__)
|
||||||
|
elif isosx:
|
||||||
|
candidate = os.path.join(os.path.expanduser(u'~/Library/Caches'), __appname__)
|
||||||
|
else:
|
||||||
|
candidate = os.environ.get('XDG_CACHE_HOME', u'~/.cache')
|
||||||
|
candidate = os.path.join(os.path.expanduser(candidate),
|
||||||
|
__appname__)
|
||||||
|
if isinstance(candidate, bytes):
|
||||||
|
try:
|
||||||
|
candidate = candidate.decode(filesystem_encoding)
|
||||||
|
except ValueError:
|
||||||
|
candidate = confcache
|
||||||
|
if not os.path.exists(candidate):
|
||||||
|
try:
|
||||||
|
os.makedirs(candidate)
|
||||||
|
except:
|
||||||
|
candidate = confcache
|
||||||
|
return candidate
|
||||||
|
|
||||||
|
def cache_dir():
|
||||||
|
global _cache_dir
|
||||||
|
if _cache_dir is None:
|
||||||
|
_cache_dir = _get_cache_dir()
|
||||||
|
return _cache_dir
|
||||||
|
|
||||||
# plugins {{{
|
# plugins {{{
|
||||||
|
|
||||||
class Plugins(collections.Mapping):
|
class Plugins(collections.Mapping):
|
||||||
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import cStringIO, ctypes, datetime, os, platform, re, shutil, sys, tempfile, time
|
import cStringIO, ctypes, datetime, os, platform, re, shutil, sys, tempfile, time
|
||||||
|
|
||||||
from calibre.constants import __appname__, __version__, DEBUG
|
from calibre.constants import __appname__, __version__, DEBUG, cache_dir
|
||||||
from calibre import fit_image, confirm_config_name, strftime as _strftime
|
from calibre import fit_image, confirm_config_name, strftime as _strftime
|
||||||
from calibre.constants import isosx, iswindows
|
from calibre.constants import isosx, iswindows
|
||||||
from calibre.devices.errors import OpenFeedback, UserFeedback
|
from calibre.devices.errors import OpenFeedback, UserFeedback
|
||||||
@ -289,9 +289,7 @@ class ITUNES(DriverBase):
|
|||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
cached_books = {}
|
cached_books = {}
|
||||||
cache_dir = os.path.join(config_dir, 'caches', 'itunes')
|
|
||||||
calibre_library_path = prefs['library_path']
|
calibre_library_path = prefs['library_path']
|
||||||
archive_path = os.path.join(cache_dir, "thumbs.zip")
|
|
||||||
description_prefix = "added by calibre"
|
description_prefix = "added by calibre"
|
||||||
ejected = False
|
ejected = False
|
||||||
iTunes = None
|
iTunes = None
|
||||||
@ -884,6 +882,8 @@ class ITUNES(DriverBase):
|
|||||||
logger().info(" BCD: %s" % ['0x%x' % x for x in sorted(self.BCD)])
|
logger().info(" BCD: %s" % ['0x%x' % x for x in sorted(self.BCD)])
|
||||||
logger().info(" PRODUCT_ID: %s" % ['0x%x' % x for x in sorted(self.PRODUCT_ID)])
|
logger().info(" PRODUCT_ID: %s" % ['0x%x' % x for x in sorted(self.PRODUCT_ID)])
|
||||||
|
|
||||||
|
self.cache_dir = os.path.join(cache_dir(), 'itunes')
|
||||||
|
self.archive_path = os.path.join(self.cache_dir, "thumbs.zip")
|
||||||
# Confirm/create thumbs archive
|
# Confirm/create thumbs archive
|
||||||
if not os.path.exists(self.cache_dir):
|
if not os.path.exists(self.cache_dir):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
@ -9,7 +9,7 @@ from xml.sax.saxutils import escape
|
|||||||
|
|
||||||
from calibre import (prepare_string_for_xml, strftime, force_unicode,
|
from calibre import (prepare_string_for_xml, strftime, force_unicode,
|
||||||
isbytestring)
|
isbytestring)
|
||||||
from calibre.constants import isosx
|
from calibre.constants import isosx, cache_dir
|
||||||
from calibre.customize.conversion import DummyReporter
|
from calibre.customize.conversion import DummyReporter
|
||||||
from calibre.customize.ui import output_profiles
|
from calibre.customize.ui import output_profiles
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString
|
||||||
@ -18,7 +18,6 @@ from calibre.ebooks.metadata import author_to_author_sort
|
|||||||
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException, \
|
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException, \
|
||||||
InvalidGenresSourceFieldException
|
InvalidGenresSourceFieldException
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils.config import config_dir
|
|
||||||
from calibre.utils.date import format_date, is_date_undefined, now as nowf
|
from calibre.utils.date import format_date, is_date_undefined, now as nowf
|
||||||
from calibre.utils.filenames import ascii_text, shorten_components_to
|
from calibre.utils.filenames import ascii_text, shorten_components_to
|
||||||
from calibre.utils.icu import capitalize, collation_order, sort_key
|
from calibre.utils.icu import capitalize, collation_order, sort_key
|
||||||
@ -109,7 +108,7 @@ class CatalogBuilder(object):
|
|||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.reporter = report_progress
|
self.reporter = report_progress
|
||||||
self.stylesheet = stylesheet
|
self.stylesheet = stylesheet
|
||||||
self.cache_dir = os.path.join(config_dir, 'caches', 'catalog')
|
self.cache_dir = os.path.join(cache_dir(), 'catalog')
|
||||||
self.catalog_path = PersistentTemporaryDirectory("_epub_mobi_catalog", prefix='')
|
self.catalog_path = PersistentTemporaryDirectory("_epub_mobi_catalog", prefix='')
|
||||||
self.content_dir = os.path.join(self.catalog_path, "content")
|
self.content_dir = os.path.join(self.catalog_path, "content")
|
||||||
self.excluded_tags = self.get_excluded_tags()
|
self.excluded_tags = self.get_excluded_tags()
|
||||||
|
@ -16,7 +16,7 @@ from PyQt4.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache,
|
|||||||
from PyQt4.QtWebKit import QWebPage, QWebSettings, QWebView, QWebElement
|
from PyQt4.QtWebKit import QWebPage, QWebSettings, QWebView, QWebElement
|
||||||
|
|
||||||
from calibre import USER_AGENT, prints, get_proxies, get_proxy_info
|
from calibre import USER_AGENT, prints, get_proxies, get_proxy_info
|
||||||
from calibre.constants import ispy3, config_dir
|
from calibre.constants import ispy3, cache_dir
|
||||||
from calibre.utils.logging import ThreadSafeLog
|
from calibre.utils.logging import ThreadSafeLog
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
from calibre.web.jsbrowser.forms import FormsMixin
|
from calibre.web.jsbrowser.forms import FormsMixin
|
||||||
@ -44,7 +44,7 @@ class WebPage(QWebPage): # {{{
|
|||||||
settings = self.settings()
|
settings = self.settings()
|
||||||
if enable_developer_tools:
|
if enable_developer_tools:
|
||||||
settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
|
settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
|
||||||
QWebSettings.enablePersistentStorage(os.path.join(config_dir, 'caches',
|
QWebSettings.enablePersistentStorage(os.path.join(cache_dir(),
|
||||||
'webkit-persistence'))
|
'webkit-persistence'))
|
||||||
QWebSettings.setMaximumPagesInCache(0)
|
QWebSettings.setMaximumPagesInCache(0)
|
||||||
|
|
||||||
@ -135,8 +135,7 @@ class NetworkAccessManager(QNetworkAccessManager): # {{{
|
|||||||
self.log = log
|
self.log = log
|
||||||
if use_disk_cache:
|
if use_disk_cache:
|
||||||
self.cache = QNetworkDiskCache(self)
|
self.cache = QNetworkDiskCache(self)
|
||||||
self.cache.setCacheDirectory(os.path.join(config_dir, 'caches',
|
self.cache.setCacheDirectory(os.path.join(cache_dir(), 'jsbrowser'))
|
||||||
'jsbrowser'))
|
|
||||||
self.setCache(self.cache)
|
self.setCache(self.cache)
|
||||||
self.sslErrors.connect(self.on_ssl_errors)
|
self.sslErrors.connect(self.on_ssl_errors)
|
||||||
self.pf = ProxyFactory(log)
|
self.pf = ProxyFactory(log)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user