##// END OF EJS Templates
Redo after corrupted codebase.
damianavila -
Show More
@@ -0,0 +1,44 b''
1 #!/usr/bin/env python
2 """
3 Contains writer for writing nbconvert output to filesystem.
4 """
5 #-----------------------------------------------------------------------------
6 #Copyright (c) 2013, the IPython Development Team.
7 #
8 #Distributed under the terms of the Modified BSD License.
9 #
10 #The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 import os
18
19 from BaseHTTPServer import HTTPServer
20 from SimpleHTTPServer import SimpleHTTPRequestHandler
21
22 from .files import FilesWriter
23
24 #-----------------------------------------------------------------------------
25 # Classes
26 #-----------------------------------------------------------------------------
27
28 class ServeWriter(FilesWriter):
29 """
30 Consumes nbconvert output and produces files (inherited from FilesWriter).
31 Then serve the build directory containing the nbconverted files.
32 """
33
34 def serve(self, format):
35 """
36 Simple implementation to serve the build directory.
37 """
38
39 os.chdir(self.build_directory)
40 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
41 sa = httpd.socket.getsockname()
42 print("Serving '" + format + "' nbconverted ipynb on http://" + sa[0] + ":" + str(sa[1]) + "/")
43 print("Use Control-C to stop this server.")
44 httpd.serve_forever() No newline at end of file
@@ -67,6 +67,10 b' nbconvert_flags.update({'
67 'stdout' : (
67 'stdout' : (
68 {'NbConvertApp' : {'writer_class' : "StdoutWriter"}},
68 {'NbConvertApp' : {'writer_class' : "StdoutWriter"}},
69 "Write notebook output to stdout instead of files."
69 "Write notebook output to stdout instead of files."
70 ),
71 'serve' : (
72 {'NbConvertApp' : {'writer_class' : "ServeWriter"}},
73 "Write notebook to a file and serve it."
70 )
74 )
71 })
75 })
72
76
@@ -141,7 +145,8 b' class NbConvertApp(BaseIPythonApplication):'
141 results of the conversion""")
145 results of the conversion""")
142 writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
146 writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
143 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',
147 'DebugWriter': 'IPython.nbconvert.writers.debug.DebugWriter',
144 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter'}
148 'StdoutWriter': 'IPython.nbconvert.writers.stdout.StdoutWriter',
149 'ServeWriter': 'IPython.nbconvert.writers.serve.ServeWriter'}
145 writer_factory = Type()
150 writer_factory = Type()
146
151
147 def _writer_class_changed(self, name, old, new):
152 def _writer_class_changed(self, name, old, new):
@@ -246,6 +251,7 b' class NbConvertApp(BaseIPythonApplication):'
246 """
251 """
247 super(NbConvertApp, self).start()
252 super(NbConvertApp, self).start()
248 self.convert_notebooks()
253 self.convert_notebooks()
254 self.serve_files()
249
255
250 def convert_notebooks(self):
256 def convert_notebooks(self):
251 """
257 """
@@ -292,7 +298,12 b' class NbConvertApp(BaseIPythonApplication):'
292 if conversion_success == 0:
298 if conversion_success == 0:
293 self.print_help()
299 self.print_help()
294 sys.exit(-1)
300 sys.exit(-1)
295
301
302 def serve_files(self):
303 """
304 Serve the resulting files arter nbconversion.
305 """
306 self.writer.serve(self.export_format)
296
307
297 #-----------------------------------------------------------------------------
308 #-----------------------------------------------------------------------------
298 # Main entry point
309 # Main entry point
@@ -99,4 +99,11 b' class FilesWriter(WriterBase):'
99 # Write conversion results.
99 # Write conversion results.
100 with io.open(dest, 'w') as f:
100 with io.open(dest, 'w') as f:
101 f.write(output)
101 f.write(output)
102 return dest No newline at end of file
102 return dest
103
104
105 def serve(self, format):
106 """
107 Not implemented function to serve the build directory.
108 """
109 pass No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now