##// END OF EJS Templates
remove wrong support file log message
MinRK -
Show More
@@ -1,108 +1,108
1 1 """
2 2 Contains writer for writing nbconvert output to filesystem.
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 io
17 17 import os
18 18 import glob
19 19
20 20 from IPython.utils.traitlets import Unicode
21 21 from IPython.utils.path import link_or_copy
22 22
23 23 from .base import WriterBase
24 24
25 25 #-----------------------------------------------------------------------------
26 26 # Classes
27 27 #-----------------------------------------------------------------------------
28 28
29 29 class FilesWriter(WriterBase):
30 30 """Consumes nbconvert output and produces files."""
31 31
32 32
33 33 build_directory = Unicode(".", config=True,
34 34 help="""Directory to write output to. Leave blank
35 35 to output to the current directory""")
36 36
37 37
38 38 # Make sure that the output directory exists.
39 39 def _build_directory_changed(self, name, old, new):
40 40 if new and not os.path.isdir(new):
41 41 os.makedirs(new)
42 42
43 43
44 44 def __init__(self, **kw):
45 45 super(FilesWriter, self).__init__(**kw)
46 46 self._build_directory_changed('build_directory', self.build_directory,
47 47 self.build_directory)
48 48
49 49 def _makedir(self, path):
50 50 """Make a directory if it doesn't already exist"""
51 51 if not os.path.isdir(path):
52 52 self.log.info("Making directory %s", path)
53 53 os.makedirs(path)
54 54
55 55 def write(self, output, resources, notebook_name=None, **kw):
56 56 """
57 57 Consume and write Jinja output to the file system. Output directory
58 58 is set via the 'build_directory' variable of this instance (a
59 59 configurable).
60 60
61 61 See base for more...
62 62 """
63 63
64 64 # Pull the extension and subdir from the resources dict.
65 65 output_extension = resources['output_extension']
66 66
67 67 # Write all of the extracted resources to the destination directory.
68 68 # NOTE: WE WRITE EVERYTHING AS-IF IT'S BINARY. THE EXTRACT FIG
69 69 # TRANSFORMER SHOULD HANDLE UNIX/WINDOWS LINE ENDINGS...
70 70 for filename, data in resources.get('outputs', {}).items():
71 71
72 72 # Determine where to write the file to
73 73 dest = os.path.join(self.build_directory, filename)
74 74 path = os.path.dirname(dest)
75 75 self._makedir(path)
76 76
77 77 # Write file
78 78 self.log.debug("Writing %i bytes to support file %s", len(data), dest)
79 79 with io.open(dest, 'wb') as f:
80 80 f.write(data)
81 81
82 82 # Copy referenced files to output directory
83 83 if self.build_directory:
84 84 for filename in self.files:
85 85
86 86 # Copy files that match search pattern
87 87 for matching_filename in glob.glob(filename):
88 88
89 89 # Make sure folder exists.
90 90 dest = os.path.join(self.build_directory, filename)
91 91 path = os.path.dirname(dest)
92 92 self._makedir(path)
93 93
94 94 # Copy if destination is different.
95 95 if not os.path.normpath(dest) == os.path.normpath(matching_filename):
96 96 self.log.info("Linking %s -> %s", matching_filename, dest)
97 97 link_or_copy(matching_filename, dest)
98 98
99 99 # Determine where to write conversion results.
100 100 dest = notebook_name + '.' + output_extension
101 101 if self.build_directory:
102 102 dest = os.path.join(self.build_directory, dest)
103 103
104 104 # Write conversion results.
105 self.log.info("Writing %i bytes to support file %s", len(output), dest)
105 self.log.info("Writing %i bytes to %s", len(output), dest)
106 106 with io.open(dest, 'w') as f:
107 107 f.write(output)
108 108 return dest No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now