mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
Initial REST API for terminals
This commit is contained in:
parent
9c0084e615
commit
b929b3f09e
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from terminado import NamedTermManager
|
||||
from .handlers import TerminalHandler, NewTerminalHandler, TermSocket
|
||||
from . import api_handlers
|
||||
|
||||
def initialize(webapp):
|
||||
shell = os.environ.get('SHELL', 'sh')
|
||||
@ -10,5 +11,7 @@ def initialize(webapp):
|
||||
(r"/terminals/(\w+)", TerminalHandler),
|
||||
(r"/terminals/websocket/(\w+)", TermSocket,
|
||||
{'term_manager': webapp.terminal_manager}),
|
||||
(r"/api/terminals", api_handlers.TerminalRootHandler),
|
||||
(r"/api/terminals/(\w+)", api_handlers.TerminalHandler),
|
||||
]
|
||||
webapp.add_handlers(".*$", handlers)
|
35
IPython/html/terminal/api_handlers.py
Normal file
35
IPython/html/terminal/api_handlers.py
Normal file
@ -0,0 +1,35 @@
|
||||
import json
|
||||
from tornado import web
|
||||
from ..base.handlers import IPythonHandler, json_errors
|
||||
|
||||
class TerminalRootHandler(IPythonHandler):
|
||||
@web.authenticated
|
||||
@json_errors
|
||||
def get(self):
|
||||
tm = self.application.terminal_manager
|
||||
terms = [{'name': name} for name in tm.terminals]
|
||||
self.finish(json.dumps(terms))
|
||||
|
||||
class TerminalHandler(IPythonHandler):
|
||||
SUPPORTED_METHODS = ('GET', 'DELETE')
|
||||
|
||||
@web.authenticated
|
||||
@json_errors
|
||||
def get(self, name):
|
||||
tm = self.application.terminal_manager
|
||||
if name in tm.terminals:
|
||||
self.finish(json.dumps({'name': name}))
|
||||
else:
|
||||
raise web.HTTPError(404, "Terminal not found: %r" % name)
|
||||
|
||||
@web.authenticated
|
||||
@json_errors
|
||||
def delete(self, name):
|
||||
tm = self.application.terminal_manager
|
||||
if name in tm.terminals:
|
||||
tm.kill(name)
|
||||
# XXX: Should this wait for terminal to finish before returning?
|
||||
self.set_status(204)
|
||||
self.finish()
|
||||
else:
|
||||
raise web.HTTPError(404, "Terminal not found: %r" % name)
|
Loading…
Reference in New Issue
Block a user