def test_output(tmpdir): # check if sys.stdout is diverting to file # this tests both open_output and close_output utils.output_dir = str(tmpdir) old_std = sys.stdout out = utils.open_output("test.txt", config=True) assert sys.stdout != old_std utils.close_output(out) assert sys.stdout == old_std
def index_dump( self, index_filename = None ): output = None if index_filename: output = utils.open_output( index_filename ) log.debug("Building index in %s.", index_filename ) self.index_enter() for name in self.block_index: self.index_name_enter( name ) self.index_name_exit( name ) self.index_exit() if output: utils.close_output( output )
def section_dump( self, section, section_filename = None ): output = None log.debug( "Building page %s.", section_filename ) if section_filename: output = utils.open_output( section_filename ) self.section_enter( section ) for name in section.block_names: skip_entry = 0 try: block = self.identifiers[name] # `block_names' can contain field names also, # which we filter out for markup in block.markups: if markup.tag == 'values': for field in markup.fields: if field.name == name: skip_entry = 1 except Exception: skip_entry = 1 # this happens e.g. for `/empty/' entries if skip_entry: continue self.block_enter( block ) for markup in block.markups[1:]: # always ignore first markup! self.markup_enter( markup, block ) for field in markup.fields: self.field_enter( field, markup, block ) self.field_exit( field, markup, block ) self.markup_exit( markup, block ) self.block_exit( block ) self.section_exit( section ) if output: utils.close_output( output )
def build_config(self): """Build the YAML configuration.""" # End chapter if started self.end_chapter() # Open yml file output = utils.open_output(config_filename, config=True) # Build basic site info self.build_site_config() order = ['site_name', 'site_author', 'docs_dir', 'site_dir'] self.write_config_order("Project information", order) # Build theme configuration self.build_theme_config() self.write_config("Configuration") # Build pages self.build_pages() self.write_config("Pages") # Build extra scripts build_extras() # Add extra CSS and Javascript self.populate_config(yml_extra) self.write_config("Customization") # Add Markdown extensions self.populate_config(md_extensions) self.write_config("Extensions") # Add other options self.populate_config(yml_other) self.write_config("Other Options") # Close the file utils.close_output(output)
def toc_dump( self, toc_filename = None, index_filename = None ): output = None if toc_filename: output = utils.open_output( toc_filename ) log.debug( "Building table of contents in %s.", toc_filename ) self.toc_enter() for chap in self.processor.chapters: self.toc_chapter_enter( chap ) for section in chap.sections: self.toc_section_enter( section ) self.toc_section_exit( section ) self.toc_chapter_exit( chap ) self.toc_index( index_filename ) self.toc_exit() if output: utils.close_output( output )