mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only store tweaks that have been changed from default values
This commit is contained in:
parent
05ef1457e8
commit
40d631f39a
@ -1,43 +1,35 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
# License: GPLv3 Copyright: 2010, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
from functools import partial
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from functools import partial
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, AbortCommit
|
|
||||||
from calibre.gui2.search_box import SearchBox2
|
|
||||||
from calibre.gui2 import error_dialog, info_dialog
|
|
||||||
from calibre.utils.config_base import read_custom_tweaks, write_custom_tweaks, exec_tweaks, default_tweaks_raw
|
|
||||||
from calibre.gui2.widgets import PythonHighlighter
|
|
||||||
from calibre import isbytestring
|
|
||||||
from calibre.utils.icu import lower
|
|
||||||
from calibre.utils.search_query_parser import (ParseException,
|
|
||||||
SearchQueryParser)
|
|
||||||
from polyglot.builtins import iteritems, unicode_type, range, map
|
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QAbstractListModel, Qt, QStyledItemDelegate, QStyle, QStyleOptionViewItem,
|
QAbstractListModel, QApplication, QDialog, QDialogButtonBox, QFont, QGridLayout,
|
||||||
QFont, QDialogButtonBox, QDialog, QApplication, QVBoxLayout,
|
QGroupBox, QIcon, QLabel, QListView, QMenu, QModelIndex, QPlainTextEdit,
|
||||||
QPlainTextEdit, QLabel, QModelIndex, QMenu, QIcon, QListView, QGridLayout,
|
QPushButton, QSizePolicy, QSplitter, QStyle, QStyledItemDelegate,
|
||||||
QSizePolicy, QGroupBox, QWidget, QPushButton, QSplitter, pyqtSignal)
|
QStyleOptionViewItem, Qt, QVBoxLayout, QWidget, pyqtSignal
|
||||||
|
)
|
||||||
|
|
||||||
|
from calibre import isbytestring
|
||||||
|
from calibre.gui2 import error_dialog, info_dialog
|
||||||
|
from calibre.gui2.preferences import AbortCommit, ConfigWidgetBase, test_widget
|
||||||
|
from calibre.gui2.search_box import SearchBox2
|
||||||
|
from calibre.gui2.widgets import PythonHighlighter
|
||||||
|
from calibre.utils.config_base import (
|
||||||
|
default_tweaks_raw, exec_tweaks, normalize_tweak, read_custom_tweaks,
|
||||||
|
write_custom_tweaks
|
||||||
|
)
|
||||||
|
from calibre.utils.icu import lower
|
||||||
|
from calibre.utils.search_query_parser import ParseException, SearchQueryParser
|
||||||
|
from polyglot.builtins import iteritems, range, unicode_type
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
|
|
||||||
|
|
||||||
def normalize(val):
|
|
||||||
if isinstance(val, (list, tuple)):
|
|
||||||
return tuple(map(normalize, val))
|
|
||||||
if isinstance(val, dict):
|
|
||||||
return {k: normalize(v) for k, v in iteritems(val)}
|
|
||||||
return val
|
|
||||||
|
|
||||||
|
|
||||||
def format_doc(doc):
|
def format_doc(doc):
|
||||||
current_indent = default_indent = None
|
current_indent = default_indent = None
|
||||||
lines = ['']
|
lines = ['']
|
||||||
@ -120,7 +112,7 @@ class Tweak(object): # {{{
|
|||||||
def is_customized(self):
|
def is_customized(self):
|
||||||
for x, val in iteritems(self.default_values):
|
for x, val in iteritems(self.default_values):
|
||||||
cval = self.custom_values.get(x, val)
|
cval = self.custom_values.get(x, val)
|
||||||
if normalize(cval) != normalize(val):
|
if normalize_tweak(cval) != normalize_tweak(val):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -539,9 +539,24 @@ def make_unicode(obj):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_tweak(val):
|
||||||
|
if isinstance(val, (list, tuple)):
|
||||||
|
return tuple(map(normalize_tweak, val))
|
||||||
|
if isinstance(val, dict):
|
||||||
|
return {k: normalize_tweak(v) for k, v in iteritems(val)}
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
def write_custom_tweaks(tweaks_dict):
|
def write_custom_tweaks(tweaks_dict):
|
||||||
make_config_dir()
|
make_config_dir()
|
||||||
raw = json_dumps(make_unicode(tweaks_dict))
|
tweaks_dict = make_unicode(tweaks_dict)
|
||||||
|
changed_tweaks = {}
|
||||||
|
default_tweaks = exec_tweaks(default_tweaks_raw())
|
||||||
|
for key, cval in iteritems(tweaks_dict):
|
||||||
|
if key in default_tweaks and normalize_tweak(cval) == normalize_tweak(default_tweaks[key]):
|
||||||
|
continue
|
||||||
|
changed_tweaks[key] = cval
|
||||||
|
raw = json_dumps(changed_tweaks)
|
||||||
with open(tweaks_file(), 'wb') as f:
|
with open(tweaks_file(), 'wb') as f:
|
||||||
f.write(raw)
|
f.write(raw)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user