diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 62cf7d3..240787e 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -162,7 +162,8 @@ class NbConvertApp(BaseIPythonApplication): post_processor_class = DottedOrNone(config=True, help="""PostProcessor class used to write the results of the conversion""") - post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor'} + post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor', + 'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'} post_processor_factory = Type() def _post_processor_class_changed(self, name, old, new): diff --git a/IPython/nbconvert/post_processors/__init__.py b/IPython/nbconvert/post_processors/__init__.py index 72c4819..6cae641 100644 --- a/IPython/nbconvert/post_processors/__init__.py +++ b/IPython/nbconvert/post_processors/__init__.py @@ -1,2 +1,3 @@ from .base import PostProcessorBase from .pdf import PDFPostProcessor +from .serve import ServePostProcessor diff --git a/IPython/nbconvert/post_processors/serve.py b/IPython/nbconvert/post_processors/serve.py new file mode 100644 index 0000000..022322f --- /dev/null +++ b/IPython/nbconvert/post_processors/serve.py @@ -0,0 +1,45 @@ +""" +Contains postprocessor for serving nbconvert output. +""" +#----------------------------------------------------------------------------- +#Copyright (c) 2013, the IPython Development Team. +# +#Distributed under the terms of the Modified BSD License. +# +#The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +from BaseHTTPServer import HTTPServer +from SimpleHTTPServer import SimpleHTTPRequestHandler + +from IPython.utils.traitlets import Unicode + +from .base import PostProcessorBase + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- +class ServePostProcessor(PostProcessorBase): + """Post processor designed to serve files""" + + + build_directory = Unicode(".", config=True, + help="""Directory to write output to. Leave blank + to output to the current directory""") + + def call(self, input): + """ + Simple implementation to serve the build directory. + """ + + os.chdir(self.build_directory) + httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) + sa = httpd.socket.getsockname() + print("Serving '" + input + "' nbconverted from ipynb on http://" + sa[0] + ":" + str(sa[1]) + "/") + print("Use Control-C to stop this server.") + httpd.serve_forever()