mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only dynamically compile actually changed coffeescript
This commit is contained in:
parent
9529fa26dc
commit
ef39b9b584
@ -77,12 +77,15 @@ def get_image_path(path, data=False, allow_user_override=True):
|
||||
return get_path('images', allow_user_override=allow_user_override)
|
||||
return get_path('images/'+path, data=data, allow_user_override=allow_user_override)
|
||||
|
||||
def _compile_coffeescript(name):
|
||||
from calibre.utils.serve_coffee import compile_coffeescript
|
||||
path = (u'/'.join(name.split('.'))) + '.coffee'
|
||||
def js_name_to_path(name, ext='.coffee'):
|
||||
path = (u'/'.join(name.split('.'))) + ext
|
||||
d = os.path.dirname
|
||||
base = d(d(os.path.abspath(__file__)))
|
||||
src = os.path.join(base, path)
|
||||
return os.path.join(base, path)
|
||||
|
||||
def _compile_coffeescript(name):
|
||||
from calibre.utils.serve_coffee import compile_coffeescript
|
||||
src = js_name_to_path(name)
|
||||
with open(src, 'rb') as f:
|
||||
cs, errors = compile_coffeescript(f.read(), src)
|
||||
if errors:
|
||||
@ -93,12 +96,19 @@ def _compile_coffeescript(name):
|
||||
return cs
|
||||
|
||||
def compiled_coffeescript(name, dynamic=False):
|
||||
if dynamic:
|
||||
return _compile_coffeescript(name)
|
||||
else:
|
||||
import zipfile
|
||||
zipf = get_path('compiled_coffeescript.zip', allow_user_override=False)
|
||||
with zipfile.ZipFile(zipf, 'r') as zf:
|
||||
import zipfile
|
||||
zipf = get_path('compiled_coffeescript.zip', allow_user_override=False)
|
||||
with zipfile.ZipFile(zipf, 'r') as zf:
|
||||
if dynamic:
|
||||
import json
|
||||
existing_hash = json.loads(zf.comment or '{}').get(name + '.js')
|
||||
if existing_hash is not None:
|
||||
import hashlib
|
||||
with open(js_name_to_path(name), 'rb') as f:
|
||||
if existing_hash == hashlib.sha1(f.read()).hexdigest():
|
||||
return zf.read(name + '.js')
|
||||
return _compile_coffeescript(name)
|
||||
else:
|
||||
return zf.read(name+'.js')
|
||||
|
||||
__builtin__.__dict__['P'] = get_path
|
||||
|
Loading…
x
Reference in New Issue
Block a user