Show More
@@ -1,52 +1,51 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Contains writer for writing nbconvert output to PDF. |
|
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 subprocess |
|
17 | 17 | import os |
|
18 | 18 | |
|
19 | 19 | from IPython.utils.traitlets import Integer, List, Bool |
|
20 | 20 | |
|
21 | 21 | from .base import PostProcessorBase |
|
22 | 22 | |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | # Classes |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | class PDFPostProcessor(PostProcessorBase): |
|
27 | 27 | """Writer designed to write to PDF files""" |
|
28 | 28 | |
|
29 | 29 | iteration_count = Integer(3, config=True, help=""" |
|
30 | 30 | How many times pdflatex will be called. |
|
31 | 31 | """) |
|
32 | 32 | |
|
33 | 33 | command = List(["pdflatex", "{filename}"], config=True, help=""" |
|
34 | 34 | Shell command used to compile PDF.""") |
|
35 | 35 | |
|
36 | 36 | verbose = Bool(False, config=True, help=""" |
|
37 | 37 | Whether or not to display the output of the compile call. |
|
38 | 38 | """) |
|
39 | 39 | |
|
40 | 40 | def call(self, input): |
|
41 | 41 | """ |
|
42 | 42 | Consume and write Jinja output a PDF. |
|
43 | 43 | See files.py for more... |
|
44 | 44 | """ |
|
45 | 45 | command = [c.format(filename=input) for c in self.command] |
|
46 | 46 | self.log.info("Building PDF: `%s`", ' '.join(command)) |
|
47 | for index in range(self.iteration_count): | |
|
48 |
if self.verbose |
|
|
49 | subprocess.Popen(command) | |
|
50 | else: | |
|
51 | with open(os.devnull, 'wb') as null: | |
|
52 | subprocess.Popen(command, stdout=null) | |
|
47 | with open(os.devnull, 'wb') as null: | |
|
48 | stdout = null if self.verbose else None | |
|
49 | for index in range(self.iteration_count): | |
|
50 | p = subprocess.Popen(command, stdout=stdout) | |
|
51 | p.wait() |
General Comments 0
You need to be logged in to leave comments.
Login now