Merge pull request #416 from mwhudson/installpath-rejig

rework installpath model to record what the user entered
This commit is contained in:
Michael Hudson-Doyle 2019-03-06 15:54:41 +13:00 committed by GitHub
commit fa58cb1fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 28 deletions

View File

@ -21,15 +21,10 @@ log = logging.getLogger("subiquity.models.installpath")
class InstallpathModel(object): class InstallpathModel(object):
""" Model representing install options """Model representing install options"""
List of install paths in the form of:
('UI Text seen by user', <signal name>, <callback function string>)
"""
path = 'ubuntu' path = 'ubuntu'
# update() is not run, upon selecting the default choice... results = {}
curtin = {}
def __init__(self, target, sources=None): def __init__(self, target, sources=None):
self.target = target self.target = target
@ -59,21 +54,24 @@ class InstallpathModel(object):
for n, u in enumerate(src_map[self.path])} for n, u in enumerate(src_map[self.path])}
def update(self, results): def update(self, results):
self.curtin = {} self.results = results
def render(self):
config = {}
def t(path): def t(path):
return os.path.join(self.target, path) return os.path.join(self.target, path)
if self.path == 'maas_region': if self.path == 'maas_region':
self.curtin['debconf_selections'] = { config['debconf_selections'] = {
'maas-username': ('maas-region-controller maas/username ' 'maas-username': ('maas-region-controller maas/username '
'string %s' % results['username']), 'string %s' % self.results['username']),
'maas-password': ('maas-region-controller maas/password ' 'maas-password': ('maas-region-controller maas/password '
'password %s' % results['password']), 'password %s' % self.results['password']),
} }
self.curtin['late_commands'] = { config['late_commands'] = {
# Maintainer scripts cache results, from config files, if they # Maintainer scripts cache self.results, from config files, if
# exist. These shouldn't exist, since this was fixed in # they # exist. These shouldn't exist, since this was fixed in
# livecd-rootfs but remove these, just to be sure. # livecd-rootfs but remove these, just to be sure.
'900-maas': ['rm', '-f', t('etc/maas/rackd.conf')], '900-maas': ['rm', '-f', t('etc/maas/rackd.conf')],
'901-maas': ['rm', '-f', t('etc/maas/region.conf')], '901-maas': ['rm', '-f', t('etc/maas/region.conf')],
@ -128,15 +126,15 @@ class InstallpathModel(object):
'915-maas': ['umount', t('proc')], '915-maas': ['umount', t('proc')],
} }
elif self.path == 'maas_rack': elif self.path == 'maas_rack':
self.curtin['debconf_selections'] = { config['debconf_selections'] = {
'maas-url': ('maas-rack-controller ' 'maas-url': ('maas-rack-controller '
'maas-rack-controller/maas-url ' 'maas-rack-controller/maas-url '
'string %s' % results['url']), 'string %s' % self.results['url']),
'maas-secret': ('maas-rack-controller ' 'maas-secret': ('maas-rack-controller '
'maas-rack-controller/shared-secret ' 'maas-rack-controller/shared-secret '
'password %s' % results['secret']), 'password %s' % self.results['secret']),
} }
self.curtin['late_commands'] = { config['late_commands'] = {
'90-maas': ['rm', '-f', t('etc/maas/rackd.conf')], '90-maas': ['rm', '-f', t('etc/maas/rackd.conf')],
'91-maas': ['curtin', 'in-target', '--', 'maas-rack', '91-maas': ['curtin', 'in-target', '--', 'maas-rack',
'config', '--init'], 'config', '--init'],
@ -149,9 +147,6 @@ class InstallpathModel(object):
'/var/lib/dpkg/info/maas-rack-controller.postinst' '/var/lib/dpkg/info/maas-rack-controller.postinst'
' configure || :')], ' configure || :')],
} }
else: elif self.path != "ubuntu":
raise ValueError("invalid Installpath %s" % self.path) raise ValueError("invalid Installpath %s" % self.path)
self.curtin['sources'] = self.sources return config
def render(self):
return self.curtin

View File

@ -65,17 +65,22 @@ class InstallpathView(BaseView):
self.items = [] self.items = []
back = back_btn(_("Back"), on_press=self.cancel) back = back_btn(_("Back"), on_press=self.cancel)
super().__init__(screen( super().__init__(screen(
[button_pile(self._build_choices()), Text("")], [back], [self._build_choices(), Text("")], [back],
focus_buttons=False, excerpt=_(self.excerpt))) focus_buttons=False, excerpt=_(self.excerpt)))
def _build_choices(self): def _build_choices(self):
choices = [] choices = []
for label, path in self.model.paths: focus_position = 0
for i, (label, path) in enumerate(self.model.paths):
log.debug("Building inputs: {}".format(path)) log.debug("Building inputs: {}".format(path))
choices.append( choices.append(
forward_btn( forward_btn(
label=label, on_press=self.confirm, user_arg=path)) label=label, on_press=self.confirm, user_arg=path))
return choices if path == self.model.path:
focus_position = i
bp = button_pile(choices)
bp.base_widget.focus_position = focus_position
return bp
def confirm(self, sender, path): def confirm(self, sender, path):
self.controller.choose_path(path) self.controller.choose_path(path)
@ -174,9 +179,9 @@ class MAASView(BaseView):
self.title = title self.title = title
if self.model.path == "maas_region": if self.model.path == "maas_region":
self.form = RegionForm() self.form = RegionForm(initial=self.model.results)
elif self.model.path == "maas_rack": elif self.model.path == "maas_rack":
self.form = RackForm() self.form = RackForm(initial=self.model.results)
else: else:
raise ValueError("invalid MAAS form %s" % self.model.path) raise ValueError("invalid MAAS form %s" % self.model.path)