mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When running the embedded server from source compile the RapydSCript in the server thread and use atomic writes to update the output
This commit is contained in:
parent
2240b19882
commit
db4ba63005
@ -46,10 +46,6 @@ class Server(object):
|
||||
self.opts = opts
|
||||
self.log, self.access_log = log, access_log
|
||||
self.handler.set_log(self.log)
|
||||
_df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
||||
if _df and os.path.exists(_df):
|
||||
from calibre.utils.rapydscript import compile_srv
|
||||
compile_srv()
|
||||
|
||||
@property
|
||||
def user_manager(self):
|
||||
@ -91,6 +87,10 @@ class Server(object):
|
||||
pass
|
||||
reset_caches() # we reset the cache as the server tdir has changed
|
||||
try:
|
||||
_df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
||||
if _df and os.path.exists(_df):
|
||||
from calibre.utils.rapydscript import compile_srv
|
||||
compile_srv()
|
||||
self.loop.serve_forever()
|
||||
except BaseException as e:
|
||||
self.exception = e
|
||||
|
@ -19,6 +19,7 @@ from threading import Thread, local
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.constants import __appname__, __version__, cache_dir
|
||||
from calibre.utils.filenames import atomic_rename
|
||||
from calibre.utils.terminal import ANSIStream
|
||||
from duktape import Context, JSError, to_python
|
||||
from lzma.xz import compress, decompress
|
||||
@ -223,10 +224,16 @@ def compile_srv():
|
||||
html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1)
|
||||
|
||||
manifest = create_manifest(html)
|
||||
with lopen(os.path.join(base, 'index-generated.html'), 'wb') as f:
|
||||
f.write(html)
|
||||
with lopen(os.path.join(base, 'calibre.appcache'), 'wb') as f:
|
||||
f.write(manifest)
|
||||
|
||||
def atomic_write(name, content):
|
||||
name = os.path.join(base, name)
|
||||
tname = name + '.tmp'
|
||||
with lopen(tname, 'wb') as f:
|
||||
f.write(content)
|
||||
atomic_rename(tname, name)
|
||||
|
||||
atomic_write('index-generated.html', html)
|
||||
atomic_write('calibre.appcache', manifest)
|
||||
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user