def write_file_if_different(data, out_path, mode="w"):
    """ Write the data to out_path if the content is different """
    try:
        with open(out_path, "r") as outr:
            out_prev = outr.read()
        if out_prev == data:
            ui.debug("skipping write to %s: same content" % (out_path))
            return
    except Exception:
        pass
    with open(out_path, mode) as out_file:
        out_file.write(data)