Show More
@@ -33,15 +33,26 b' class NotebookRootHandler(IPythonHandler):' | |||||
33 |
|
33 | |||
34 | @web.authenticated |
|
34 | @web.authenticated | |
35 | def get(self): |
|
35 | def get(self): | |
|
36 | """get returns a list of notebooks from the location | |||
|
37 | where the server was started.""" | |||
36 | nbm = self.notebook_manager |
|
38 | nbm = self.notebook_manager | |
37 | notebooks = nbm.list_notebooks("") |
|
39 | notebooks = nbm.list_notebooks("") | |
38 | self.finish(jsonapi.dumps(notebooks)) |
|
40 | self.finish(jsonapi.dumps(notebooks)) | |
39 |
|
41 | |||
40 | @web.authenticated |
|
42 | @web.authenticated | |
41 | def post(self): |
|
43 | def post(self): | |
|
44 | """post creates a notebooks in the directory where the | |||
|
45 | server was started""" | |||
42 | nbm = self.notebook_manager |
|
46 | nbm = self.notebook_manager | |
43 | notebook_name = nbm.new_notebook() |
|
47 | body = self.request.body.strip() | |
44 | model = nbm.notebook_model(notebook_name) |
|
48 | format = self.get_argument('format', default='json') | |
|
49 | name = self.get_argument('name', default=None) | |||
|
50 | if body: | |||
|
51 | fname = nbm.save_new_notebook(body, notebook_path=None, name=name, format=format) | |||
|
52 | else: | |||
|
53 | fname = nbm.new_notebook(notebook_path=None) | |||
|
54 | self.set_header('Location', nbm.notebook_dir + fname) | |||
|
55 | model = nbm.notebook_model(fname) | |||
45 | self.set_header('Location', '{0}api/notebooks/{1}'.format(self.base_project_url, notebook_name)) |
|
56 | self.set_header('Location', '{0}api/notebooks/{1}'.format(self.base_project_url, notebook_name)) | |
46 | self.finish(jsonapi.dumps(model)) |
|
57 | self.finish(jsonapi.dumps(model)) | |
47 |
|
58 | |||
@@ -50,22 +61,29 b' class NotebookRootRedirect(IPythonHandler):' | |||||
50 |
|
61 | |||
51 | @web.authenticated |
|
62 | @web.authenticated | |
52 | def get(self): |
|
63 | def get(self): | |
|
64 | """get redirects to not include trailing backslash""" | |||
53 | self.redirect("/api/notebooks") |
|
65 | self.redirect("/api/notebooks") | |
54 |
|
66 | |||
55 |
|
67 | |||
56 | class NotebookHandler(IPythonHandler): |
|
68 | class NotebookHandler(IPythonHandler): | |
57 |
|
69 | |||
58 | SUPPORTED_METHODS = ('GET', 'PUT', 'PATCH', 'DELETE') |
|
70 | SUPPORTED_METHODS = ('GET', 'PUT', 'PATCH', 'POST','DELETE') | |
59 |
|
71 | |||
60 | @web.authenticated |
|
72 | @web.authenticated | |
61 | def get(self, notebook_path): |
|
73 | def get(self, notebook_path): | |
|
74 | """get checks if a notebook is not named, an returns a list of notebooks | |||
|
75 | in the notebook path given. If a name is given, return | |||
|
76 | the notebook representation""" | |||
62 | nbm = self.notebook_manager |
|
77 | nbm = self.notebook_manager | |
63 | name, path = nbm.named_notebook_path(notebook_path) |
|
78 | name, path = nbm.named_notebook_path(notebook_path) | |
64 |
|
79 | |||
65 | if name == None: |
|
80 | # Check to see if a notebook name was given | |
|
81 | if name is None: | |||
|
82 | # List notebooks in 'notebook_path' | |||
66 | notebooks = nbm.list_notebooks(path) |
|
83 | notebooks = nbm.list_notebooks(path) | |
67 | self.finish(jsonapi.dumps(notebooks)) |
|
84 | self.finish(jsonapi.dumps(notebooks)) | |
68 | else: |
|
85 | else: | |
|
86 | # get and return notebook representation | |||
69 | format = self.get_argument('format', default='json') |
|
87 | format = self.get_argument('format', default='json') | |
70 | download = self.get_argument('download', default='False') |
|
88 | download = self.get_argument('download', default='False') | |
71 | model = nbm.notebook_model(name,path) |
|
89 | model = nbm.notebook_model(name,path) | |
@@ -86,6 +104,8 b' class NotebookHandler(IPythonHandler):' | |||||
86 |
|
104 | |||
87 | @web.authenticated |
|
105 | @web.authenticated | |
88 | def patch(self, notebook_path): |
|
106 | def patch(self, notebook_path): | |
|
107 | """patch is currently used strictly for notebook renaming. | |||
|
108 | Changes the notebook name to the name given in data.""" | |||
89 | nbm = self.notebook_manager |
|
109 | nbm = self.notebook_manager | |
90 | name, path = nbm.named_notebook_path(notebook_path) |
|
110 | name, path = nbm.named_notebook_path(notebook_path) | |
91 | data = jsonapi.loads(self.request.body) |
|
111 | data = jsonapi.loads(self.request.body) | |
@@ -94,30 +114,35 b' class NotebookHandler(IPythonHandler):' | |||||
94 | self.finish(jsonapi.dumps(model)) |
|
114 | self.finish(jsonapi.dumps(model)) | |
95 |
|
115 | |||
96 | @web.authenticated |
|
116 | @web.authenticated | |
97 |
def p |
|
117 | def post(self,notebook_path): | |
|
118 | """Create a new notebook in the location given by 'notebook_path'.""" | |||
98 | nbm = self.notebook_manager |
|
119 | nbm = self.notebook_manager | |
99 | fname, path = nbm.named_notebook_path(notebook_path) |
|
120 | fname, path = nbm.named_notebook_path(notebook_path) | |
100 | if fname == None: |
|
121 | body = self.request.body.strip() | |
101 | body = self.request.body.strip() |
|
122 | format = self.get_argument('format', default='json') | |
102 |
|
|
123 | name = self.get_argument('name', default=None) | |
103 | name = self.get_argument('name', default=None) |
|
124 | if body: | |
104 | if body: |
|
125 | fname = nbm.save_new_notebook(body, notebook_path=path, name=name, format=format) | |
105 | fname = nbm.save_new_notebook(body, notebook_path=path, name=name, format=format) |
|
126 | else: | |
106 | else: |
|
127 | fname = nbm.new_notebook(notebook_path=path) | |
107 | fname = nbm.new_notebook(notebook_path=path) |
|
128 | self.set_header('Location', nbm.notebook_dir + path + fname) | |
108 | self.set_header('Location', nbm.notebook_dir + path + fname) |
|
129 | model = nbm.notebook_model(fname, path) | |
109 | model = nbm.notebook_model(fname, path) |
|
130 | self.finish(jsonapi.dumps(model)) | |
110 | self.finish(jsonapi.dumps(model)) |
|
131 | ||
111 | else: |
|
132 | @web.authenticated | |
112 | format = self.get_argument('format', default='json') |
|
133 | def put(self, notebook_path): | |
113 | name = self.get_argument('name', default=None) |
|
134 | """saves the notebook in the location given by 'notebook_path'.""" | |
114 | nbm.save_notebook(self.request.body, notebook_path=path, name=name, format=format) |
|
135 | nbm = self.notebook_manager | |
115 | model = nbm.notebook_model(fname, path) |
|
136 | name, path = nbm.named_notebook_path(notebook_path) | |
116 | self.set_status(204) |
|
137 | format = self.get_argument('format', default='json') | |
117 | self.finish(jsonapi.dumps(model)) |
|
138 | nbm.save_notebook(self.request.body, notebook_path=path, name=name, format=format) | |
|
139 | model = nbm.notebook_model(name, path) | |||
|
140 | self.set_status(204) | |||
|
141 | self.finish(jsonapi.dumps(model)) | |||
118 |
|
142 | |||
119 | @web.authenticated |
|
143 | @web.authenticated | |
120 | def delete(self, notebook_path): |
|
144 | def delete(self, notebook_path): | |
|
145 | """delete rmoves the notebook in the given notebook path""" | |||
121 | nbm = self.notebook_manager |
|
146 | nbm = self.notebook_manager | |
122 | name, path = nbm.named_notebook_path(notebook_path) |
|
147 | name, path = nbm.named_notebook_path(notebook_path) | |
123 | nbm.delete_notebook(name, path) |
|
148 | nbm.delete_notebook(name, path) |
@@ -73,10 +73,12 b' class NotebookManager(LoggingConfigurable):' | |||||
73 | return name, path |
|
73 | return name, path | |
74 |
|
74 | |||
75 | def url_encode(self, path): |
|
75 | def url_encode(self, path): | |
|
76 | """Returns the path with all special characters URL encoded""" | |||
76 | parts = os.path.split(path) |
|
77 | parts = os.path.split(path) | |
77 | return os.path.join(*[quote(p) for p in parts]) |
|
78 | return os.path.join(*[quote(p) for p in parts]) | |
78 |
|
79 | |||
79 | def url_decode(self, path): |
|
80 | def url_decode(self, path): | |
|
81 | """Returns the URL with special characters decoded""" | |||
80 | parts = os.path.split(path) |
|
82 | parts = os.path.split(path) | |
81 | return os.path.join(*[unquote(p) for p in parts]) |
|
83 | return os.path.join(*[unquote(p) for p in parts]) | |
82 |
|
84 | |||
@@ -156,7 +158,7 b' class NotebookManager(LoggingConfigurable):' | |||||
156 | """Get the object representation of a notebook by notebook_id.""" |
|
158 | """Get the object representation of a notebook by notebook_id.""" | |
157 | raise NotImplementedError('must be implemented in a subclass') |
|
159 | raise NotImplementedError('must be implemented in a subclass') | |
158 |
|
160 | |||
159 |
def save_new_notebook(self, data, notebook_path |
|
161 | def save_new_notebook(self, data, notebook_path=None, name=None, format=u'json'): | |
160 | """Save a new notebook and return its name. |
|
162 | """Save a new notebook and return its name. | |
161 |
|
163 | |||
162 | If a name is passed in, it overrides any values in the notebook data |
|
164 | If a name is passed in, it overrides any values in the notebook data | |
@@ -216,7 +218,7 b' class NotebookManager(LoggingConfigurable):' | |||||
216 | """ |
|
218 | """ | |
217 | return name |
|
219 | return name | |
218 |
|
220 | |||
219 |
def new_notebook(self, notebook_path= |
|
221 | def new_notebook(self, notebook_path='/'): | |
220 | """Create a new notebook and return its notebook_name.""" |
|
222 | """Create a new notebook and return its notebook_name.""" | |
221 | name = self.increment_filename('Untitled', notebook_path) |
|
223 | name = self.increment_filename('Untitled', notebook_path) | |
222 | metadata = current.new_metadata(name=name) |
|
224 | metadata = current.new_metadata(name=name) |
@@ -32,6 +32,7 b' class SessionRootHandler(IPythonHandler):' | |||||
32 |
|
32 | |||
33 | @web.authenticated |
|
33 | @web.authenticated | |
34 | def get(self): |
|
34 | def get(self): | |
|
35 | # Return a list of running sessions | |||
35 | sm = self.session_manager |
|
36 | sm = self.session_manager | |
36 | nbm = self.notebook_manager |
|
37 | nbm = self.notebook_manager | |
37 | km = self.kernel_manager |
|
38 | km = self.kernel_manager | |
@@ -40,11 +41,14 b' class SessionRootHandler(IPythonHandler):' | |||||
40 |
|
41 | |||
41 | @web.authenticated |
|
42 | @web.authenticated | |
42 | def post(self): |
|
43 | def post(self): | |
|
44 | # Creates a new session | |||
|
45 | #(unless a session already exists for the named nb) | |||
43 | sm = self.session_manager |
|
46 | sm = self.session_manager | |
44 | nbm = self.notebook_manager |
|
47 | nbm = self.notebook_manager | |
45 | km = self.kernel_manager |
|
48 | km = self.kernel_manager | |
46 | notebook_path = self.get_argument('notebook_path', default=None) |
|
49 | notebook_path = self.get_argument('notebook_path', default=None) | |
47 | name, path = nbm.named_notebook_path(notebook_path) |
|
50 | name, path = nbm.named_notebook_path(notebook_path) | |
|
51 | # Check to see if session exists | |||
48 | if sm.session_exists(name=name, path=path): |
|
52 | if sm.session_exists(name=name, path=path): | |
49 | model = sm.get_session(name=name, path=path) |
|
53 | model = sm.get_session(name=name, path=path) | |
50 | kernel_id = model['kernel']['id'] |
|
54 | kernel_id = model['kernel']['id'] | |
@@ -65,6 +69,7 b' class SessionHandler(IPythonHandler):' | |||||
65 |
|
69 | |||
66 | @web.authenticated |
|
70 | @web.authenticated | |
67 | def get(self, session_id): |
|
71 | def get(self, session_id): | |
|
72 | # Returns the JSON model for a single session | |||
68 | sm = self.session_manager |
|
73 | sm = self.session_manager | |
69 | model = sm.get_session(id=session_id) |
|
74 | model = sm.get_session(id=session_id) | |
70 | self.finish(jsonapi.dumps(model)) |
|
75 | self.finish(jsonapi.dumps(model)) | |
@@ -77,12 +82,13 b' class SessionHandler(IPythonHandler):' | |||||
77 | km = self.kernel_manager |
|
82 | km = self.kernel_manager | |
78 | notebook_path = self.request.body |
|
83 | notebook_path = self.request.body | |
79 | name, path = nbm.named_notebook_path(notebook_path) |
|
84 | name, path = nbm.named_notebook_path(notebook_path) | |
80 |
sm.update_session( |
|
85 | sm.update_session(session_id, name=name) | |
81 | model = sm.get_session(id=session_id) |
|
86 | model = sm.get_session(id=session_id) | |
82 | self.finish(jsonapi.dumps(model)) |
|
87 | self.finish(jsonapi.dumps(model)) | |
83 |
|
88 | |||
84 | @web.authenticated |
|
89 | @web.authenticated | |
85 | def delete(self, session_id): |
|
90 | def delete(self, session_id): | |
|
91 | # Deletes the session with given session_id | |||
86 | sm = self.session_manager |
|
92 | sm = self.session_manager | |
87 | nbm = self.notebook_manager |
|
93 | nbm = self.notebook_manager | |
88 | km = self.kernel_manager |
|
94 | km = self.kernel_manager |
General Comments 0
You need to be logged in to leave comments.
Login now