Skip to content

Commit

Permalink
storage: client: accept coroutines as actions
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Gayot <[email protected]>
  • Loading branch information
ogayot committed Jun 19, 2024
1 parent ad11418 commit 2f9e361
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions subiquity/client/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)
from subiquity.ui.views import FilesystemView, GuidedDiskSelectionView
from subiquity.ui.views.filesystem.probing import ProbingFailed, SlowProbing
from subiquitycore.async_helpers import run_bg_task
from subiquitycore.async_helpers import connect_async_signal, run_bg_task
from subiquitycore.lsb_release import lsb_release
from subiquitycore.view import BaseView

Expand Down Expand Up @@ -201,6 +201,11 @@ async def _answers_action(self, action):
)
from subiquitycore.ui.stretchy import StretchyOverlay

form_submitted = asyncio.Event()

async def on_form_closed(*args, **kwargs):
form_submitted.set()

log.debug("_answers_action %r", action)
if "obj" in action:
obj = self._action_get(action["obj"])
Expand All @@ -214,11 +219,18 @@ async def _answers_action(self, action):
meth = getattr(
self.ui.body.avail_list, "_{}_{}".format(obj.type, action_name)
)
meth(obj)
maybe_coro = meth(obj)
if asyncio.iscoroutine(maybe_coro):
await maybe_coro
self.ui.body.request_redraw()

yield
body = self.ui.body._w
if not isinstance(body, StretchyOverlay):
return

connect_async_signal(body.stretchy, "closed", on_form_closed)

if isinstance(
body.stretchy, (ConfirmDeleteStretchy, ConfirmReformatStretchy)
):
Expand All @@ -229,28 +241,34 @@ async def _answers_action(self, action):
body.stretchy.form, action["data"], action.get("submit", True)
):
pass

await form_submitted.wait()
elif action["action"] == "create-raid":
self.ui.body.create_raid()
yield
body = self.ui.body._w
connect_async_signal(body.stretchy, "closed", on_form_closed)
async for _ in self._enter_form_data(
body.stretchy.form,
action["data"],
action.get("submit", True),
clean_suffix="raid",
):
pass
await form_submitted.wait()
elif action["action"] == "create-vg":
self.ui.body.create_vg()
yield
body = self.ui.body._w
connect_async_signal(body.stretchy, "closed", on_form_closed)
async for _ in self._enter_form_data(
body.stretchy.form,
action["data"],
action.get("submit", True),
clean_suffix="vg",
):
pass
await form_submitted.wait()
elif action["action"] == "done":
if not self.ui.body.done_btn.enabled:
raise Exception("answers did not provide complete fs config")
Expand Down

0 comments on commit 2f9e361

Please sign in to comment.