Env variables for server root & URL in terminals

This came up on reddit: if you want to open a notebook or a file in the
text editor from the terminal inside the notebook web interface, you can
construct a URL to open. But to do that accurately, you need to know the
root directory where the server is looking, and the first part of the
URL. This exposes both of those as environment variables:
$JUPYTER_SERVER_ROOT and $JUPYTER_SERVER_URL.
Thomas Kluyver 11 years ago
parent cc1f01d21e
commit a425ed30ef

@ -889,7 +889,7 @@ class NotebookApp(JupyterApp):
def init_terminals(self):
try:
from .terminal import initialize
initialize(self.web_app)
initialize(self.web_app, self.notebook_dir, self.connection_url)
self.web_app.settings['terminals_available'] = True
except ImportError as e:
log = self.log.debug if sys.platform == 'win32' else self.log.warn

@ -12,9 +12,14 @@ from notebook.utils import url_path_join as ujoin
from .handlers import TerminalHandler, TermSocket
from . import api_handlers
def initialize(webapp):
def initialize(webapp, notebook_dir, connection_url):
shell = os.environ.get('SHELL') or 'sh'
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(shell_command=[shell])
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
shell_command=[shell],
extra_env={'JUPYTER_SERVER_ROOT': notebook_dir,
'JUPYTER_SERVER_URL': connection_url,
},
)
terminal_manager.log = app_log
base_url = webapp.settings['base_url']
handlers = [
@ -24,4 +29,4 @@ def initialize(webapp):
(ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
(ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
]
webapp.add_handlers(".*$", handlers)
webapp.add_handlers(".*$", handlers)

Loading…
Cancel
Save