Show More
@@ -1,53 +1,52 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Contains writer for writing nbconvert output to PDF. |
|
2 | Contains writer for writing nbconvert output to PDF. | |
3 | """ |
|
3 | """ | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | #Copyright (c) 2013, the IPython Development Team. |
|
5 | #Copyright (c) 2013, the IPython Development Team. | |
6 | # |
|
6 | # | |
7 | #Distributed under the terms of the Modified BSD License. |
|
7 | #Distributed under the terms of the Modified BSD License. | |
8 | # |
|
8 | # | |
9 | #The full license is in the file COPYING.txt, distributed with this software. |
|
9 | #The full license is in the file COPYING.txt, distributed with this software. | |
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 |
|
11 | |||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | import subprocess |
|
16 | import subprocess | |
17 | import os |
|
17 | import os | |
18 | import shlex |
|
|||
19 |
|
18 | |||
20 |
from IPython.utils.traitlets import Integer, |
|
19 | from IPython.utils.traitlets import Integer, List, Bool | |
21 |
|
20 | |||
22 | from .base import PostProcessorBase |
|
21 | from .base import PostProcessorBase | |
23 |
|
22 | |||
24 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
25 | # Classes |
|
24 | # Classes | |
26 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
27 | class PDFPostProcessor(PostProcessorBase): |
|
26 | class PDFPostProcessor(PostProcessorBase): | |
28 | """Writer designed to write to PDF files""" |
|
27 | """Writer designed to write to PDF files""" | |
29 |
|
28 | |||
30 | iteration_count = Integer(3, config=True, help=""" |
|
29 | iteration_count = Integer(3, config=True, help=""" | |
31 | How many times pdflatex will be called. |
|
30 | How many times pdflatex will be called. | |
32 | """) |
|
31 | """) | |
33 |
|
32 | |||
34 |
compiler = |
|
33 | compiler = List(["pdflatex", "{filename}"], config=True, help=""" | |
35 | Shell command used to compile PDF.""") |
|
34 | Shell command used to compile PDF.""") | |
36 |
|
35 | |||
37 | verbose = Bool(False, config=True, help=""" |
|
36 | verbose = Bool(False, config=True, help=""" | |
38 | Whether or not to display the output of the compile call. |
|
37 | Whether or not to display the output of the compile call. | |
39 | """) |
|
38 | """) | |
40 |
|
39 | |||
41 | def call(self, input): |
|
40 | def call(self, input): | |
42 | """ |
|
41 | """ | |
43 | Consume and write Jinja output a PDF. |
|
42 | Consume and write Jinja output a PDF. | |
44 | See files.py for more... |
|
43 | See files.py for more... | |
45 | """ |
|
44 | """ | |
46 | command = self.compiler.format(shlex.quote(input)) |
|
45 | command = [c.format(filename=input) for c in self.compiler] | |
47 | self.log.info("Building PDF: `%s`", command) |
|
46 | self.log.info("Building PDF: `%s`", ' '.join(command)) | |
48 | for index in range(self.iteration_count): |
|
47 | for index in range(self.iteration_count): | |
49 | if self.verbose: |
|
48 | if self.verbose: | |
50 | subprocess.Popen(command, shell=True) |
|
49 | subprocess.Popen(command, shell=True) | |
51 | else: |
|
50 | else: | |
52 | with open(os.devnull, 'wb') as null: |
|
51 | with open(os.devnull, 'wb') as null: | |
53 | subprocess.Popen(command, shell=True, stdout=null) |
|
52 | subprocess.Popen(command, shell=True, stdout=null) |
General Comments 0
You need to be logged in to leave comments.
Login now