def get_exporter(self, page): from zim.fs import File, Dir from zim.export import \ build_mhtml_file_exporter, \ build_single_file_exporter, \ build_page_exporter, \ build_notebook_exporter format = self.opts.get('format', 'html') if not 'output' in self.opts: raise UsageError(_('Output location needed for export') ) # T: error in export command output = Dir(self.opts['output']) if not output.isdir(): output = File(self.opts.get('output')) template = self.opts.get('template', 'Default') if output.exists() and not self.opts.get('overwrite'): if output.isdir(): if len(output.list()) > 0: raise Error( _('Output folder exists and not empty, specify "--overwrite" to force export' )) # T: error message for export else: pass else: raise Error( _('Output file exists, specify "--overwrite" to force export' )) # T: error message for export if format == 'mhtml': self.ignore_options('index-page') if output.isdir(): raise UsageError(_('Need output file to export MHTML') ) # T: error message for export exporter = build_mhtml_file_exporter( output, template, document_root_url=self.opts.get('root-url'), ) elif page: self.ignore_options('index-page') if output.exists() and output.isdir(): ext = 'html' output = output.file(page.basename) + '.' + ext if self.opts.get('singlefile'): exporter = build_single_file_exporter( output, format, template, namespace=page, document_root_url=self.opts.get('root-url'), ) else: exporter = build_page_exporter( output, format, template, page, document_root_url=self.opts.get('root-url'), ) else: if not output.exists(): output = Dir(output.path) elif not output.isdir(): raise UsageError( _('Need output folder to export full notebook') ) # T: error message for export exporter = build_notebook_exporter( output, format, template, index_page=self.opts.get('index-page'), document_root_url=self.opts.get('root-url'), ) return exporter
def get_exporter(self, page): from zim.fs import File, Dir from zim.export import \ build_mhtml_file_exporter, \ build_single_file_exporter, \ build_page_exporter, \ build_notebook_exporter format = self.opts.get('format', 'html') if not 'output' in self.opts: raise UsageError, _('Output location needed for export') # T: error in export command output = Dir(self.opts['output']) if not output.isdir(): output = File(self.opts.get('output')) template = self.opts.get('template', 'Default') if output.exists() and not self.opts.get('overwrite'): if output.isdir(): if len(output.list()) > 0: raise Error, _('Output folder exists and not empty, specify "--overwrite" to force export') # T: error message for export else: pass else: raise Error, _('Output file exists, specify "--overwrite" to force export') # T: error message for export if format == 'mhtml': self.ignore_options('index-page') if output.isdir(): raise UsageError, _('Need output file to export MHTML') # T: error message for export exporter = build_mhtml_file_exporter( output, template, document_root_url=self.opts.get('root-url'), ) elif page: self.ignore_options('index-page') if output.exists() and output.isdir(): ext = 'html' output = output.file(page.basename) + '.' + ext if self.opts.get('singlefile'): exporter = build_single_file_exporter( output, format, template, namespace=page, document_root_url=self.opts.get('root-url'), ) else: exporter = build_page_exporter( output, format, template, page, document_root_url=self.opts.get('root-url'), ) else: if not output.exists(): output = Dir(output.path) elif not output.isdir(): raise UsageError, _('Need output folder to export full notebook') # T: error message for export exporter = build_notebook_exporter( output, format, template, index_page=self.opts.get('index-page'), document_root_url=self.opts.get('root-url'), ) return exporter