##// END OF EJS Templates
Merge pull request #3780 from damianavila/reveal_writer...
Jonathan Frederic -
r11829:c6497ff5 merge
parent child Browse files
Show More
@@ -0,0 +1,58 b''
1 """
2 Contains postprocessor for serving nbconvert output.
3 """
4 #-----------------------------------------------------------------------------
5 #Copyright (c) 2013, the IPython Development Team.
6 #
7 #Distributed under the terms of the Modified BSD License.
8 #
9 #The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
11
12 #-----------------------------------------------------------------------------
13 # Imports
14 #-----------------------------------------------------------------------------
15
16 import os
17 import webbrowser
18
19 from BaseHTTPServer import HTTPServer
20 from SimpleHTTPServer import SimpleHTTPRequestHandler
21
22 from IPython.utils.traitlets import Unicode, Bool
23
24 from .base import PostProcessorBase
25
26 #-----------------------------------------------------------------------------
27 # Classes
28 #-----------------------------------------------------------------------------
29 class ServePostProcessor(PostProcessorBase):
30 """Post processor designed to serve files"""
31
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,
38 help="""Set to False to deactivate
39 the opening of the browser""")
40
41 def call(self, input):
42 """
43 Simple implementation to serve the build directory.
44 """
45
46 try:
47 os.chdir(self.build_directory)
48 httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
49 sa = httpd.socket.getsockname()
50 name = input[2:]
51 url = "http://" + sa[0] + ":" + str(sa[1]) + "/" + name
52 if self.open_in_browser:
53 webbrowser.open(url, new=2)
54 print("Serving " + name + " on " + url)
55 print("Use Control-C to stop this server.")
56 httpd.serve_forever()
57 except KeyboardInterrupt:
58 print("The server is shut down.")
@@ -119,6 +119,10 b' class NbConvertApp(BaseIPythonApplication):'
119 119
120 120 > ipython nbconvert mynotebook.ipynb --to latex --post PDF
121 121
122 You can get (and serve) a Reveal.js-powered slideshow
123
124 > ipython nbconvert myslides.ipynb --to slides --post serve
125
122 126 Multiple notebooks can be given at the command line in a couple of
123 127 different ways:
124 128
@@ -157,7 +161,8 b' class NbConvertApp(BaseIPythonApplication):'
157 161 post_processor_class = DottedOrNone(config=True,
158 162 help="""PostProcessor class used to write the
159 163 results of the conversion""")
160 post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor'}
164 post_processor_aliases = {'PDF': 'IPython.nbconvert.post_processors.pdf.PDFPostProcessor',
165 'serve': 'IPython.nbconvert.post_processors.serve.ServePostProcessor'}
161 166 post_processor_factory = Type()
162 167
163 168 def _post_processor_class_changed(self, name, old, new):
@@ -293,7 +298,6 b' class NbConvertApp(BaseIPythonApplication):'
293 298 self.print_help()
294 299 sys.exit(-1)
295 300
296
297 301 #-----------------------------------------------------------------------------
298 302 # Main entry point
299 303 #-----------------------------------------------------------------------------
@@ -1,2 +1,3 b''
1 1 from .base import PostProcessorBase
2 2 from .pdf import PDFPostProcessor
3 from .serve import ServePostProcessor
1 NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now