diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 4653529095..75f95b1a90 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -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.max_view_width.setValue(opts.max_view_width) 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)) pmap = {} for i in range(len(pats)): diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 3d2663cd1d..5c8fe523e3 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -705,7 +705,8 @@ if prefs['installation_uuid'] is None: # Read tweaks def read_raw_tweaks(): 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') if not os.path.exists(tweaks_file): with open(tweaks_file, 'wb') as f: diff --git a/src/calibre/utils/resources.py b/src/calibre/utils/resources.py index dd600eb627..97c14926e4 100644 --- a/src/calibre/utils/resources.py +++ b/src/calibre/utils/resources.py @@ -25,29 +25,36 @@ class PathResolver(object): pass return False + self.default_path = sys.resources_location + dev_path = os.environ.get('CALIBRE_DEVELOP_FROM', None) if dev_path is not None: dev_path = os.path.join(os.path.abspath( os.path.dirname(dev_path)), 'resources') if suitable(dev_path): self.locations.insert(0, dev_path) + self.default_path = dev_path user_path = os.path.join(config_dir, 'resources') + self.user_path = None if suitable(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, '/') ans = self.cache.get(path, None) if ans is None: for base in self.locations: + if not allow_user_override and base == self.user_path: + continue fpath = os.path.join(base, *path.split('/')) if os.path.exists(fpath): ans = fpath break 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 @@ -55,13 +62,13 @@ class PathResolver(object): _resolver = PathResolver() -def get_path(path, data=False): - fpath = _resolver(path) +def get_path(path, data=False, allow_user_override=True): + fpath = _resolver(path, allow_user_override=allow_user_override) if data: return open(fpath, 'rb').read() 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) __builtin__.__dict__['P'] = get_path