def move_strings()

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


def move_strings(srcfile, dstfile, id_finder, keep_dest):
    output_for_original_file = []
    output_for_new_file = []

    logging.debug("Reading xml file: %s", srcfile)
    data = get_resource_content_without_header(srcfile)

    for match in ROW_PATTERN.finditer(data):
        piece = match.group(0)
        if id_finder.get_id(match.group(2)) is not None:
            output_for_new_file.append(piece)
        else:
            output_for_original_file.append(piece)

    if keep_dest:
        try:
            data = get_resource_content_without_header(dstfile)
            for match in ROW_PATTERN.finditer(data):
                piece = match.group(0)
                output_for_new_file.append(piece)
        except FileNotFoundError:
            # The output file doesn't exist. It's OK.
            pass

    with open(srcfile, "wt") as xml_file:
        logging.debug("Updating: %s", srcfile)
        xml_file.write(HEADER)
        xml_file.write("".join(output_for_original_file))
        xml_file.write(FOOTER)

    if not output_for_new_file:
        logging.debug("No strings to write out")

        # There's no strings to write
        return

    # Create a directory for dstfile, in case it doesn't exist
    os.makedirs(os.path.dirname(dstfile), exist_ok=True)

    with open(dstfile, "wt") as xml_file:
        logging.debug("Writing out: %s", dstfile)
        xml_file.write(HEADER)
        xml_file.write("".join(output_for_new_file))
        xml_file.write(FOOTER)