support early and late commands
This commit is contained in:
parent
1f4c05a50f
commit
99218fbeb4
|
@ -3,6 +3,10 @@ early-commands:
|
|||
- echo a
|
||||
- sleep 1
|
||||
- echo a
|
||||
late-commands:
|
||||
- echo a
|
||||
- sleep 1
|
||||
- echo a
|
||||
keyboard:
|
||||
layout: gb
|
||||
identity:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# 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 .cmdlist import EarlyController, LateController
|
||||
from .error import ErrorController
|
||||
from .filesystem import FilesystemController
|
||||
from .identity import IdentityController
|
||||
|
@ -29,11 +30,13 @@ from .ssh import SSHController
|
|||
from .welcome import WelcomeController
|
||||
from .zdev import ZdevController
|
||||
__all__ = [
|
||||
'EarlyController',
|
||||
'ErrorController',
|
||||
'FilesystemController',
|
||||
'IdentityController',
|
||||
'InstallProgressController',
|
||||
'KeyboardController',
|
||||
'LateController',
|
||||
'ProxyController',
|
||||
'MirrorController',
|
||||
'NetworkController',
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# Copyright 2019 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 asyncio
|
||||
|
||||
from subiquity.controller import NoUIController
|
||||
|
||||
|
||||
class CmdListController(NoUIController):
|
||||
|
||||
autoinstall_default = []
|
||||
cmds = ()
|
||||
|
||||
def load_autoinstall_data(self, data):
|
||||
self.cmds = data
|
||||
|
||||
async def run(self):
|
||||
for i, cmd in enumerate(self.cmds):
|
||||
with self.context.child("command_{}".format(i), cmd):
|
||||
proc = await asyncio.create_subprocess_shell(cmd)
|
||||
await proc.communicate()
|
||||
|
||||
|
||||
class EarlyController(CmdListController):
|
||||
|
||||
autoinstall_key = 'early-commands'
|
||||
|
||||
|
||||
class LateController(CmdListController):
|
||||
|
||||
autoinstall_key = 'late-commands'
|
|
@ -79,21 +79,23 @@ class Subiquity(Application):
|
|||
return SubiquityUI(self)
|
||||
|
||||
controllers = [
|
||||
"Welcome",
|
||||
"Refresh",
|
||||
"Keyboard",
|
||||
"Zdev",
|
||||
"Network",
|
||||
"Proxy",
|
||||
"Mirror",
|
||||
"Refresh",
|
||||
"Filesystem",
|
||||
"Identity",
|
||||
"SSH",
|
||||
"SnapList",
|
||||
"InstallProgress",
|
||||
"Error", # does not have a UI
|
||||
"Reporting", # does not have a UI
|
||||
"Early",
|
||||
"Reporting",
|
||||
"Error",
|
||||
"Welcome",
|
||||
"Refresh",
|
||||
"Keyboard",
|
||||
"Zdev",
|
||||
"Network",
|
||||
"Proxy",
|
||||
"Mirror",
|
||||
"Refresh",
|
||||
"Filesystem",
|
||||
"Identity",
|
||||
"SSH",
|
||||
"SnapList",
|
||||
"InstallProgress",
|
||||
"Late",
|
||||
]
|
||||
|
||||
def __init__(self, opts, block_log_dir):
|
||||
|
@ -148,8 +150,17 @@ class Subiquity(Application):
|
|||
self.opts.autoinstall, self.merged_autoinstall_path)
|
||||
with open(self.merged_autoinstall_path) as fp:
|
||||
self.autoinstall_config = yaml.safe_load(fp)
|
||||
self.controllers.load("Early")
|
||||
self.controllers.load("Reporting")
|
||||
self.controllers.Reporting.start()
|
||||
self.aio_loop.run_until_complete(self.controllers.Early.run())
|
||||
self.new_event_loop()
|
||||
with open(self.merged_autoinstall_path) as fp:
|
||||
self.autoinstall_config = yaml.safe_load(fp)
|
||||
try:
|
||||
super().run()
|
||||
self.new_event_loop()
|
||||
self.aio_loop.run_until_complete(self.controllers.Late.run())
|
||||
except Exception:
|
||||
print("generating crash report")
|
||||
report = self.make_apport_report(
|
||||
|
|
|
@ -363,11 +363,16 @@ class Application:
|
|||
self.updated = os.path.exists(os.path.join(self.state_dir, 'updating'))
|
||||
self.signal = Signal()
|
||||
self.prober = prober
|
||||
self.aio_loop = asyncio.get_event_loop()
|
||||
self.new_event_loop()
|
||||
self.urwid_loop = None
|
||||
self.controllers = ControllerSet(self, self.controllers)
|
||||
self.context = Context.new(self)
|
||||
|
||||
def new_event_loop(self):
|
||||
new_loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(new_loop)
|
||||
self.aio_loop = new_loop
|
||||
|
||||
def run_command_in_foreground(self, cmd, before_hook=None, after_hook=None,
|
||||
**kw):
|
||||
screen = self.urwid_loop.screen
|
||||
|
|
Loading…
Reference in New Issue