##// END OF EJS Templates
Merge pull request #3780 from damianavila/reveal_writer...
Merge pull request #3780 from damianavila/reveal_writer Added serving the output directory if html-based format are selected.

File last commit:

r11807:5ee93c08
r11829:c6497ff5 merge
Show More
serve.py
58 lines | 2.1 KiB | text/x-python | PythonLexer
damianavila
Added serve option as a post processor.
r11773 """
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
damianavila
Added webbroser to auto open the slideshow.
r11804 import webbrowser
damianavila
Added serve option as a post processor.
r11773 from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
damianavila
Made open_in_browser configurable.
r11807 from IPython.utils.traitlets import Unicode, Bool
damianavila
Added serve option as a post processor.
r11773
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""")
damianavila
Made open_in_browser configurable.
r11807
open_in_browser = Bool(True, config=True,
help="""Set to False to deactivate
the opening of the browser""")
damianavila
Added serve option as a post processor.
r11773
def call(self, input):
"""
Simple implementation to serve the build directory.
"""
damianavila
Capturing Keyboard interrupt.
r11775 try:
os.chdir(self.build_directory)
httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
sa = httpd.socket.getsockname()
damianavila
Added webbroser to auto open the slideshow.
r11804 name = input[2:]
url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + name
damianavila
Made open_in_browser configurable.
r11807 if self.open_in_browser:
webbrowser.open(url, new=2)
damianavila
Added webbroser to auto open the slideshow.
r11804 print("Serving " + name + " on " + url)
damianavila
Capturing Keyboard interrupt.
r11775 print("Use Control-C to stop this server.")
httpd.serve_forever()
except KeyboardInterrupt:
print("The server is shut down.")