Add a jupyter server extension to render desktop/

A mess of a commit, should have been several.

- Finish renaming package from jupyter_desktop to
  jupyter_desktop_server
- Revert 360f9b04c5. Looks like
  websockify gets super confused when you put shell in the middle
  of it and the process it is spawning.
- Add a server extension that renders a slightly modified copy
  of vnc_lite.html as /desktop. This will be modified more and more
  as we go forward. This also helps us remove the mapping present
  in the jupyter server proxy entry
This commit is contained in:
YuviPanda 2019-11-19 16:36:54 -08:00
parent bda9a7ec21
commit 18d7fb7b2a
245 changed files with 62 additions and 14 deletions

View File

@ -1 +1,3 @@
graft jupyter_desktop/share
graft jupyter_desktop_server/share
graft jupyter_desktop_server/etc
graft jupyter_desktop_server/templates

View File

@ -1,17 +1,20 @@
import os
import shlex
import tempfile
from notebook.utils import url_path_join as ujoin
from tornado.web import StaticFileHandler
from .handlers import DesktopHandler
HERE = os.path.dirname(os.path.abspath(__file__))
def setup_desktop():
def setup_vnc():
# make a secure temporary directory for sockets
# This is only readable, writeable & searchable by our uid
sockets_dir = tempfile.mkdtemp()
sockets_path = os.path.join(sockets_dir, 'vnc-socket')
vnc_command = ' '.join((shlex.quote(p) for p in [
vnc_command = [
os.path.join(HERE, 'share/tigervnc/bin/vncserver'),
'-verbose',
'-xstartup', os.path.join(HERE, 'share/xstartup'),
@ -20,7 +23,7 @@ def setup_desktop():
'-rfbunixpath', sockets_path,
'-fg',
':1',
]))
]
return {
'command': [
'websockify', '-v',
@ -29,10 +32,18 @@ def setup_desktop():
'5901',
'--unix-target', sockets_path,
'--',
'/bin/sh', '-c',
f'cd {os.getcwd()} && {vnc_command}'
],
] + vnc_command,
'port': 5901,
'timeout': 30,
'mappath': {'/': '/vnc_lite.html'},
}
def load_jupyter_server_extension(nbapp):
# Set up handlers picked up via config
base_url = nbapp.web_app.settings['base_url']
web_path = os.path.join(HERE, 'share/web')
nbapp.web_app.add_handlers('.*', [
(ujoin(base_url, 'desktop-server/static/(.*)'), StaticFileHandler, {'path': web_path}),
(ujoin(base_url, 'desktop'), DesktopHandler)
])

View File

@ -0,0 +1,7 @@
{
"NotebookApp": {
"nbserver_extensions": {
"jupyter_desktop_server": true
}
}
}

View File

@ -0,0 +1,24 @@
from notebook.base.handlers import IPythonHandler
import jinja2
import os
class DesktopHandler(IPythonHandler):
def initialize(self):
super().initialize()
# FIXME: Is this really the best way to use jinja2 here?
# I can't seem to get the jinja2 env in the base handler to
# actually load templates from arbitrary paths ugh.
jinja2_env = self.settings['jinja2_env']
jinja2_env.loader = jinja2.ChoiceLoader([
jinja2_env.loader,
jinja2.FileSystemLoader(
os.path.join(os.path.dirname(__file__), 'templates')
)
])
def get(self):
novnc_base_url = self.base_url + "desktop-server/static/noVNC-1.1.0/"
self.write(
self.render_template('desktop.html', novnc_base_url=novnc_base_url)
)

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Some files were not shown because too many files have changed in this diff Show More