Merge pull request #1814 from ogayot/noop-no-emit-source-configured
source: do not fire a configured event again if nothing changed
This commit is contained in:
commit
d4e9f7d3b8
|
@ -13,7 +13,6 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import contextlib
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
@ -79,6 +78,7 @@ class SourceController(SubiquityController):
|
||||||
self._handler = None
|
self._handler = None
|
||||||
self.source_path: Optional[str] = None
|
self.source_path: Optional[str] = None
|
||||||
self.ai_source_id: Optional[str] = None
|
self.ai_source_id: Optional[str] = None
|
||||||
|
self._configured: bool = False
|
||||||
|
|
||||||
def make_autoinstall(self):
|
def make_autoinstall(self):
|
||||||
return {
|
return {
|
||||||
|
@ -148,10 +148,31 @@ class SourceController(SubiquityController):
|
||||||
|
|
||||||
async def configured(self):
|
async def configured(self):
|
||||||
await super().configured()
|
await super().configured()
|
||||||
|
self._configured = True
|
||||||
self.app.base_model.set_source_variant(self.model.current.variant)
|
self.app.base_model.set_source_variant(self.model.current.variant)
|
||||||
|
|
||||||
async def POST(self, source_id: str, search_drivers: bool = False) -> None:
|
async def POST(self, source_id: str, search_drivers: bool = False) -> None:
|
||||||
self.model.search_drivers = search_drivers
|
# Marking the source model configured has an effect on many of the
|
||||||
with contextlib.suppress(KeyError):
|
# other controllers. Oftentimes, it would involve cancelling and
|
||||||
self.model.current = self.model.get_matching_source(source_id)
|
# restarting various operations.
|
||||||
await self.configured()
|
# Let's try not to trigger the event again if we are not changing any
|
||||||
|
# of the settings.
|
||||||
|
changed = False
|
||||||
|
if self.model.search_drivers != search_drivers:
|
||||||
|
changed = True
|
||||||
|
self.model.search_drivers = search_drivers
|
||||||
|
|
||||||
|
try:
|
||||||
|
new_source = self.model.get_matching_source(source_id)
|
||||||
|
except KeyError:
|
||||||
|
# TODO going forward, we should probably stop ignoring unmatched
|
||||||
|
# sources.
|
||||||
|
log.warning("unable to find '%s' in sources catalog", source_id)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if self.model.current != new_source:
|
||||||
|
changed = True
|
||||||
|
self.model.current = new_source
|
||||||
|
|
||||||
|
if changed or not self._configured:
|
||||||
|
await self.configured()
|
||||||
|
|
Loading…
Reference in New Issue