Show More
@@ -1,6 +1,8 | |||||
|
1 | import datetime | |||
1 | import json |
|
2 | import json | |
2 | import logging |
|
3 | import logging | |
3 | import os |
|
4 | import os | |
|
5 | import urllib | |||
4 |
|
6 | |||
5 | import zmq |
|
7 | import zmq | |
6 |
|
8 | |||
@@ -103,6 +105,53 class ShellStreamHandler(ZMQStreamHandler): | |||||
103 | stream_name = 'shell' |
|
105 | stream_name = 'shell' | |
104 |
|
106 | |||
105 |
|
107 | |||
|
108 | class NotebookRootHandler(web.RequestHandler): | |||
|
109 | ||||
|
110 | def get(self): | |||
|
111 | files = os.listdir(os.getcwd()) | |||
|
112 | files = [file for file in files if file.endswith(".nb")] | |||
|
113 | self.write(json.dumps(files)) | |||
|
114 | ||||
|
115 | ||||
|
116 | class NotebookHandler(web.RequestHandler): | |||
|
117 | ||||
|
118 | SUPPORTED_METHODS = ("GET", "DELETE", "PUT") | |||
|
119 | ||||
|
120 | def find_path(self, filename): | |||
|
121 | filename = urllib.unquote(filename) + ".nb" | |||
|
122 | path = os.path.join(os.getcwd(), filename) | |||
|
123 | return path | |||
|
124 | ||||
|
125 | def get(self, filename): | |||
|
126 | path = self.find_path(filename) | |||
|
127 | if not os.path.isfile(path): | |||
|
128 | raise web.HTTPError(404) | |||
|
129 | info = os.stat(path) | |||
|
130 | self.set_header("Content-Type", "application/unknown") | |||
|
131 | self.set_header("Last-Modified", datetime.datetime.utcfromtimestamp( | |||
|
132 | info.st_mtime)) | |||
|
133 | f = open(path, "r") | |||
|
134 | try: | |||
|
135 | self.finish(f.read()) | |||
|
136 | finally: | |||
|
137 | f.close() | |||
|
138 | ||||
|
139 | def put(self, filename): | |||
|
140 | path = self.find_path(filename) | |||
|
141 | f = open(path, "w") | |||
|
142 | f.write(self.request.body) | |||
|
143 | f.close() | |||
|
144 | self.finish() | |||
|
145 | ||||
|
146 | def delete(self, filename): | |||
|
147 | path = self.find_path(filename) | |||
|
148 | if not os.path.isfile(path): | |||
|
149 | raise web.HTTPError(404) | |||
|
150 | os.unlink(path) | |||
|
151 | self.set_status(204) | |||
|
152 | self.finish() | |||
|
153 | ||||
|
154 | ||||
106 | class NotebookApplication(web.Application): |
|
155 | class NotebookApplication(web.Application): | |
107 |
|
156 | |||
108 | def __init__(self): |
|
157 | def __init__(self): | |
@@ -112,6 +161,8 class NotebookApplication(web.Application): | |||||
112 | (r"/kernels/%s/sessions" % (_kernel_id_regex,), SessionHandler), |
|
161 | (r"/kernels/%s/sessions" % (_kernel_id_regex,), SessionHandler), | |
113 | (r"/kernels/%s/sessions/%s/iopub" % (_kernel_id_regex,_session_id_regex), IOPubStreamHandler), |
|
162 | (r"/kernels/%s/sessions/%s/iopub" % (_kernel_id_regex,_session_id_regex), IOPubStreamHandler), | |
114 | (r"/kernels/%s/sessions/%s/shell" % (_kernel_id_regex,_session_id_regex), ShellStreamHandler), |
|
163 | (r"/kernels/%s/sessions/%s/shell" % (_kernel_id_regex,_session_id_regex), ShellStreamHandler), | |
|
164 | (r"/notebooks", NotebookRootHandler), | |||
|
165 | (r"/notebooks/([^/]+)", NotebookHandler) | |||
115 | ] |
|
166 | ] | |
116 | settings = dict( |
|
167 | settings = dict( | |
117 | template_path=os.path.join(os.path.dirname(__file__), "templates"), |
|
168 | template_path=os.path.join(os.path.dirname(__file__), "templates"), |
@@ -1,6 +1,26 | |||||
1 | var IPYTHON = {}; |
|
1 | var IPYTHON = {}; | |
2 |
|
2 | |||
3 |
|
3 | |||
|
4 | ||||
|
5 | // $.get("/notebooks/number2.nb",function (data, status, xhr) {console.log(data);}); | |||
|
6 | // | |||
|
7 | // settings = { | |||
|
8 | // processData : false, | |||
|
9 | // cache : false, | |||
|
10 | // type : "DELETE", | |||
|
11 | // success : function (data, status, xhr) {console.log(data);} | |||
|
12 | // } | |||
|
13 | // $.ajax("/notebooks/number2.nb",settings) | |||
|
14 | // | |||
|
15 | // settings = { | |||
|
16 | // processData : false, | |||
|
17 | // cache : false, | |||
|
18 | // type : "PUT", | |||
|
19 | // success : function (data, status, xhr) {console.log(data);} | |||
|
20 | // } | |||
|
21 | // $.ajax("/notebooks/number2.nb",settings) | |||
|
22 | ||||
|
23 | ||||
4 | //============================================================================ |
|
24 | //============================================================================ | |
5 | // Utilities |
|
25 | // Utilities | |
6 | //============================================================================ |
|
26 | //============================================================================ |
@@ -8,9 +8,8 | |||||
8 | <link rel="stylesheet" href="static/css/notebook.css" type="text/css" /> |
|
8 | <link rel="stylesheet" href="static/css/notebook.css" type="text/css" /> | |
9 | <link rel="stylesheet" href="static/jquery/css/jquery.wijmo-open.1.1.3.css" type="text/css" /> |
|
9 | <link rel="stylesheet" href="static/jquery/css/jquery.wijmo-open.1.1.3.css" type="text/css" /> | |
10 | <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" /> |
|
10 | <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" /> | |
11 | <!-- <link rel="stylesheet" href="static/jquery/css/themes/ui-lightness/jquery-ui-1.8.10.custom.css" type="text/css" /> --> |
|
|||
12 | <!-- <script src="static/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript" charset="utf-8"></script> --> |
|
|||
13 | <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script> |
|
11 | <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script> | |
|
12 | ||||
14 | </head> |
|
13 | </head> | |
15 |
|
14 | |||
16 | <body> |
|
15 | <body> | |
@@ -83,6 +82,7 | |||||
83 | <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script> |
|
82 | <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script> | |
84 | <script src="static/jquery/js/jquery.wijmo-open.1.1.3.min.js" type="text/javascript" charset="utf-8"></script> |
|
83 | <script src="static/jquery/js/jquery.wijmo-open.1.1.3.min.js" type="text/javascript" charset="utf-8"></script> | |
85 | <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script> |
|
84 | <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script> | |
|
85 | ||||
86 | </body> |
|
86 | </body> | |
87 |
|
87 | |||
88 | </html> No newline at end of file |
|
88 | </html> |
General Comments 0
You need to be logged in to leave comments.
Login now