asyncioify "fine grained action" handling a bit
This commit is contained in:
parent
399e711b28
commit
f89b9e692a
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue