! @brief Program by performing sector erases.

def _sector_erase_program(self, progress_cb=_stub_progress):
        """! @brief Program by performing sector erases."""
        actual_sector_erase_count = 0
        actual_sector_erase_weight = 0
        progress = 0

        progress_cb(0.0)

        # Fill in same flag for all pages. This is done up front so we're not trying
        # to read from flash while simultaneously programming it.
        progress = self._scan_pages_for_same(progress_cb)
        
        for sector in self.sector_list:
            if sector.are_any_pages_not_same():
                # Erase the sector
                self.flash.init(self.flash.Operation.ERASE)
                self.flash.erase_sector(sector.addr)
                self.flash.uninit()

                actual_sector_erase_weight += sector.erase_weight

                # Update progress
                if self.sector_erase_weight > 0:
                    progress_cb(float(progress) / float(self.sector_erase_weight))
                
                # The sector was erased, so we must program all pages in the sector
                # regardless of whether they were the same or not.
                for page in sector.page_list:

                    progress += page.get_program_weight()

                    self.flash.init(self.flash.Operation.PROGRAM)
                    self.flash.program_page(page.addr, page.data)
                    self.flash.uninit()
            
                    actual_sector_erase_count += 1
                    actual_sector_erase_weight += page.get_program_weight()

                    # Update progress
                    if self.sector_erase_weight > 0:
                        progress_cb(float(progress) / float(self.sector_erase_weight))

        progress_cb(1.0)

        LOG.debug("Estimated sector erase programmed page count: %i", self.sector_erase_count)
        LOG.debug("Actual sector erase programmed page count: %i", actual_sector_erase_count)

        return FlashBuilder.FLASH_SECTOR_ERASE