Add a mirror panel.

This very simply adds a mirror panel to subiquity.
Nothing intelligent at all.  Just defaults to filling with
http://archive.ubuntu.com/ubuntu/ and lets user fill it in.

As implemented here, the mirror only replaces primary mirror,
security will still use http://security.ubuntu.com/ubuntu/
This commit is contained in:
Scott Moser 2018-06-08 12:21:28 -04:00 committed by GitHub
parent 7bf11ef883
commit 777610572b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 0 deletions

View File

@ -8,6 +8,8 @@ Network:
accept-default: yes
Proxy:
proxy: ""
Mirror:
mirror: "http://us.archive.ubuntu.com"
Filesystem:
guided: yes
guided-index: 0

View File

@ -19,6 +19,7 @@ from .installpath import InstallpathController
from .installprogress import InstallProgressController
from .keyboard import KeyboardController
from .proxy import ProxyController
from .mirror import MirrorController
from subiquitycore.controllers.login import LoginController
from subiquitycore.controllers.network import NetworkController
from .snaplist import SnapListController
@ -30,6 +31,7 @@ __all__ = [
'InstallProgressController',
'KeyboardController',
'ProxyController',
'MirrorController',
'LoginController',
'NetworkController',
'SnapListController',

View File

@ -0,0 +1,42 @@
# Copyright 2018 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 subiquity.ui.views.mirror import MirrorView
log = logging.getLogger('subiquity.controllers.mirror')
class MirrorController(BaseController):
def __init__(self, common):
super().__init__(common)
self.model = self.base_model.mirror
self.answers = self.all_answers.get('Mirror', {})
def default(self):
self.ui.set_body(MirrorView(self.model, self))
if 'mirror' in self.answers:
self.done(self.answers['mirror'])
def cancel(self):
self.signal.emit_signal('prev-screen')
def done(self, mirror):
if mirror != self.model.mirror:
self.model.mirror = mirror
self.signal.emit_signal('next-screen')

View File

@ -36,6 +36,7 @@ class Subiquity(Application):
"Installpath",
"Network",
"Proxy",
"Mirror",
"Filesystem",
"Identity",
"SnapList",

View File

@ -0,0 +1,26 @@
# Copyright 2018 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
log = logging.getLogger('subiquitycore.models.mirror')
DEFAULT_MIRROR = 'http://archive.ubuntu.com/ubuntu'
class MirrorModel(object):
def __init__(self):
self.mirror = DEFAULT_MIRROR

View File

@ -26,6 +26,7 @@ from .installpath import InstallpathModel
from .keyboard import KeyboardModel
from .locale import LocaleModel
from .proxy import ProxyModel
from .mirror import MirrorModel
from .snaplist import SnapListModel
@ -54,6 +55,7 @@ class SubiquityModel:
self.filesystem = FilesystemModel(common['prober'])
self.identity = IdentityModel()
self.proxy = ProxyModel()
self.mirror = MirrorModel()
self.snaplist = SnapListModel()
def _cloud_init_config(self):
@ -124,6 +126,9 @@ class SubiquityModel:
'apt': {
'http_proxy': self.proxy.proxy,
'https_proxy': self.proxy.proxy,
'primary': [{'arches': ["default"],
'uri': self.mirror.mirror}],
'preserve_sources_list': False,
},
'install': {

View File

@ -0,0 +1,64 @@
# Copyright 2018 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/>.
""" Mirror View.
Select the Ubuntu archive mirror.
"""
import logging
from urwid import connect_signal
from subiquitycore.view import BaseView
from subiquitycore.ui.form import (
Form,
URLField,
)
from subiquity.models.mirror import DEFAULT_MIRROR
log = logging.getLogger('subiquity.ui.mirror')
mirror_help = _(
"You may provide an archive mirror that will be used instead "
"of the default '" + DEFAULT_MIRROR + "'")
class MirrorForm(Form):
url = URLField(_("Mirror address:"), help=mirror_help)
class MirrorView(BaseView):
title = _("Configure Ubuntu archive mirror")
excerpt = _("If you use an alternative mirror for Ubuntu, enter its"
"details here.")
def __init__(self, model, controller):
self.model = model
self.controller = controller
self.form = MirrorForm(initial={'url': self.model.mirror})
connect_signal(self.form, 'submit', self.done)
connect_signal(self.form, 'cancel', self.cancel)
super().__init__(self.form.as_screen(excerpt=_(self.excerpt)))
def done(self, result):
log.debug("User input: {}".format(result.as_data()))
self.controller.done(result.url.value)
def cancel(self, result=None):
self.controller.cancel()