def safe_copy(src, dest):
    """
    Copy a source file to a destination but
    do not overwrite dest if it is more recent than src
    Create any missing directories when necessary
    If dest is a directory, src will be copied inside dest.
    """
    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))
    if not up_to_date(dest, src):
        shutil.copy(src, dest)