Merge pull request #187 from CanonicalLtd/mwhudson/disentangle-identity-welcome

disentangle identity & welcome models, views and controllers
This commit is contained in:
Michael Hudson-Doyle 2017-01-18 09:40:56 +13:00 committed by GitHub
commit c87893570b
13 changed files with 92 additions and 91 deletions

View File

@ -19,7 +19,8 @@ import os
import subprocess import subprocess
import sys import sys
from subiquitycore.controllers.identity import BaseIdentityController from subiquitycore.controller import BaseController
from subiquitycore.models import IdentityModel
from subiquitycore.utils import disable_first_boot_service, run_command from subiquitycore.utils import disable_first_boot_service, run_command
from console_conf.ui.views import IdentityView, LoginView from console_conf.ui.views import IdentityView, LoginView
@ -98,8 +99,11 @@ def write_login_details_standalone():
return 0 return 0
class IdentityController(BaseIdentityController): class IdentityController(BaseController):
identity_view = IdentityView
def __init__(self, common):
super().__init__(common)
self.model = IdentityModel(self.opts)
def default(self): def default(self):
title = "Profile setup" title = "Profile setup"
@ -107,7 +111,7 @@ class IdentityController(BaseIdentityController):
footer = "" footer = ""
self.ui.set_header(title, excerpt) self.ui.set_header(title, excerpt)
self.ui.set_footer(footer, 40) self.ui.set_footer(footer, 40)
self.ui.set_body(self.identity_view(self.model, self, self.opts, self.loop)) self.ui.set_body(IdentityView(self.model, self, self.opts, self.loop))
device_owner = get_device_owner() device_owner = get_device_owner()
if device_owner is not None: if device_owner is not None:
self.model.add_user(device_owner) self.model.add_user(device_owner)

View File

@ -13,20 +13,25 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from console_conf.ui.views import WelcomeView from console_conf.ui.views import WelcomeView
from subiquitycore.controllers.welcome import ( from subiquitycore.controller import BaseController
WelcomeController as WelcomeControllerBase,
)
class WelcomeController(WelcomeControllerBase): class WelcomeController(BaseController):
def default(self): def default(self):
title = "Ubuntu Core" title = "Ubuntu Core"
excerpt = ("Configure the network and setup an administrator " excerpt = ("Configure the network and setup an administrator "
"account on this all-snap Ubuntu Core system.") "account on this all-snap Ubuntu Core system.")
self.ui.set_header(title, excerpt) self.ui.set_header(title, excerpt)
self.ui.set_footer("") self.ui.set_footer("")
view = WelcomeView(self.model, self) view = WelcomeView(self)
self.ui.set_body(view) self.ui.set_body(view)
def done(self):
self.signal.emit_signal('next-screen')
def cancel(self):
# Can't go back from here!
pass

View File

@ -19,18 +19,28 @@ Welcome provides user with language selection
""" """
import logging import logging
from urwid import Pile from urwid import ListBox, Pile
from subiquitycore.ui.buttons import start_btn from subiquitycore.ui.buttons import ok_btn
from subiquitycore.ui.utils import Color from subiquitycore.ui.utils import Padding, Color
from subiquitycore.ui.views.welcome import CoreWelcomeView from subiquitycore.view import BaseView
log = logging.getLogger("console_conf.views.welcome") log = logging.getLogger("console_conf.views.welcome")
class WelcomeView(CoreWelcomeView): class WelcomeView(BaseView):
def __init__(self, controller):
self.controller = controller
self.body = [
Padding.fixed_10(self._build_buttons())
]
super().__init__(ListBox(self.body))
def _build_buttons(self): def _build_buttons(self):
self.buttons = [ self.buttons = [
Color.button(start_btn(on_press=self.confirm), Color.button(ok_btn(on_press=self.confirm),
focus_map='button focus'), focus_map='button focus'),
] ]
return Pile(self.buttons) return Pile(self.buttons)
def confirm(self, result):
self.controller.done()

View File

@ -15,9 +15,9 @@
from subiquitycore.controllers.login import LoginController # NOQA from subiquitycore.controllers.login import LoginController # NOQA
from subiquitycore.controllers.network import NetworkController # NOQA from subiquitycore.controllers.network import NetworkController # NOQA
from subiquitycore.controllers.welcome import WelcomeController # NOQA
from .identity import IdentityController # NOQA from .identity import IdentityController # NOQA
from .installpath import InstallpathController # NOQA from .installpath import InstallpathController # NOQA
from .installprogress import InstallProgressController # NOQA from .installprogress import InstallProgressController # NOQA
from .filesystem import FilesystemController # NOQA from .filesystem import FilesystemController # NOQA
from .welcome import WelcomeController # NOQA

View File

