def output_string_ids_map()

in library/scripts/find_movable_strings.py [0:0]


def output_string_ids_map(sp_config, strings_to_move):
    string_pack_ids = []
    for index, string_tuple in enumerate(sorted(strings_to_move)):
        string_type, string_name = string_tuple
        string_pack_ids.append((" " * 10 + "R.%s.%s,") % (string_type, string_name))

    class_file_path = sp_config.pack_ids_class_file_path
    if class_file_path is None or not path.exists(class_file_path):
        # No class file is provided, print to console directly to let people copy/paste later.
        for pack_id in string_pack_ids:
            print(pack_id)
        return

    # Directly update the class file with latest ids.
    with open(class_file_path, "rt") as pack_ids_file:
        existing_class_file_lines = pack_ids_file.readlines()

    region_start_index = None
    region_end_index = None
    for i, line in enumerate(existing_class_file_lines):
        if "// region" in line:
            region_start_index = i
        elif "// endregion" in line:
            region_end_index = i

    if region_start_index is None or region_end_index is None:
        print(
            "Can't find the String Pack IDs map region in %s to update content."
            % class_file_path
        )
        return

    with open(class_file_path, "wt") as pack_ids_file:
        pack_ids_file.writelines(
            existing_class_file_lines[0 : region_start_index + 1]
            + (
                generate_kotlin(string_pack_ids)
                if class_file_path.endswith(".kt")
                else generate_java(string_pack_ids)
            )
            + existing_class_file_lines[region_end_index:]
        )
    print("Updated: " + class_file_path)