Show More
@@ -1,45 +1,48 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 | 17 | from BaseHTTPServer import HTTPServer |
|
18 | 18 | from SimpleHTTPServer import SimpleHTTPRequestHandler |
|
19 | 19 | |
|
20 | 20 | from IPython.utils.traitlets import Unicode |
|
21 | 21 | |
|
22 | 22 | from .base import PostProcessorBase |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Classes |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | class ServePostProcessor(PostProcessorBase): |
|
28 | 28 | """Post processor designed to serve files""" |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | build_directory = Unicode(".", config=True, |
|
32 | 32 | help="""Directory to write output to. Leave blank |
|
33 | 33 | to output to the current directory""") |
|
34 | 34 | |
|
35 | 35 | def call(self, input): |
|
36 | 36 | """ |
|
37 | 37 | Simple implementation to serve the build directory. |
|
38 | 38 | """ |
|
39 | 39 | |
|
40 | try: | |
|
40 | 41 | os.chdir(self.build_directory) |
|
41 | 42 | httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) |
|
42 | 43 | sa = httpd.socket.getsockname() |
|
43 |
print("Serving |
|
|
44 | print("Serving " + input[2:] + " on http://" + sa[0] + ":" + str(sa[1])) | |
|
44 | 45 | print("Use Control-C to stop this server.") |
|
45 | 46 | httpd.serve_forever() |
|
47 | except KeyboardInterrupt: | |
|
48 | print("The server is shut down.") |
General Comments 0
You need to be logged in to leave comments.
Login now