##// END OF EJS Templates
Added serve option as a post processor.
damianavila -
Show More
@@ -0,0 +1,45 b''
1 """
2 Contains postprocessor for serving nbconvert output.
3 """
4 #-----------------------------------------------------------------------------
5 #Copyright (c) 2013, the IPython Development Team.
6 #
7 #Distributed under the terms of the Modified BSD License.
8 #
9 #The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
11
12 #-----------------------------------------------------------------------------
13 # Imports
14 #-----------------------------------------------------------------------------
15
16 import os
17 from BaseHTTPServer import HTTPServer
18 from SimpleHTTPServer import SimpleHTTPRequestHandler
19
20 from IPython.utils.traitlets import Unicode
21
22 from .base import PostProcessorBase
23
24 #-----------------------------------------------------------------------------
25 # Classes
26 #-----------------------------------------------------------------------------
27 class ServePostProcessor(PostProcessorBase):
28 """Post processor designed to serve files"""
29
30
31 build_directory = Unicode(".", config=True,
32 help="""Directory to write output to. Leave blank
33 to output to the current directory""")
34
35 def call(self, input):
36 """
37 Simple implementation to serve the build directory.
38 """
39
40 os.chdir(self.build_directory)
41 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
42 sa = httpd.socket.getsockname()
43 print("Serving '" + input + "' nbconverted from ipynb on http://" + sa[0] + ":" + str(sa[1]) + "/")
44 print("Use Control-C to stop this server.")
45 httpd.serve_forever()
@@ -162,7 +162,8 b' class NbConvertApp(BaseIPythonApplication):'
162 post_processor_class = DottedOrNone(config=True,
162 post_processor_class = DottedOrNone(config=True,
163 help="""PostProcessor class used to write the
163 help="""PostProcessor class used to write the
164 results of the conversion""")
164 results of the conversion""")
165 post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor'}
165 post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',
166 'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}
166 post_processor_factory = Type()
167 post_processor_factory = Type()
167
168
168 def _post_processor_class_changed(self, name, old, new):
169 def _post_processor_class_changed(self, name, old, new):
@@ -1,2 +1,3 b''
1 from .base import PostProcessorBase
1 from .base import PostProcessorBase
2 from .pdf import PDFPostProcessor
2 from .pdf import PDFPostProcessor
3 from .serve import ServePostProcessor
General Comments 0
You need to be logged in to leave comments. Login now