Show More
@@ -164,6 +164,10 b' class IPythonHandler(AuthenticatedHandler):' | |||||
164 | return self.settings['session_manager'] |
|
164 | return self.settings['session_manager'] | |
165 |
|
165 | |||
166 | @property |
|
166 | @property | |
|
167 | def terminal_manager(self): | |||
|
168 | return self.settings['terminal_manager'] | |||
|
169 | ||||
|
170 | @property | |||
167 | def kernel_spec_manager(self): |
|
171 | def kernel_spec_manager(self): | |
168 | return self.settings['kernel_spec_manager'] |
|
172 | return self.settings['kernel_spec_manager'] | |
169 |
|
173 |
@@ -39,11 +39,28 b' define([' | |||||
39 | $('#new_terminal').click($.proxy(this.new_terminal, this)); |
|
39 | $('#new_terminal').click($.proxy(this.new_terminal, this)); | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | TerminalList.prototype.new_terminal = function() { |
|
42 | TerminalList.prototype.new_terminal = function () { | |
43 | var url = utils.url_join_encode(this.base_url, 'terminals/new'); |
|
43 | var w = window.open(); | |
44 | window.open(url, '_blank'); |
|
44 | var base_url = this.base_url; | |
|
45 | var settings = { | |||
|
46 | type : "POST", | |||
|
47 | dataType: "json", | |||
|
48 | success : function (data, status, xhr) { | |||
|
49 | var name = data.name; | |||
|
50 | w.location = utils.url_join_encode(base_url, 'terminals', name); | |||
|
51 | }, | |||
|
52 | error : function(jqXHR, status, error){ | |||
|
53 | w.close(); | |||
|
54 | utils.log_ajax_error(jqXHR, status, error); | |||
|
55 | }, | |||
|
56 | }; | |||
|
57 | var url = utils.url_join_encode( | |||
|
58 | this.base_url, | |||
|
59 | 'api/terminals' | |||
|
60 | ); | |||
|
61 | $.ajax(url, settings); | |||
45 | }; |
|
62 | }; | |
46 |
|
63 | |||
47 | TerminalList.prototype.load_terminals = function() { |
|
64 | TerminalList.prototype.load_terminals = function() { | |
48 | var that = this; |
|
65 | var that = this; | |
49 | var url = utils.url_join_encode(this.base_url, 'api/terminals'); |
|
66 | var url = utils.url_join_encode(this.base_url, 'api/terminals'); |
@@ -1,18 +1,17 b'' | |||||
1 | import os |
|
1 | import os | |
2 | from terminado import NamedTermManager |
|
2 | from terminado import NamedTermManager | |
3 | from IPython.html.utils import url_path_join as ujoin |
|
3 | from IPython.html.utils import url_path_join as ujoin | |
4 |
from .handlers import TerminalHandler, |
|
4 | from .handlers import TerminalHandler, TermSocket | |
5 | from . import api_handlers |
|
5 | from . import api_handlers | |
6 |
|
6 | |||
7 | def initialize(webapp): |
|
7 | def initialize(webapp): | |
8 | shell = os.environ.get('SHELL', 'sh') |
|
8 | shell = os.environ.get('SHELL', 'sh') | |
9 | webapp.terminal_manager = NamedTermManager(shell_command=[shell]) |
|
9 | terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(shell_command=[shell]) | |
10 | base_url = webapp.settings['base_url'] |
|
10 | base_url = webapp.settings['base_url'] | |
11 | handlers = [ |
|
11 | handlers = [ | |
12 | (ujoin(base_url, "/terminals/new"), NewTerminalHandler), |
|
|||
13 | (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), |
|
12 | (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), | |
14 | (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, |
|
13 | (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, | |
15 |
{'term_manager': |
|
14 | {'term_manager': terminal_manager}), | |
16 | (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), |
|
15 | (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), | |
17 | (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), |
|
16 | (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), | |
18 | ] |
|
17 | ] |
@@ -1,22 +1,31 b'' | |||||
1 | import json |
|
1 | import json | |
2 | from tornado import web |
|
2 | from tornado import web | |
3 | from ..base.handlers import IPythonHandler, json_errors |
|
3 | from ..base.handlers import IPythonHandler, json_errors | |
|
4 | from ..utils import url_path_join | |||
4 |
|
5 | |||
5 | class TerminalRootHandler(IPythonHandler): |
|
6 | class TerminalRootHandler(IPythonHandler): | |
6 | @web.authenticated |
|
7 | @web.authenticated | |
7 | @json_errors |
|
8 | @json_errors | |
8 | def get(self): |
|
9 | def get(self): | |
9 |
tm = self. |
|
10 | tm = self.terminal_manager | |
10 | terms = [{'name': name} for name in tm.terminals] |
|
11 | terms = [{'name': name} for name in tm.terminals] | |
11 | self.finish(json.dumps(terms)) |
|
12 | self.finish(json.dumps(terms)) | |
12 |
|
13 | |||
|
14 | @web.authenticated | |||
|
15 | @json_errors | |||
|
16 | def post(self): | |||
|
17 | """POST /terminals creates a new terminal and redirects to it""" | |||
|
18 | name, _ = self.terminal_manager.new_named_terminal() | |||
|
19 | self.finish(json.dumps({'name': name})) | |||
|
20 | ||||
|
21 | ||||
13 | class TerminalHandler(IPythonHandler): |
|
22 | class TerminalHandler(IPythonHandler): | |
14 | SUPPORTED_METHODS = ('GET', 'DELETE') |
|
23 | SUPPORTED_METHODS = ('GET', 'DELETE') | |
15 |
|
24 | |||
16 | @web.authenticated |
|
25 | @web.authenticated | |
17 | @json_errors |
|
26 | @json_errors | |
18 | def get(self, name): |
|
27 | def get(self, name): | |
19 |
tm = self. |
|
28 | tm = self.terminal_manager | |
20 | if name in tm.terminals: |
|
29 | if name in tm.terminals: | |
21 | self.finish(json.dumps({'name': name})) |
|
30 | self.finish(json.dumps({'name': name})) | |
22 | else: |
|
31 | else: | |
@@ -25,7 +34,7 b' class TerminalHandler(IPythonHandler):' | |||||
25 | @web.authenticated |
|
34 | @web.authenticated | |
26 | @json_errors |
|
35 | @json_errors | |
27 | def delete(self, name): |
|
36 | def delete(self, name): | |
28 |
tm = self. |
|
37 | tm = self.terminal_manager | |
29 | if name in tm.terminals: |
|
38 | if name in tm.terminals: | |
30 | tm.kill(name) |
|
39 | tm.kill(name) | |
31 | # XXX: Should this wait for terminal to finish before returning? |
|
40 | # XXX: Should this wait for terminal to finish before returning? |
@@ -16,13 +16,6 b' class TerminalHandler(IPythonHandler):' | |||||
16 | self.write(self.render_template('terminal.html', |
|
16 | self.write(self.render_template('terminal.html', | |
17 | ws_path="terminals/websocket/%s" % term_name)) |
|
17 | ws_path="terminals/websocket/%s" % term_name)) | |
18 |
|
18 | |||
19 | class NewTerminalHandler(IPythonHandler): |
|
|||
20 | """Redirect to a new terminal.""" |
|
|||
21 | @web.authenticated |
|
|||
22 | def get(self): |
|
|||
23 | name, _ = self.application.terminal_manager.new_named_terminal() |
|
|||
24 | self.redirect(name, permanent=False) |
|
|||
25 |
|
||||
26 | class TermSocket(terminado.TermSocket, IPythonHandler): |
|
19 | class TermSocket(terminado.TermSocket, IPythonHandler): | |
27 | def get(self, *args, **kwargs): |
|
20 | def get(self, *args, **kwargs): | |
28 | if not self.get_current_user(): |
|
21 | if not self.get_current_user(): |
General Comments 0
You need to be logged in to leave comments.
Login now