docs: def _render_templates(files, filetable, written_files, force, open_mode='w'):
      """Write template contents from filetable into files.
  
      Using filetable for the rendered templates, and the list of files, render
      all the templates into actual files on disk, forcing to overwrite the file
      as appropriate, and using the given open mode for the file.
      """
      for tpl_path, content in filetable:
          target_path = files[tpl_path]
          needdir = os.path.dirname(target_path)
          assert needdir, "Target should have valid parent dir"
          try:
              os.makedirs(needdir)
          except OSError as err:
              if err.errno != errno.EEXIST:
                  raise
  
          if os.path.isfile(target_path):
              if force:
                  LOG.warning("Forcing overwrite of existing file %s.",
                              target_path)
              elif target_path in written_files:
                  LOG.warning("Previous stencil has already written file %s.",
                              target_path)
              else:
                  print("Skipping existing file %s" % target_path)
                  LOG.info("Skipping existing file %s", target_path)
                  continue
  
          with open(target_path, open_mode) as newfile:
              print("Writing rendered file %s" % target_path)
              LOG.info("Writing rendered file %s", target_path)
              newfile.write(content)
              written_files.append(target_path)