attach a controller to most contexts

This commit is contained in:
Michael Hudson-Doyle 2020-04-06 16:28:46 +12:00
parent 246570314a
commit 9a11e90719
4 changed files with 32 additions and 1 deletions

26
subiquity/context.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright 2020 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/>.
from subiquitycore.context import Context
class SubiquityContext(Context):
controller = None
def __init__(self, app, name, description, parent, level, childlevel=None):
super().__init__(app, name, description, parent, level, childlevel)
if parent is not None:
self.controller = parent.controller

View File

@ -35,6 +35,7 @@ class SubiquityController(BaseController):
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
self.autoinstall_applied = False self.autoinstall_applied = False
self.context.controller = self
self.setup_autoinstall() self.setup_autoinstall()
def setup_autoinstall(self): def setup_autoinstall(self):

View File

@ -37,6 +37,7 @@ from subiquitycore.controller import Skip
from subiquitycore.core import Application from subiquitycore.core import Application
from subiquitycore.utils import run_command from subiquitycore.utils import run_command
from subiquity.context import SubiquityContext
from subiquity.controllers.error import ( from subiquity.controllers.error import (
ErrorReportKind, ErrorReportKind,
) )
@ -86,6 +87,8 @@ class Subiquity(Application):
project = "subiquity" project = "subiquity"
context_cls = SubiquityContext
def make_model(self): def make_model(self):
root = '/' root = '/'
if self.opts.dry_run: if self.opts.dry_run:

View File

@ -315,6 +315,7 @@ class Application:
# instance. # instance.
make_ui = SubiquityCoreUI make_ui = SubiquityCoreUI
context_cls = Context
def __init__(self, opts): def __init__(self, opts):
self.debug_flags = () self.debug_flags = ()
@ -366,7 +367,7 @@ class Application:
self.new_event_loop() self.new_event_loop()
self.urwid_loop = None self.urwid_loop = None
self.controllers = ControllerSet(self, self.controllers) self.controllers = ControllerSet(self, self.controllers)
self.context = Context.new(self) self.context = self.context_cls.new(self)
def new_event_loop(self): def new_event_loop(self):
new_loop = asyncio.new_event_loop() new_loop = asyncio.new_event_loop()