def override_existing_buildspec()

in src/prepare_dlc_dev_environment.py [0:0]


def override_existing_buildspec(buildspec_path):
    """
    Override the autopatch_build and build_tag_override tags in an existing buildspec file.
    """
    full_path = validate_buildspec_path(buildspec_path)
    if not full_path:
        return

    with open(full_path, "r") as file:
        content = file.readlines()

    build_tag_override_found = any("# build_tag_override:" in line for line in content)

    if build_tag_override_found:
        updated_content = []

        for line in content:
            if line.strip().startswith("# build_tag_override:"):
                updated_line = uncomment_build_tag_override_line(line)
            elif line.strip().startswith("autopatch_build"):
                updated_line = f"# {line}"
            else:
                updated_line = line

            updated_content.append(updated_line)

        with open(full_path, "w") as file:
            file.writelines(updated_content)
        LOGGER.info(f"Updated {buildspec_path}")
    else:
        LOGGER.warning(
            f"WARNING: No build_tag_override tag found in {buildspec_path}, file will not be overridden"
        )