##// END OF EJS Templates
Merge pull request #3845 from martijnvermaat/nbconvert-fix-serve-dir...
Jonathan Frederic -
r11883:6bc8d9bf merge
parent child Browse files
Show More
@@ -19,7 +19,7 b' import webbrowser'
19 from BaseHTTPServer import HTTPServer
19 from BaseHTTPServer import HTTPServer
20 from SimpleHTTPServer import SimpleHTTPRequestHandler
20 from SimpleHTTPServer import SimpleHTTPRequestHandler
21
21
22 from IPython.utils.traitlets import Unicode, Bool
22 from IPython.utils.traitlets import Bool
23
23
24 from .base import PostProcessorBase
24 from .base import PostProcessorBase
25
25
@@ -30,28 +30,24 b' class ServePostProcessor(PostProcessorBase):'
30 """Post processor designed to serve files"""
30 """Post processor designed to serve files"""
31
31
32
32
33 build_directory = Unicode(".", config=True,
34 help="""Directory to write output to. Leave blank
35 to output to the current directory""")
36
37 open_in_browser = Bool(True, config=True,
33 open_in_browser = Bool(True, config=True,
38 help="""Set to False to deactivate
34 help="""Set to False to deactivate
39 the opening of the browser""")
35 the opening of the browser""")
40
36
41 def call(self, input):
37 def call(self, input):
42 """
38 """
43 Simple implementation to serve the build directory.
39 Simple implementation to serve the build directory.
44 """
40 """
45
41
46 try:
42 try:
47 os.chdir(self.build_directory)
43 dirname, filename = os.path.split(input)
44 os.chdir(dirname)
48 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
45 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
49 sa = httpd.socket.getsockname()
46 sa = httpd.socket.getsockname()
50 name = input[2:]
47 url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + filename
51 url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + name
52 if self.open_in_browser:
48 if self.open_in_browser:
53 webbrowser.open(url, new=2)
49 webbrowser.open(url, new=2)
54 print("Serving " + name + " on " + url)
50 print("Serving your slides on " + url)
55 print("Use Control-C to stop this server.")
51 print("Use Control-C to stop this server.")
56 httpd.serve_forever()
52 httpd.serve_forever()
57 except KeyboardInterrupt:
53 except KeyboardInterrupt:
General Comments 0
You need to be logged in to leave comments. Login now