##// END OF EJS Templates
Add the . into file_extension
Thomas Kluyver -
Show More
@@ -43,7 +43,7 b' def respond_zip(handler, name, output, resources):'
43 # Prepare the zip file
43 # Prepare the zip file
44 buffer = io.BytesIO()
44 buffer = io.BytesIO()
45 zipf = zipfile.ZipFile(buffer, mode='w', compression=zipfile.ZIP_DEFLATED)
45 zipf = zipfile.ZipFile(buffer, mode='w', compression=zipfile.ZIP_DEFLATED)
46 output_filename = os.path.splitext(name)[0] + '.' + resources['output_extension']
46 output_filename = os.path.splitext(name)[0] + resources['output_extension']
47 zipf.writestr(output_filename, cast_bytes(output, 'utf-8'))
47 zipf.writestr(output_filename, cast_bytes(output, 'utf-8'))
48 for filename, data in output_files.items():
48 for filename, data in output_files.items():
49 zipf.writestr(os.path.basename(filename), data)
49 zipf.writestr(os.path.basename(filename), data)
@@ -96,7 +96,7 b' class NbconvertFileHandler(IPythonHandler):'
96
96
97 # Force download if requested
97 # Force download if requested
98 if self.get_argument('download', 'false').lower() == 'true':
98 if self.get_argument('download', 'false').lower() == 'true':
99 filename = os.path.splitext(name)[0] + '.' + resources['output_extension']
99 filename = os.path.splitext(name)[0] + resources['output_extension']
100 self.set_header('Content-Disposition',
100 self.set_header('Content-Disposition',
101 'attachment; filename="%s"' % filename)
101 'attachment; filename="%s"' % filename)
102
102
@@ -359,7 +359,7 b' define(['
359 // Set menu entry text to e.g. "Python (.py)"
359 // Set menu entry text to e.g. "Python (.py)"
360 var langname = (langinfo.name || 'Script')
360 var langname = (langinfo.name || 'Script')
361 langname = langname.charAt(0).toUpperCase()+langname.substr(1) // Capitalise
361 langname = langname.charAt(0).toUpperCase()+langname.substr(1) // Capitalise
362 el.find('a').text(langname + ' (.'+(langinfo.file_extension || 'txt')+')');
362 el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')');
363
363
364 // Unregister any previously registered handlers
364 // Unregister any previously registered handlers
365 el.off('click');
365 el.off('click');
@@ -76,7 +76,7 b' class IPythonKernel(KernelBase):'
76 'version': sys.version_info[0]},
76 'version': sys.version_info[0]},
77 'pygments_lexer': 'ipython%d' % (3 if PY3 else 2),
77 'pygments_lexer': 'ipython%d' % (3 if PY3 else 2),
78 'nbconvert_exporter': 'python',
78 'nbconvert_exporter': 'python',
79 'file_extension': 'py'
79 'file_extension': '.py'
80 }
80 }
81 @property
81 @property
82 def banner(self):
82 def banner(self):
@@ -32,7 +32,7 b' class Exporter(LoggingConfigurable):'
32 """
32 """
33
33
34 file_extension = Unicode(
34 file_extension = Unicode(
35 'txt', config=True,
35 '.txt', config=True,
36 help="Extension of the file that should be written to disk"
36 help="Extension of the file that should be written to disk"
37 )
37 )
38
38
@@ -32,7 +32,7 b' class HTMLExporter(TemplateExporter):'
32 """
32 """
33
33
34 def _file_extension_default(self):
34 def _file_extension_default(self):
35 return 'html'
35 return '.html'
36
36
37 def _default_template_path_default(self):
37 def _default_template_path_default(self):
38 return os.path.join("..", "templates", "html")
38 return os.path.join("..", "templates", "html")
@@ -135,7 +135,7 b' class PDFExporter(LatexExporter):'
135
135
136 # convert output extension to pdf
136 # convert output extension to pdf
137 # the writer above required it to be tex
137 # the writer above required it to be tex
138 resources['output_extension'] = 'pdf'
138 resources['output_extension'] = '.pdf'
139
139
140 return pdf_data, resources
140 return pdf_data, resources
141
141
@@ -23,7 +23,7 b' class PythonExporter(TemplateExporter):'
23 Exports a Python code file.
23 Exports a Python code file.
24 """
24 """
25 def _file_extension_default(self):
25 def _file_extension_default(self):
26 return 'py'
26 return '.py'
27
27
28 def _template_file_default(self):
28 def _template_file_default(self):
29 return 'python'
29 return 'python'
@@ -26,7 +26,7 b' class RSTExporter(TemplateExporter):'
26 """
26 """
27
27
28 def _file_extension_default(self):
28 def _file_extension_default(self):
29 return 'rst'
29 return '.rst'
30
30
31 def _template_file_default(self):
31 def _template_file_default(self):
32 return 'rst'
32 return 'rst'
@@ -8,7 +8,7 b' class ScriptExporter(TemplateExporter):'
8
8
9 def from_notebook_node(self, nb, resources=None, **kw):
9 def from_notebook_node(self, nb, resources=None, **kw):
10 langinfo = nb.metadata.get('language_info', {})
10 langinfo = nb.metadata.get('language_info', {})
11 self.file_extension = langinfo.get('file_extension', 'txt')
11 self.file_extension = langinfo.get('file_extension', '.txt')
12 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
12 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
13
13
14 return super(ScriptExporter, self).from_notebook_node(nb, resources, **kw)
14 return super(ScriptExporter, self).from_notebook_node(nb, resources, **kw)
@@ -286,7 +286,7 b' class NbConvertApp(BaseIPythonApplication):'
286 # strip duplicate extension from output_base, to avoid Basname.ext.ext
286 # strip duplicate extension from output_base, to avoid Basname.ext.ext
287 if getattr(exporter, 'file_extension', False):
287 if getattr(exporter, 'file_extension', False):
288 base, ext = os.path.splitext(self.output_base)
288 base, ext = os.path.splitext(self.output_base)
289 if ext == '.' + exporter.file_extension:
289 if ext == exporter.file_extension:
290 self.output_base = base
290 self.output_base = base
291 notebook_name = self.output_base
291 notebook_name = self.output_base
292 resources = {}
292 resources = {}
@@ -93,7 +93,7 b' class FilesWriter(WriterBase):'
93
93
94 # Determine where to write conversion results.
94 # Determine where to write conversion results.
95 if output_extension is not None:
95 if output_extension is not None:
96 dest = notebook_name + '.' + output_extension
96 dest = notebook_name + output_extension
97 else:
97 else:
98 dest = notebook_name
98 dest = notebook_name
99 if self.build_directory:
99 if self.build_directory:
@@ -59,7 +59,7 b' class Testfiles(TestsBase):'
59 with self.create_temp_cwd():
59 with self.create_temp_cwd():
60
60
61 # Create the resoruces dictionary
61 # Create the resoruces dictionary
62 res = {'output_extension': 'txt'}
62 res = {'output_extension': '.txt'}
63
63
64 # Create files writer, test output
64 # Create files writer, test output
65 writer = FilesWriter()
65 writer = FilesWriter()
General Comments 0
You need to be logged in to leave comments. Login now