mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Infrastructure for serving rapydscript in the new content server
This commit is contained in:
parent
28a16466e2
commit
fa49f81b3e
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ resources/builtin_recipes.zip
|
||||
resources/template-functions.json
|
||||
resources/editor-functions.json
|
||||
resources/user-manual-translation-stats.json
|
||||
resources/content-server/main.js
|
||||
icons/icns/*.iconset
|
||||
setup/installer/windows/calibre/build.log
|
||||
tags
|
||||
|
10
resources/content-server/index.html
Normal file
10
resources/content-server/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>calibre</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<script type="text/javascript" src="js/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
@ -61,7 +61,7 @@ if islinux:
|
||||
for fd in r:
|
||||
w = self.fd_map[fd]
|
||||
modified |= w()
|
||||
self.handle_modified()
|
||||
self.handle_modified(modified)
|
||||
|
||||
def ignore_event(self, path, name):
|
||||
return not self.file_is_watched(name)
|
||||
@ -176,6 +176,7 @@ def find_dirs_to_watch(fpath, dirs, add_default_dirs):
|
||||
base = d(d(d(srv)))
|
||||
add(os.path.join(base, 'resources', 'server'))
|
||||
add(os.path.join(base, 'src', 'calibre', 'db'))
|
||||
add(os.path.join(base, 'src', 'pyj'))
|
||||
return dirs
|
||||
|
||||
def join_process(p, timeout=5):
|
||||
@ -211,7 +212,9 @@ class Worker(object):
|
||||
self.p = None
|
||||
|
||||
def restart(self):
|
||||
from calibre.utils.rapydscript import compile_srv
|
||||
self.clean_kill()
|
||||
compile_srv()
|
||||
self.p = subprocess.Popen(self.cmd, creationflags=getattr(subprocess, 'CREATE_NEW_PROCESS_GROUP', 0))
|
||||
|
||||
def auto_reload(log, dirs=frozenset(), cmd=None, add_default_dirs=True):
|
||||
|
23
src/calibre/srv/code.py
Normal file
23
src/calibre/srv/code.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
import errno
|
||||
|
||||
from calibre.srv.errors import HTTPNotFound
|
||||
from calibre.srv.routes import endpoint
|
||||
|
||||
@endpoint('', auth_required=False)
|
||||
def index(ctx, rd):
|
||||
return open(P('content-server/index.html'), 'rb')
|
||||
|
||||
@endpoint('/js/{which}', auth_required=False)
|
||||
def js(ctx, rd, which):
|
||||
try:
|
||||
return open(P('content-server/' + which), 'rb')
|
||||
except EnvironmentError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
raise HTTPNotFound('No js with name: %r' % which)
|
||||
raise
|
@ -131,7 +131,7 @@ class Handler(object):
|
||||
|
||||
def __init__(self, libraries, opts, testing=False):
|
||||
self.router = Router(ctx=Context(libraries, opts, testing=testing), url_prefix=opts.url_prefix)
|
||||
for module in ('content', 'ajax'):
|
||||
for module in ('content', 'ajax', 'code'):
|
||||
module = import_module('calibre.srv.' + module)
|
||||
self.router.load_routes(vars(module).itervalues())
|
||||
self.router.finalize()
|
||||
|
@ -69,6 +69,10 @@ class Server(object):
|
||||
self.handler.set_log(self.loop.log)
|
||||
self.serve_forever = self.loop.serve_forever
|
||||
self.stop = self.loop.stop
|
||||
_df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
||||
if _df and os.path.exists(_df):
|
||||
from calibre.utils.rapydscript import compile_srv
|
||||
compile_srv()
|
||||
|
||||
|
||||
def create_option_parser():
|
||||
|
@ -78,6 +78,17 @@ def compile_pyj(data, filename='<stdin>', beautify=True, private_scope=True, lib
|
||||
}
|
||||
c.g.rs_source_code = data
|
||||
return c.eval('exports["compile"](rs_source_code, %s, current_options)' % json.dumps(filename))
|
||||
|
||||
def compile_srv():
|
||||
d = os.path.dirname
|
||||
base = d(d(d(d(os.path.abspath(__file__)))))
|
||||
rapydscript_dir = os.path.join(base, 'src', 'pyj')
|
||||
fname = os.path.join(rapydscript_dir, 'srv.pyj')
|
||||
with open(fname, 'rb') as f:
|
||||
raw = compile_pyj(f.read(), fname)
|
||||
with open(P('content-server/main.js', allow_user_override=False), 'wb') as f:
|
||||
f.write(raw.encode('utf-8'))
|
||||
|
||||
# }}}
|
||||
|
||||
# Translations {{{
|
||||
|
5
src/pyj/srv.pyj
Normal file
5
src/pyj/srv.pyj
Normal file
@ -0,0 +1,5 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
alert('hello world!')
|
||||
|
Loading…
x
Reference in New Issue
Block a user