refactor how we tell when to show confirmation a bit

This commit is contained in:
Michael Hudson-Doyle 2020-09-23 14:51:03 +12:00
parent 59364a737e
commit 9cb66cdc71
3 changed files with 16 additions and 11 deletions

View File

@ -92,7 +92,6 @@ class InstallProgressController(SubiquityTuiController):
self._log_syslog_identifier = 'curtin_log.%s' % (os.getpid(),)
self.tb_extractor = TracebackExtractor()
self.curtin_event_contexts = {}
self.confirmation = asyncio.Event()
def interactive(self):
return self.app.interactive()
@ -307,7 +306,7 @@ class InstallProgressController(SubiquityTuiController):
self.update_state(InstallState.NEEDS_CONFIRMATION)
await self.confirmation.wait()
await self.model.confirmation.wait()
self.update_state(InstallState.RUNNING)

View File

@ -191,8 +191,6 @@ class Subiquity(TuiApplication):
self.note_data_for_apport("SnapUpdated", str(self.updated))
self.note_data_for_apport("UsingAnswers", str(bool(self.answers)))
self.install_confirmed = False
def subiquity_event(self, event):
if event["MESSAGE"] == "starting install":
if event["_PID"] == os.getpid():
@ -405,8 +403,7 @@ class Subiquity(TuiApplication):
listener.report_finish_event(context, description, status)
async def confirm_install(self):
self.install_confirmed = True
self.controllers.InstallProgress.confirmation.set()
self.base_model.confirm()
def _cancel_show_progress(self):
if self.show_progress_handle is not None:
@ -466,10 +463,7 @@ class Subiquity(TuiApplication):
self.next_screen(self.confirm_install())
async def make_view_for_controller(self, new):
can_install = all(e.is_set() for e in self.base_model.install_events)
if can_install and not self.install_confirmed:
if new.model_name:
if not self.base_model.is_configured(new.model_name):
if self.base_model.needs_confirmation(new.model_name):
raise Confirm
if new.interactive():
if new.answers:

View File

@ -119,6 +119,8 @@ class SubiquityModel:
self.ssh = SSHModel()
self.userdata = {}
self.confirmation = asyncio.Event()
self._events = {
name: asyncio.Event() for name in ALL_MODEL_NAMES
}
@ -143,6 +145,16 @@ class SubiquityModel:
}
log.debug("model %s is configured, to go %s", model_name, unconfigured)
def needs_confirmation(self, model_name):
if model_name is None:
return False
if not all(e.is_set() for e in self.install_events):
return None
return not self.confirmation.is_set()
def confirm(self):
self.confirmation.set()
def is_configured(self, model_name):
return self._events[model_name].is_set()