Show More
@@ -17,6 +17,8 b' Command-line interface for the NbConvert conversion utility.' | |||||
17 |
|
17 | |||
18 | # Stdlib imports |
|
18 | # Stdlib imports | |
19 | from __future__ import print_function |
|
19 | from __future__ import print_function | |
|
20 | ||||
|
21 | import logging | |||
20 | import sys |
|
22 | import sys | |
21 | import os |
|
23 | import os | |
22 | import glob |
|
24 | import glob | |
@@ -80,6 +82,9 b' class NbConvertApp(BaseIPythonApplication):' | |||||
80 | aliases = nbconvert_aliases |
|
82 | aliases = nbconvert_aliases | |
81 | flags = nbconvert_flags |
|
83 | flags = nbconvert_flags | |
82 |
|
84 | |||
|
85 | def _log_level_default(self): | |||
|
86 | return logging.INFO | |||
|
87 | ||||
83 | def _classes_default(self): |
|
88 | def _classes_default(self): | |
84 | classes = [NbConvertBase] |
|
89 | classes = [NbConvertBase] | |
85 | for pkg in (exporters, transformers, writers): |
|
90 | for pkg in (exporters, transformers, writers): | |
@@ -273,6 +278,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
273 | self.exit(1) |
|
278 | self.exit(1) | |
274 |
|
279 | |||
275 | for notebook_filename in self.notebooks: |
|
280 | for notebook_filename in self.notebooks: | |
|
281 | self.log.info("Converting notebook %s to %s", notebook_filename, self.export_format) | |||
276 |
|
282 | |||
277 | # Get a unique key for the notebook and set it in the resources object. |
|
283 | # Get a unique key for the notebook and set it in the resources object. | |
278 | basename = os.path.basename(notebook_filename) |
|
284 | basename = os.path.basename(notebook_filename) | |
@@ -282,6 +288,7 b' class NbConvertApp(BaseIPythonApplication):' | |||||
282 | resources = {} |
|
288 | resources = {} | |
283 | resources['unique_key'] = notebook_name |
|
289 | resources['unique_key'] = notebook_name | |
284 | resources['output_files_dir'] = '%s_files' % notebook_name |
|
290 | resources['output_files_dir'] = '%s_files' % notebook_name | |
|
291 | self.log.debug("Writing extra files to %s", resources['output_files_dir']) | |||
285 |
|
292 | |||
286 | # Try to export |
|
293 | # Try to export | |
287 | try: |
|
294 | try: |
@@ -79,8 +79,9 b' class Transformer(NbConvertBase):' | |||||
79 | Additional resources used in the conversion process. Allows |
|
79 | Additional resources used in the conversion process. Allows | |
80 | transformers to pass variables into the Jinja engine. |
|
80 | transformers to pass variables into the Jinja engine. | |
81 | """ |
|
81 | """ | |
|
82 | self.log.debug("Applying transform: %s", self.__class__.__name__) | |||
82 | try : |
|
83 | try : | |
83 |
for worksheet in nb.worksheets |
|
84 | for worksheet in nb.worksheets: | |
84 | for index, cell in enumerate(worksheet.cells): |
|
85 | for index, cell in enumerate(worksheet.cells): | |
85 | worksheet.cells[index], resources = self.transform_cell(cell, resources, index) |
|
86 | worksheet.cells[index], resources = self.transform_cell(cell, resources, index) | |
86 | return nb, resources |
|
87 | return nb, resources |
@@ -12,13 +12,13 b'' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | from IPython.utils.traitlets import List |
|
14 | from IPython.utils.traitlets import List | |
15 | from IPython.config.configurable import Configurable |
|
15 | from IPython.config.configurable import LoggingConfigurable | |
16 |
|
16 | |||
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 | # Classes and functions |
|
18 | # Classes and functions | |
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 |
|
20 | |||
21 | class NbConvertBase(Configurable): |
|
21 | class NbConvertBase(LoggingConfigurable): | |
22 | """Global configurable class for shared config |
|
22 | """Global configurable class for shared config | |
23 |
|
23 | |||
24 | Usefull for display data priority that might be use by many trasnformers |
|
24 | Usefull for display data priority that might be use by many trasnformers |
@@ -45,7 +45,12 b' class FilesWriter(WriterBase):' | |||||
45 | super(FilesWriter, self).__init__(**kw) |
|
45 | super(FilesWriter, self).__init__(**kw) | |
46 | self._build_directory_changed('build_directory', self.build_directory, |
|
46 | self._build_directory_changed('build_directory', self.build_directory, | |
47 | self.build_directory) |
|
47 | self.build_directory) | |
48 |
|
48 | |||
|
49 | def _makedir(self, path): | |||
|
50 | """Make a directory if it doesn't already exist""" | |||
|
51 | if not os.path.isdir(path): | |||
|
52 | self.log.info("Making directory %s", path) | |||
|
53 | os.makedirs(path) | |||
49 |
|
54 | |||
50 | def write(self, output, resources, notebook_name=None, **kw): |
|
55 | def write(self, output, resources, notebook_name=None, **kw): | |
51 | """ |
|
56 | """ | |
@@ -67,10 +72,10 b' class FilesWriter(WriterBase):' | |||||
67 | # Determine where to write the file to |
|
72 | # Determine where to write the file to | |
68 | dest = os.path.join(self.build_directory, filename) |
|
73 | dest = os.path.join(self.build_directory, filename) | |
69 | path = os.path.dirname(dest) |
|
74 | path = os.path.dirname(dest) | |
70 |
|
|
75 | self._makedir(path) | |
71 | os.makedirs(path) |
|
|||
72 |
|
76 | |||
73 | # Write file |
|
77 | # Write file | |
|
78 | self.log.info("Writing support file %s", dest) | |||
74 | with io.open(dest, 'wb') as f: |
|
79 | with io.open(dest, 'wb') as f: | |
75 | f.write(data) |
|
80 | f.write(data) | |
76 |
|
81 | |||
@@ -84,11 +89,11 b' class FilesWriter(WriterBase):' | |||||
84 | # Make sure folder exists. |
|
89 | # Make sure folder exists. | |
85 | dest = os.path.join(self.build_directory, filename) |
|
90 | dest = os.path.join(self.build_directory, filename) | |
86 | path = os.path.dirname(dest) |
|
91 | path = os.path.dirname(dest) | |
87 |
|
|
92 | self._makedir(path) | |
88 | os.makedirs(path) |
|
|||
89 |
|
93 | |||
90 | # Copy if destination is different. |
|
94 | # Copy if destination is different. | |
91 | if not os.path.normpath(dest) == os.path.normpath(matching_filename): |
|
95 | if not os.path.normpath(dest) == os.path.normpath(matching_filename): | |
|
96 | self.log.info("Linking %s -> %s", matching_filename, dest) | |||
92 | link_or_copy(matching_filename, dest) |
|
97 | link_or_copy(matching_filename, dest) | |
93 |
|
98 | |||
94 | # Determine where to write conversion results. |
|
99 | # Determine where to write conversion results. | |
@@ -97,6 +102,7 b' class FilesWriter(WriterBase):' | |||||
97 | dest = os.path.join(self.build_directory, dest) |
|
102 | dest = os.path.join(self.build_directory, dest) | |
98 |
|
103 | |||
99 | # Write conversion results. |
|
104 | # Write conversion results. | |
|
105 | self.log.info("Writing %s", dest) | |||
100 | with io.open(dest, 'w') as f: |
|
106 | with io.open(dest, 'w') as f: | |
101 | f.write(output) |
|
107 | f.write(output) | |
102 | return dest No newline at end of file |
|
108 | return dest |
General Comments 0
You need to be logged in to leave comments.
Login now