def mps2_set_board_image_file(self, disk, images_cfg_path, image0file_path, image_name='images.txt'):
        """ This function will alter image cfg file

        @details Main goal of this function is to change number of images to 1, comment all
                 existing image entries and append at the end of file new entry with test path

        @return True when all steps were successful
        """
        MBED_SDK_TEST_STAMP = 'test suite entry'
        image_path = join(disk, images_cfg_path, image_name)
        new_file_lines = [] # New configuration file lines (entries)

        # Check each line of the image configuration file
        try:
            with open(image_path, 'r') as file:
                for line in file:
                    if re.search('^TOTALIMAGES', line):
                        # Check number of total images, should be 1
                        new_file_lines.append(re.sub('^TOTALIMAGES:[\t ]*[\d]+', 'TOTALIMAGES: 1', line))
                    elif re.search('; - %s[\n\r]*$'% MBED_SDK_TEST_STAMP, line):
                        # Look for test suite entries and remove them
                        pass    # Omit all test suite entries
                    elif re.search('^IMAGE[\d]+FILE', line):
                        # Check all image entries and mark the ';'
                        new_file_lines.append(';' + line)   # Comment non test suite lines
                    else:
                        # Append line to new file
                        new_file_lines.append(line)
        except __HOLE__ as e:
            return False

        # Add new image entry with proper commented stamp
        new_file_lines.append('IMAGE0FILE: %s    ; - %s\r\n'% (image0file_path, MBED_SDK_TEST_STAMP))

        # Write all lines to file
        try:
            with open(image_path, 'w') as file:
                for line in new_file_lines:
                    file.write(line),
        except IOError:
            return False

        return True
dataset/ETHPy150Open ARMmbed/htrun/mbed_host_tests/host_tests_plugins/module_copy_mps2.py/HostTestPluginCopyMethod_MPS2.mps2_set_board_image_file