def export_index(self, index_page, pages): # TODO remove hack here, and get rid of IndexPage in current shape from Notebook if pages.prefix: indexpage = Page(pages.prefix + index_page) else: indexpage = Page(Path(index_page)) # Bit of a HACK here - need better support for these index pages _page = IndexPage(pages.notebook, pages.prefix) # TODO make more flexible - use pages iter itself indexpage.readonly = False indexpage.set_parsetree(_page.get_parsetree()) indexpage.readonly = True self.export_page(pages.notebook, indexpage, pages)
def export_all(self, dir, callback=None): '''Export all pages in the notebook Will also copy all attachments and created a folder with icons for checkboxes etc. So the resulting folder should contain all the notebook information. @param dir: a L{Dir} object for the target folder @param callback: a callback function that will be called after each page being exported with the page object as single argument. If the function returns C{False} the export is canceled. @returns: C{False} if the action was cancelled, C{True} otherwise ''' logger.info('Exporting notebook to %s', dir) self.linker.target_dir = dir # Needed to resolve icons # Copy icons for name in ('checked-box', 'unchecked-box', 'xchecked-box'): icon = data_file('pixmaps/%s.png' % name) file = dir.file('_resources/' + name + '.png') icon.copyto(file) # Copy template resources (can overwrite icons) if self.template and self.template.resources_dir \ and self.template.resources_dir.exists(): resources = dir.subdir('_resources') self.template.resources_dir.copyto(resources) # Set special pages if self.index_page: indexpage = Page(Path(self.index_page)) else: indexpage = None pages = { 'index': indexpage, 'home': self.notebook.get_home_page(), } # Export the pages prev, current, next = None, None, None for page in self.notebook.walk(): if page.hascontent: prev, current, next = current, next, page # shift if current: pages['previous'] = prev pages['next'] = next self.export_page(dir, current, pages, use_namespace=True) if callback and not callback(current): logger.warn('Export canceled') return False prev, current, next = current, next, None # shift once more if current: pages['previous'] = prev pages['next'] = next self.export_page(dir, current, pages, use_namespace=True) if callback and not callback(current): logger.warn('Export canceled') return False # Generate index page if indexpage: _page = IndexPage(self.notebook, Path(':')) # Bit of a HACK here - need better support for these index pages indexpage.readonly = False indexpage.set_parsetree(_page.get_parsetree()) indexpage.readonly = True self.export_page(dir, indexpage, use_namespace=True) self.linker.target_dir = None # reset logger.info('Export done') return True