##// END OF EJS Templates
Added webbroser to auto open the slideshow.
damianavila -
Show More
@@ -1,48 +1,53 b''
1 1 """
2 2 Contains postprocessor for serving nbconvert output.
3 3 """
4 4 #-----------------------------------------------------------------------------
5 5 #Copyright (c) 2013, the IPython Development Team.
6 6 #
7 7 #Distributed under the terms of the Modified BSD License.
8 8 #
9 9 #The full license is in the file COPYING.txt, distributed with this software.
10 10 #-----------------------------------------------------------------------------
11 11
12 12 #-----------------------------------------------------------------------------
13 13 # Imports
14 14 #-----------------------------------------------------------------------------
15 15
16 16 import os
17 import webbrowser
18
17 19 from BaseHTTPServer import HTTPServer
18 20 from SimpleHTTPServer import SimpleHTTPRequestHandler
19 21
20 22 from IPython.utils.traitlets import Unicode
21 23
22 24 from .base import PostProcessorBase
23 25
24 26 #-----------------------------------------------------------------------------
25 27 # Classes
26 28 #-----------------------------------------------------------------------------
27 29 class ServePostProcessor(PostProcessorBase):
28 30 """Post processor designed to serve files"""
29 31
30 32
31 33 build_directory = Unicode(".", config=True,
32 34 help="""Directory to write output to. Leave blank
33 35 to output to the current directory""")
34 36
35 37 def call(self, input):
36 38 """
37 39 Simple implementation to serve the build directory.
38 40 """
39 41
40 42 try:
41 43 os.chdir(self.build_directory)
42 44 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
43 45 sa = httpd.socket.getsockname()
44 print("Serving " + input[2:] + " on http://" + sa[0] + ":" + str(sa[1]))
46 name = input[2:]
47 url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + name
48 webbrowser.open(url, new=2)
49 print("Serving " + name + " on " + url)
45 50 print("Use Control-C to stop this server.")
46 51 httpd.serve_forever()
47 52 except KeyboardInterrupt:
48 53 print("The server is shut down.")
General Comments 0
You need to be logged in to leave comments. Login now