mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-24 15:11:30 +02:00
Changed location of scanned fonts.
In Calibre, there was decided to keep the fonts information inside the configuration directory. While scanned fonts information is actually a cache, I would keep it there. This commit is making that happen. Also removed XMLConfig in favor of JSONConfig class, since XMLConfig is not used at all.
This commit is contained in:
@@ -172,26 +172,17 @@ class OptionParser(optparse.OptionParser):
|
|||||||
return optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
return optparse.OptionParser.add_option_group(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class XMLConfig(dict):
|
class JSONConfig(dict):
|
||||||
|
|
||||||
'''
|
EXTENSION = '.json'
|
||||||
Similar to :class:`DynamicConfig`, except that it uses an XML storage
|
|
||||||
backend instead of a pickle file.
|
|
||||||
|
|
||||||
See `https://docs.python.org/dev/library/plistlib.html`_ for the supported
|
def __init__(self, relative_conf_file):
|
||||||
data types.
|
|
||||||
'''
|
|
||||||
|
|
||||||
EXTENSION = '.plist'
|
|
||||||
|
|
||||||
def __init__(self, rel_path_to_cf_file,
|
|
||||||
base_path=constants_old.config_dir):
|
|
||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
self.no_commit = False
|
self.no_commit = False
|
||||||
self.defaults = {}
|
self.defaults = {}
|
||||||
self.file_path = os.path.join(base_path,
|
self.file_path = os.path.join(self._get_cache_dir(),
|
||||||
*(rel_path_to_cf_file.split('/')))
|
relative_conf_file)
|
||||||
self.file_path = os.path.abspath(self.file_path)
|
|
||||||
if not self.file_path.endswith(self.EXTENSION):
|
if not self.file_path.endswith(self.EXTENSION):
|
||||||
self.file_path += self.EXTENSION
|
self.file_path += self.EXTENSION
|
||||||
|
|
||||||
@@ -210,15 +201,15 @@ class XMLConfig(dict):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def raw_to_object(self, raw):
|
def raw_to_object(self, raw):
|
||||||
from ebook_converter.polyglot.plistlib import loads
|
return json_loads(raw)
|
||||||
return loads(raw)
|
|
||||||
|
|
||||||
def to_raw(self):
|
def to_raw(self):
|
||||||
from ebook_converter.polyglot.plistlib import dumps
|
return json_dumps(self)
|
||||||
return dumps(self)
|
|
||||||
|
|
||||||
def decouple(self, prefix):
|
def decouple(self, prefix):
|
||||||
self.file_path = os.path.join(os.path.dirname(self.file_path), prefix + os.path.basename(self.file_path))
|
self.file_path = os.path.join(os.path.dirname(self.file_path),
|
||||||
|
prefix +
|
||||||
|
os.path.basename(self.file_path))
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def refresh(self, clear_current=True):
|
def refresh(self, clear_current=True):
|
||||||
@@ -237,30 +228,24 @@ class XMLConfig(dict):
|
|||||||
self.clear()
|
self.clear()
|
||||||
self.update(d)
|
self.update(d)
|
||||||
|
|
||||||
|
def _get_cache_dir(self):
|
||||||
|
if os.getenv('XDG_CACHE_HOME'):
|
||||||
|
return os.getenv('XDG_CACHE_HOME')
|
||||||
|
return os.path.join(os.path.expanduser('~/'), '.cache')
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
from ebook_converter.polyglot.plistlib import Data
|
|
||||||
try:
|
try:
|
||||||
ans = dict.__getitem__(self, key)
|
return dict.__getitem__(self, key)
|
||||||
if isinstance(ans, Data):
|
|
||||||
ans = ans.data
|
|
||||||
return ans
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.defaults.get(key, None)
|
return self.defaults[key]
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
from ebook_converter.polyglot.plistlib import Data
|
|
||||||
try:
|
try:
|
||||||
ans = dict.__getitem__(self, key)
|
return dict.__getitem__(self, key)
|
||||||
if isinstance(ans, Data):
|
|
||||||
ans = ans.data
|
|
||||||
return ans
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.defaults.get(key, default)
|
return self.defaults.get(key, default)
|
||||||
|
|
||||||
def __setitem__(self, key, val):
|
def __setitem__(self, key, val):
|
||||||
from ebook_converter.polyglot.plistlib import Data
|
|
||||||
if isinstance(val, bytes):
|
|
||||||
val = Data(val)
|
|
||||||
dict.__setitem__(self, key, val)
|
dict.__setitem__(self, key, val)
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
@@ -298,33 +283,6 @@ class XMLConfig(dict):
|
|||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
|
||||||
class JSONConfig(XMLConfig):
|
|
||||||
|
|
||||||
EXTENSION = '.json'
|
|
||||||
|
|
||||||
def raw_to_object(self, raw):
|
|
||||||
return json_loads(raw)
|
|
||||||
|
|
||||||
def to_raw(self):
|
|
||||||
return json_dumps(self)
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
try:
|
|
||||||
return dict.__getitem__(self, key)
|
|
||||||
except KeyError:
|
|
||||||
return self.defaults[key]
|
|
||||||
|
|
||||||
def get(self, key, default=None):
|
|
||||||
try:
|
|
||||||
return dict.__getitem__(self, key)
|
|
||||||
except KeyError:
|
|
||||||
return self.defaults.get(key, default)
|
|
||||||
|
|
||||||
def __setitem__(self, key, val):
|
|
||||||
dict.__setitem__(self, key, val)
|
|
||||||
self.commit()
|
|
||||||
|
|
||||||
|
|
||||||
class DevicePrefs:
|
class DevicePrefs:
|
||||||
|
|
||||||
def __init__(self, global_prefs):
|
def __init__(self, global_prefs):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from ebook_converter import walk
|
|||||||
from ebook_converter.constants_old import DEBUG
|
from ebook_converter.constants_old import DEBUG
|
||||||
from ebook_converter.constants_old import filesystem_encoding
|
from ebook_converter.constants_old import filesystem_encoding
|
||||||
from ebook_converter.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
from ebook_converter.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||||
|
from ebook_converter.utils import config
|
||||||
|
|
||||||
|
|
||||||
class NoFonts(ValueError):
|
class NoFonts(ValueError):
|
||||||
@@ -277,8 +278,7 @@ class FontScanner(Thread):
|
|||||||
|
|
||||||
def reload_cache(self):
|
def reload_cache(self):
|
||||||
if not hasattr(self, 'cache'):
|
if not hasattr(self, 'cache'):
|
||||||
from ebook_converter.utils.config import JSONConfig
|
self.cache = config.JSONConfig('ebook-converter-scanner-cache')
|
||||||
self.cache = JSONConfig('fonts/scanner_cache')
|
|
||||||
else:
|
else:
|
||||||
self.cache.refresh()
|
self.cache.refresh()
|
||||||
if self.cache.get('version', None) != self.CACHE_VERSION:
|
if self.cache.get('version', None) != self.CACHE_VERSION:
|
||||||
|
|||||||
Reference in New Issue
Block a user