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