Merge pull request #773 from xnox/snap-create-user-error

console_conf: fix showing error messages, when snap create-user fails
This commit is contained in:
Dimitri John Ledkov 2020-05-21 01:02:31 +01:00 committed by GitHub
commit e2fe2a0693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 24 deletions

View File

@ -156,8 +156,9 @@ class IdentityController(BaseController):
cp = run_command(
["snap", "create-user", "--sudoer", "--json", email])
if cp.returncode != 0:
self.ui.body.error.set_text(
"Creating user failed:\n" + cp.stderr)
if isinstance(self.ui.body, IdentityView):
self.ui.body.snap_create_user_failed(
"Creating user failed:", cp.stderr)
return
else:
data = json.loads(cp.stdout)

View File

@ -17,6 +17,7 @@ import logging
from urwid import connect_signal
from subiquitycore.view import BaseView
from subiquitycore.ui.utils import SomethingFailed
from subiquitycore.ui.form import (
Form,
EmailField,
@ -55,3 +56,6 @@ class IdentityView(BaseView):
def done(self, result):
self.controller.identity_done(result.email.value)
def snap_create_user_failed(self, msg, stderr):
self.show_stretchy_overlay(SomethingFailed(self, msg, stderr))

View File

@ -28,7 +28,6 @@ from subiquitycore.view import (
from subiquitycore.ui.buttons import (
cancel_btn,
ok_btn,
other_btn,
)
from subiquitycore.ui.container import (
ListBox,
@ -49,6 +48,7 @@ from subiquitycore.ui.stretchy import (
from subiquitycore.ui.utils import (
button_pile,
screen,
SomethingFailed,
)
from subiquity.ui.views.identity import (
@ -217,26 +217,6 @@ class ConfirmSSHKeys(Stretchy):
self.parent.controller.done(self.result)
class FetchingSSHKeysFailed(Stretchy):
def __init__(self, parent, msg, stderr):
self.parent = parent
ok = other_btn(label=_("Close"), on_press=self.close)
widgets = [
Text(msg),
Text(""),
Text(stderr.strip('\n')),
Text(""),
button_pile([ok]),
]
super().__init__(
"",
widgets,
2, 4)
def close(self, sender):
self.parent.remove_overlay()
class SSHView(BaseView):
title = _("SSH Setup")
@ -318,4 +298,4 @@ class SSHView(BaseView):
def fetching_ssh_keys_failed(self, msg, stderr):
self.remove_overlay()
self.show_stretchy_overlay(FetchingSSHKeysFailed(self, msg, stderr))
self.show_stretchy_overlay(SomethingFailed(self, msg, stderr))

View File

@ -30,7 +30,9 @@ from urwid import (
WidgetDisable,
)
from subiquitycore.ui.buttons import other_btn
from subiquitycore.ui.container import ListBox, Pile
from subiquitycore.ui.stretchy import Stretchy
from subiquitycore.ui.table import TableRow
from subiquitycore.ui.width import widget_width
@ -330,3 +332,23 @@ def make_action_menu_row(
def rewrap(text):
paras = text.split("\n\n")
return "\n\n".join([p.replace('\n', ' ') for p in paras]).strip()
class SomethingFailed(Stretchy):
def __init__(self, parent, msg, stderr):
self.parent = parent
ok = other_btn(label=_("Close"), on_press=self.close)
widgets = [
Text(msg),
Text(""),
Text(stderr.strip('\n')),
Text(""),
button_pile([ok]),
]
super().__init__(
"",
widgets,
2, 4)
def close(self, sender):
self.parent.remove_overlay()