##// END OF EJS Templates
allow notebook to start without nbconvert...
MinRK -
Show More
@@ -6,7 +6,7 b' from tornado import web'
6
6
7 from ..base.handlers import IPythonHandler, notebook_path_regex
7 from ..base.handlers import IPythonHandler, notebook_path_regex
8 from IPython.nbformat.current import to_notebook_json
8 from IPython.nbformat.current import to_notebook_json
9 from IPython.nbconvert.exporters.export import exporter_map
9
10 from IPython.utils import tz
10 from IPython.utils import tz
11 from IPython.utils.py3compat import cast_bytes
11 from IPython.utils.py3compat import cast_bytes
12
12
@@ -47,13 +47,30 b' def respond_zip(handler, name, output, resources):'
47 handler.finish(buffer.getvalue())
47 handler.finish(buffer.getvalue())
48 return True
48 return True
49
49
50 def get_exporter(format, **kwargs):
51 """get an exporter, raising appropriate errors"""
52 # if this fails, will raise 500
53 try:
54 from IPython.nbconvert.exporters.export import exporter_map
55 except ImportError as e:
56 raise web.HTTPError(500, "Could not import nbconvert: %s" % e)
57
58 try:
59 Exporter = exporter_map[format]
60 except KeyError:
61 # should this be 400?
62 raise web.HTTPError(404, u"No exporter for format: %s" % format)
63
64 return Exporter(**kwargs)
65
50 class NbconvertFileHandler(IPythonHandler):
66 class NbconvertFileHandler(IPythonHandler):
51
67
52 SUPPORTED_METHODS = ('GET',)
68 SUPPORTED_METHODS = ('GET',)
53
69
54 @web.authenticated
70 @web.authenticated
55 def get(self, format, path='', name=None):
71 def get(self, format, path='', name=None):
56 exporter = exporter_map[format](config=self.config)
72
73 exporter = get_exporter(format, config=self.config)
57
74
58 path = path.strip('/')
75 path = path.strip('/')
59 os_path = self.notebook_manager.get_os_path(name, path)
76 os_path = self.notebook_manager.get_os_path(name, path)
@@ -89,7 +106,7 b' class NbconvertPostHandler(IPythonHandler):'
89
106
90 @web.authenticated
107 @web.authenticated
91 def post(self, format):
108 def post(self, format):
92 exporter = exporter_map[format](config=self.config)
109 exporter = get_exporter(format, config=self.config)
93
110
94 model = self.get_json_body()
111 model = self.get_json_body()
95 nbnode = to_notebook_json(model['content'])
112 nbnode = to_notebook_json(model['content'])
@@ -3,7 +3,10 b' import json'
3 from tornado import web
3 from tornado import web
4
4
5 from ...base.handlers import IPythonHandler, json_errors
5 from ...base.handlers import IPythonHandler, json_errors
6 from IPython.nbconvert.exporters.export import exporter_map
6 try:
7 from IPython.nbconvert.exporters.export import exporter_map
8 except ImportError:
9 exporter_map = {}
7
10
8 class NbconvertRootHandler(IPythonHandler):
11 class NbconvertRootHandler(IPythonHandler):
9 SUPPORTED_METHODS = ('GET',)
12 SUPPORTED_METHODS = ('GET',)
General Comments 0
You need to be logged in to leave comments. Login now