mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-02-02 21:35:17 +01:00
Speed up resource lookup when using CALIBRE_DEVELOP_FROM
This commit is contained in:
parent
d814a9af84
commit
4f87f15e4b
1 changed files with 10 additions and 6 deletions
|
|
@ -15,19 +15,23 @@
|
|||
if not os.path.exists(_dev_path):
|
||||
_dev_path = None
|
||||
|
||||
_path_cache = {}
|
||||
|
||||
def get_path(path, data=False):
|
||||
global _dev_path
|
||||
path = path.replace(os.sep, '/')
|
||||
base = None
|
||||
base = sys.resources_location
|
||||
if _dev_path is not None:
|
||||
if path in _path_cache:
|
||||
return _path_cache[path]
|
||||
if os.path.exists(os.path.join(_dev_path, *path.split('/'))):
|
||||
base = _dev_path
|
||||
if base is None:
|
||||
base = sys.resources_location
|
||||
path = os.path.join(base, *path.split('/'))
|
||||
fpath = os.path.join(base, *path.split('/'))
|
||||
if _dev_path is not None:
|
||||
_path_cache[path] = fpath
|
||||
if data:
|
||||
return open(path, 'rb').read()
|
||||
return path
|
||||
return open(fpath, 'rb').read()
|
||||
return fpath
|
||||
|
||||
def get_image_path(path, data=False):
|
||||
return get_path('images/'+path, data=data)
|
||||
|
|
|
|||
Loading…
Reference in a new issue