mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Do not allow the user to override the default tweaks or the hyphenate javascript. Also if a file is not found, do not use the user location as the default base. Fixes #6524 (Problem opening Preferences in Ebook-Viewer v7.14)
This commit is contained in:
parent
00abd91c6f
commit
d9f60b415f
@ -81,7 +81,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.css.setToolTip(_('Set the user CSS stylesheet. This can be used to customize the look of all books.'))
|
self.css.setToolTip(_('Set the user CSS stylesheet. This can be used to customize the look of all books.'))
|
||||||
self.max_view_width.setValue(opts.max_view_width)
|
self.max_view_width.setValue(opts.max_view_width)
|
||||||
pats = [os.path.basename(x).split('.')[0] for x in
|
pats = [os.path.basename(x).split('.')[0] for x in
|
||||||
glob.glob(P('viewer/hyphenate/patterns/*.js'))]
|
glob.glob(P('viewer/hyphenate/patterns/*.js',
|
||||||
|
allow_user_override=False))]
|
||||||
names = list(map(get_language, pats))
|
names = list(map(get_language, pats))
|
||||||
pmap = {}
|
pmap = {}
|
||||||
for i in range(len(pats)):
|
for i in range(len(pats)):
|
||||||
|
@ -705,7 +705,8 @@ if prefs['installation_uuid'] is None:
|
|||||||
# Read tweaks
|
# Read tweaks
|
||||||
def read_raw_tweaks():
|
def read_raw_tweaks():
|
||||||
make_config_dir()
|
make_config_dir()
|
||||||
default_tweaks = P('default_tweaks.py', data=True)
|
default_tweaks = P('default_tweaks.py', data=True,
|
||||||
|
allow_user_override=False)
|
||||||
tweaks_file = os.path.join(config_dir, 'tweaks.py')
|
tweaks_file = os.path.join(config_dir, 'tweaks.py')
|
||||||
if not os.path.exists(tweaks_file):
|
if not os.path.exists(tweaks_file):
|
||||||
with open(tweaks_file, 'wb') as f:
|
with open(tweaks_file, 'wb') as f:
|
||||||
|
@ -25,29 +25,36 @@ class PathResolver(object):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.default_path = sys.resources_location
|
||||||
|
|
||||||
dev_path = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
dev_path = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
||||||
if dev_path is not None:
|
if dev_path is not None:
|
||||||
dev_path = os.path.join(os.path.abspath(
|
dev_path = os.path.join(os.path.abspath(
|
||||||
os.path.dirname(dev_path)), 'resources')
|
os.path.dirname(dev_path)), 'resources')
|
||||||
if suitable(dev_path):
|
if suitable(dev_path):
|
||||||
self.locations.insert(0, dev_path)
|
self.locations.insert(0, dev_path)
|
||||||
|
self.default_path = dev_path
|
||||||
|
|
||||||
user_path = os.path.join(config_dir, 'resources')
|
user_path = os.path.join(config_dir, 'resources')
|
||||||
|
self.user_path = None
|
||||||
if suitable(user_path):
|
if suitable(user_path):
|
||||||
self.locations.insert(0, user_path)
|
self.locations.insert(0, user_path)
|
||||||
|
self.user_path = user_path
|
||||||
|
|
||||||
def __call__(self, path):
|
def __call__(self, path, allow_user_override=True):
|
||||||
path = path.replace(os.sep, '/')
|
path = path.replace(os.sep, '/')
|
||||||
ans = self.cache.get(path, None)
|
ans = self.cache.get(path, None)
|
||||||
if ans is None:
|
if ans is None:
|
||||||
for base in self.locations:
|
for base in self.locations:
|
||||||
|
if not allow_user_override and base == self.user_path:
|
||||||
|
continue
|
||||||
fpath = os.path.join(base, *path.split('/'))
|
fpath = os.path.join(base, *path.split('/'))
|
||||||
if os.path.exists(fpath):
|
if os.path.exists(fpath):
|
||||||
ans = fpath
|
ans = fpath
|
||||||
break
|
break
|
||||||
|
|
||||||
if ans is None:
|
if ans is None:
|
||||||
ans = os.path.join(self.locations[0], *path.split('/'))
|
ans = os.path.join(self.default_path, *path.split('/'))
|
||||||
|
|
||||||
self.cache[path] = ans
|
self.cache[path] = ans
|
||||||
|
|
||||||
@ -55,13 +62,13 @@ class PathResolver(object):
|
|||||||
|
|
||||||
_resolver = PathResolver()
|
_resolver = PathResolver()
|
||||||
|
|
||||||
def get_path(path, data=False):
|
def get_path(path, data=False, allow_user_override=True):
|
||||||
fpath = _resolver(path)
|
fpath = _resolver(path, allow_user_override=allow_user_override)
|
||||||
if data:
|
if data:
|
||||||
return open(fpath, 'rb').read()
|
return open(fpath, 'rb').read()
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
def get_image_path(path, data=False):
|
def get_image_path(path, data=False, allow_user_override=True):
|
||||||
return get_path('images/'+path, data=data)
|
return get_path('images/'+path, data=data)
|
||||||
|
|
||||||
__builtin__.__dict__['P'] = get_path
|
__builtin__.__dict__['P'] = get_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user