def _render_binaries(files, written_files):
    """Write binary contents from filetable into files.

    Using filetable for the input files, 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 source_path, target_path in files.items():
        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 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

        print("Writing rendered file %s" % target_path)
        LOG.info("Writing rendered file %s", target_path)

        shutil.copy(source_path, target_path)
        if os.path.exists(target_path):
            written_files.append(target_path)
Write binary contents from filetable into files.

    Using filetable for the input files, 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.