def __write_files(self): """Write all files for the blog to _site Convert all templates to straight HTML Copy other non-template files directly""" #find mako templates in template_dir for root, dirs, files in os.walk("."): if root.startswith("./"): root = root[2:] for d in list(dirs): #Exclude some dirs d_path = util.path_join(root,d) if util.should_ignore_path(d_path): logger.debug("Ignoring directory: " + d_path) dirs.remove(d) try: util.mkdir(util.path_join(self.output_dir, root)) except OSError: #pragma: no cover pass for t_fn in files: t_fn_path = util.path_join(root, t_fn) if util.should_ignore_path(t_fn_path): #Ignore this file. logger.debug("Ignoring file: " + t_fn_path) continue elif t_fn.endswith(".mako"): logger.info("Processing mako file: " + t_fn_path) #Process this template file t_name = t_fn[:-5] t_file = open(t_fn_path) template = Template(t_file.read().decode("utf-8"), output_encoding="utf-8", lookup=self.template_lookup) t_file.close() path = util.path_join(self.output_dir, root, t_name) html_file = open(path, "w") # Prepare the "path" variable for the template context. page_path = util.path_join(root, t_name) if page_path.startswith('./'): page_path = page_path[2:] page_path = '/' + page_path context = dict(path=page_path, logger=template_logger) #render the page html = self.template_render(template, context) #Write to disk html_file.write(html) else: #Copy this non-template file f_path = util.path_join(root, t_fn) logger.debug("Copying file: " + f_path) out_path = util.path_join(self.output_dir, f_path) if self.bf.config.site.use_hard_links: # Try hardlinking first, and if that fails copy try: os.link(f_path, out_path) except StandardError: shutil.copyfile(f_path, out_path) else: shutil.copyfile(f_path, out_path)
def __write_files(self): """Write all files for the blog to _site Convert all templates to straight HTML Copy other non-template files directly""" #find mako templates in template_dir for root, dirs, files in os.walk("."): if root.startswith("./"): root = root[2:] for d in list(dirs): #Exclude some dirs d_path = util.path_join(root, d) if util.should_ignore_path(d_path): logger.debug("Ignoring directory: " + d_path) dirs.remove(d) try: util.mkdir(util.path_join(self.output_dir, root)) except OSError: #pragma: no cover pass for t_fn in files: t_fn_path = util.path_join(root, t_fn) if util.should_ignore_path(t_fn_path): #Ignore this file. logger.debug("Ignoring file: " + t_fn_path) continue elif t_fn.endswith(".mako"): logger.info("Processing mako file: " + t_fn_path) #Process this template file t_name = t_fn[:-5] t_file = open(t_fn_path) template = Template(t_file.read().decode("utf-8"), output_encoding="utf-8", lookup=self.template_lookup) #Remember the original path for later when setting context template.bf_meta = {"path": t_fn_path} t_file.close() path = util.path_join(self.output_dir, root, t_name) html_file = open(path, "w") html = self.template_render(template) #Write to disk html_file.write(html) else: #Copy this non-template file f_path = util.path_join(root, t_fn) logger.debug("Copying file: " + f_path) out_path = util.path_join(self.output_dir, f_path) if self.config.site.overwrite_warning and os.path.exists( out_path): logger.warn( "Location is used more than once: {0}".format( f_path)) if self.bf.config.site.use_hard_links: # Try hardlinking first, and if that fails copy try: os.link(f_path, out_path) except StandardError: shutil.copyfile(f_path, out_path) else: shutil.copyfile(f_path, out_path)
def __write_files(self): """Write all files for the blog to _site Convert all templates to straight HTML Copy other non-template files directly""" #find mako templates in template_dir for root, dirs, files in os.walk(".", followlinks=True): if root.startswith("./"): root = root[2:] for d in list(dirs): #Exclude some dirs d_path = util.path_join(root,d) if util.should_ignore_path(d_path): logger.debug("Ignoring directory: " + d_path) dirs.remove(d) try: util.mkdir(util.path_join(self.output_dir, root)) except OSError: #pragma: no cover pass for t_fn in files: t_fn_path = util.path_join(root, t_fn) if util.should_ignore_path(t_fn_path): #Ignore this file. logger.debug("Ignoring file: " + t_fn_path) continue elif t_fn.endswith(".mako"): logger.info("Processing mako file: " + t_fn_path) #Process this template file t_name = t_fn[:-5] t_file = open(t_fn_path) template = Template(t_file.read().decode("utf-8"), output_encoding="utf-8", lookup=self.template_lookup) #Remember the original path for later when setting context template.bf_meta = {"path":t_fn_path} t_file.close() path = util.path_join(self.output_dir, root, t_name) html_file = open(path, "w") html = self.template_render(template) #Write to disk html_file.write(html) else: #Copy this non-template file f_path = util.path_join(root, t_fn) logger.debug("Copying file: " + f_path) out_path = util.path_join(self.output_dir, f_path) if self.config.site.overwrite_warning and os.path.exists(out_path): logger.warn("Location is used more than once: {0}".format(f_path)) if self.bf.config.site.use_hard_links: # Try hardlinking first, and if that fails copy try: os.link(f_path, out_path) except StandardError: shutil.copyfile(f_path, out_path) else: shutil.copyfile(f_path, out_path)
def __write_files(self, posts=None): """Write all files for the blog to _site Convert all templates to straight HTML Copy other non-template files directly""" #find mako templates in template_dir for root, dirs, files in os.walk("."): excluded_roots = [] if root.startswith("./"): root = root[2:] for d in list(dirs): #Exclude some dirs d_path = os.path.join(root,d) if util.should_ignore_path(d_path): logger.info("Ignoring directory : "+d_path) dirs.remove(d) try: util.mkdir(os.path.join(self.output_dir, root)) except OSError: pass for t_fn in files: t_fn_path = os.path.join(root,t_fn) if util.should_ignore_path(t_fn_path): #Ignore this file. logger.info("Ignoring file : "+t_fn_path) continue elif t_fn.endswith(".mako"): logger.info("Processing mako file: "+t_fn_path) #Process this template file t_name = t_fn[:-5] t_file = open(t_fn_path) template = Template(t_file.read().decode("utf-8"), output_encoding="utf-8", lookup=self.template_lookup) t_file.close() path = os.path.join(self.output_dir,root,t_name) html_file = open(path,"w") html = self.__template_render(template,{"posts":posts}) #Syntax highlighting if config.syntax_highlight_enabled: html = util.do_syntax_highlight(html,config) #Write to disk html_file.write(html) else: #Copy this non-template file f_path = os.path.join(root, t_fn) logger.info("Copying file : "+f_path) shutil.copyfile(f_path,os.path.join(self.output_dir,f_path))