diff --git a/IPython/nbconvert/post_processors/serve.py b/IPython/nbconvert/post_processors/serve.py index 86e7dad..de16380 100644 --- a/IPython/nbconvert/post_processors/serve.py +++ b/IPython/nbconvert/post_processors/serve.py @@ -19,7 +19,7 @@ import webbrowser from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler -from IPython.utils.traitlets import Unicode, Bool +from IPython.utils.traitlets import Bool from .base import PostProcessorBase @@ -30,28 +30,24 @@ 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""") - open_in_browser = Bool(True, config=True, - help="""Set to False to deactivate + help="""Set to False to deactivate the opening of the browser""") def call(self, input): """ Simple implementation to serve the build directory. """ - + try: - os.chdir(self.build_directory) + dirname, filename = os.path.split(input) + os.chdir(dirname) httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) sa = httpd.socket.getsockname() - name = input[2:] - url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + name + url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + filename if self.open_in_browser: webbrowser.open(url, new=2) - print("Serving " + name + " on " + url) + print("Serving your slides on " + url) print("Use Control-C to stop this server.") httpd.serve_forever() except KeyboardInterrupt: