diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 81542839..dfa292d8 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -312,7 +312,7 @@ class FilesystemController(SubiquityTuiController): def _action_clean_level(self, level): return raidlevels_by_value[level] - def _answers_action(self, action): + async def _answers_action(self, action): from subiquitycore.ui.stretchy import StretchyOverlay from subiquity.ui.views.filesystem.delete import ConfirmDeleteStretchy log.debug("_answers_action %r", action) @@ -333,28 +333,31 @@ class FilesystemController(SubiquityTuiController): if action.get("submit", True): body.stretchy.done() else: - yield from self._enter_form_data( - body.stretchy.form, - action['data'], - action.get("submit", True)) + async for _ in self._enter_form_data( + body.stretchy.form, + action['data'], + action.get("submit", True)): + pass elif action['action'] == 'create-raid': self.ui.body.create_raid() yield body = self.ui.body._w - yield from self._enter_form_data( - body.stretchy.form, - action['data'], - action.get("submit", True), - clean_suffix='raid') + async for _ in self._enter_form_data( + body.stretchy.form, + action['data'], + action.get("submit", True), + clean_suffix='raid'): + pass elif action['action'] == 'create-vg': self.ui.body.create_vg() yield body = self.ui.body._w - yield from self._enter_form_data( - body.stretchy.form, - action['data'], - action.get("submit", True), - clean_suffix='vg') + async for _ in self._enter_form_data( + body.stretchy.form, + action['data'], + action.get("submit", True), + clean_suffix='vg'): + pass elif action['action'] == 'done': if not self.ui.body.done.enabled: raise Exception("answers did not provide complete fs config") @@ -367,7 +370,8 @@ class FilesystemController(SubiquityTuiController): if self.answers['guided']: self.finish(self.app.confirm_install()) if self.answers['manual']: - self._run_iterator(self._run_actions(self.answers['manual'])) + self.app.aio_loop.create_task( + self._run_actions(self.answers['manual'])) self.answers['manual'] = [] def guided(self): diff --git a/subiquitycore/controllers/network.py b/subiquitycore/controllers/network.py index 681edb81..ad7dcdc3 100644 --- a/subiquitycore/controllers/network.py +++ b/subiquitycore/controllers/network.py @@ -227,7 +227,7 @@ class NetworkController(TuiController): log.debug("%s", r) return r - def _answers_action(self, action): + async def _answers_action(self, action): log.debug("_answers_action %r", action) if 'obj' in action: obj = self._action_get(action['obj']).netdev_info() @@ -250,10 +250,11 @@ class NetworkController(TuiController): prefix = k.split('-')[0] form_name = prefix + "_form" submit_key = prefix + "-submit" - yield from self._enter_form_data( - getattr(body.stretchy, form_name), - v, - action.get(submit_key, True)) + async for _ in self._enter_form_data( + getattr(body.stretchy, form_name), + v, + action.get(submit_key, True)): + pass elif action['action'] == 'create-bond': self.ui.body._create_bond() yield @@ -261,10 +262,11 @@ class NetworkController(TuiController): data = action['data'].copy() if 'devices' in data: data['interfaces'] = data.pop('devices') - yield from self._enter_form_data( - body.stretchy.form, - data, - action.get("submit", True)) + async for _ in self._enter_form_data( + body.stretchy.form, + data, + action.get("submit", True)): + pass elif action['action'] == 'done': self.ui.body.done() else: @@ -431,7 +433,8 @@ class NetworkController(TuiController): elif self.answers.get('actions', False): actions = self.answers['actions'] self.answers.clear() - self._run_iterator(self._run_actions(actions)) + self.app.aio_loop.create_task( + self._run_actions(actions)) if not dhcp_events: return diff --git a/subiquitycore/tuicontroller.py b/subiquitycore/tuicontroller.py index 40b59f60..a5fce566 100644 --- a/subiquitycore/tuicontroller.py +++ b/subiquitycore/tuicontroller.py @@ -14,6 +14,7 @@ # along with this program. If not, see . from abc import abstractmethod +import asyncio import logging from subiquitycore.controller import BaseController @@ -60,7 +61,7 @@ class TuiController(BaseController): # Stuff for fine grained actions, used by filesystem and network # controller at time of writing this comment. - def _enter_form_data(self, form, data, submit, clean_suffix=''): + async def _enter_form_data(self, form, data, submit, clean_suffix=''): for k, v in data.items(): c = getattr( self, '_action_clean_{}_{}'.format(k, clean_suffix), None) @@ -81,18 +82,12 @@ class TuiController(BaseController): raise Exception("answers left form invalid!") form._click_done(None) - def _run_actions(self, actions): + async def _run_actions(self, actions): + delay = 0.2/self.app.scale_factor for action in actions: - yield from self._answers_action(action) - - def _run_iterator(self, it, delay=None): - if delay is None: - delay = 0.2/self.app.scale_factor - try: - next(it) - except StopIteration: - return - self.app.aio_loop.call_later(delay, self._run_iterator, it, delay/1.1) + async for _ in self._answers_action(action): + await asyncio.sleep(delay) + delay /= 1.1 class RepeatedController(BaseController):