@ -14,10 +14,54 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from subiquitycore.controllers.identity import BaseIdentityController import logging
from subiquitycore.controller import BaseController
from subiquitycore.models import IdentityModel
from subiquitycore import utils
from subiquity.ui.views import IdentityView from subiquity.ui.views import IdentityView
log = logging.getLogger('subiquity.controllers.identity')
class IdentityController(BaseIdentityController):
identity_view = IdentityView class IdentityController(BaseController):
def __init__(self, common):
super().__init__(common)
self.model = IdentityModel(self.opts)
def default(self):
title = "Profile setup"
excerpt = ("Input your username and password to log in to the system.")
footer = ""
self.ui.set_header(title, excerpt)
self.ui.set_footer(footer, 40)
self.ui.set_body(IdentityView(self.model, self, self.opts))
def cancel(self):
self.signal.emit_signal('prev-screen')
# None of the commented out code below is actually called. Maybe it should be?
## def identity_done(self):
## self.login()
## def login(self):
## log.debug("Identity login view")
## title = ("Configuration Complete")
## footer = ("View configured user and device access methods")
## self.ui.set_header(title)
## self.ui.set_footer(footer)
## net_model = self.controllers['Network'].model
## configured_ifaces = net_model.get_configured_interfaces()
## login_view = LoginView(self.model, self, configured_ifaces)
## self.ui.set_body(login_view)
## def login_done(self):
## # mark ourselves complete
## utils.disable_subiquity()
## self.signal.emit_signal('next-screen')

View File

@ -14,10 +14,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from subiquitycore.ui.views import WelcomeView
from subiquitycore.models import WelcomeModel
from subiquitycore.controller import BaseController from subiquitycore.controller import BaseController
from subiquity.ui.views import WelcomeView
from subiquity.models import WelcomeModel
class WelcomeController(BaseController): class WelcomeController(BaseController):

View File

@ -17,3 +17,4 @@ from .installpath import InstallpathModel # NOQA
from .installprogress import InstallProgressModel # NOQA from .installprogress import InstallProgressModel # NOQA
from .filesystem import FilesystemModel # NOQA from .filesystem import FilesystemModel # NOQA
from .raid import RaidModel # NOQA from .raid import RaidModel # NOQA
from .welcome import WelcomeModel

View File

@ -16,7 +16,7 @@
import logging import logging
log = logging.getLogger('subiquitycore.welcome') log = logging.getLogger('subiquity.models.welcome')
class WelcomeModel(object): class WelcomeModel(object):

View File

@ -26,3 +26,4 @@ from .lvm import LVMVolumeGroupView # NOQA
from .identity import IdentityView # NOQA from .identity import IdentityView # NOQA
from .installpath import InstallpathView # NOQA from .installpath import InstallpathView # NOQA
from .installprogress import ProgressView # NOQA from .installprogress import ProgressView # NOQA
from .welcome import WelcomeView

View File

@ -25,10 +25,11 @@ from subiquitycore.ui.buttons import menu_btn, ok_btn
from subiquitycore.ui.utils import Padding, Color from subiquitycore.ui.utils import Padding, Color
from subiquitycore.view import BaseView from subiquitycore.view import BaseView
log = logging.getLogger("subiquitycore.views.welcome") log = logging.getLogger("subiquity.views.welcome")
class CoreWelcomeView(BaseView): class WelcomeView(BaseView):
def __init__(self, model, controller): def __init__(self, model, controller):
self.model = model self.model = model
self.controller = controller self.controller = controller

View File

@ -1,64 +0,0 @@
# Copyright 2015 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from subiquitycore.controller import BaseController
from subiquitycore.models import IdentityModel
from subiquitycore.ui.views import LoginView
from subiquitycore import utils
log = logging.getLogger('subiquitycore.controllers.identity')
class BaseIdentityController(BaseController):
identity_view = None
def __init__(self, common):
super().__init__(common)
self.model = IdentityModel(self.opts)
def default(self):
title = "Profile setup"
excerpt = ("Input your username and password to log in to the system.")
footer = ""
self.ui.set_header(title, excerpt)
self.ui.set_footer(footer, 40)
self.ui.set_body(self.identity_view(self.model, self, self.opts))
def cancel(self):
self.signal.emit_signal('prev-screen')
def identity_done(self):
self.login()
def login(self):
log.debug("Identity login view")
title = ("Configuration Complete")
footer = ("View configured user and device access methods")
self.ui.set_header(title)
self.ui.set_footer(footer)
net_model = self.controllers['Network'].model
configured_ifaces = net_model.get_configured_interfaces()
login_view = LoginView(self.model, self, configured_ifaces)
self.ui.set_body(login_view)
def login_done(self):
# mark ourselves complete
utils.disable_subiquity()
self.signal.emit_signal('next-screen')

View File

@ -14,6 +14,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from .network import NetworkModel # NOQA from .network import NetworkModel # NOQA
from .welcome import WelcomeModel # NOQA
from .identity import IdentityModel # NOQA from .identity import IdentityModel # NOQA
from .login import LoginModel # NOQA from .login import LoginModel # NOQA

View File

@ -19,5 +19,4 @@ from .network_configure_interface import NetworkConfigureInterfaceView # NOQA
from .network_configure_manual_interface import NetworkConfigureIPv4InterfaceView, NetworkConfigureIPv6InterfaceView # NOQA from .network_configure_manual_interface import NetworkConfigureIPv4InterfaceView, NetworkConfigureIPv6InterfaceView # NOQA
from .network_configure_wlan_interface import NetworkConfigureWLANView # NOQA from .network_configure_wlan_interface import NetworkConfigureWLANView # NOQA
from .network_bond_interfaces import NetworkBondInterfacesView # NOQA from .network_bond_interfaces import NetworkBondInterfacesView # NOQA
from .welcome import CoreWelcomeView as WelcomeView # NOQA
from .login import LoginView # NOQA from .login import LoginView # NOQA