add a bare-bones proxy model/view/controller

This commit is contained in:
Michael Hudson-Doyle 2018-04-09 14:59:53 +12:00
parent 028914da97
commit 13eaa5c9dc
9 changed files with 149 additions and 9 deletions

View File

@ -6,6 +6,8 @@ Installpath:
path: ubuntu
Network:
accept-default: yes
Proxy:
proxy: ""
Filesystem:
guided: yes
guided-index: 0

View File

@ -21,4 +21,5 @@ from .installpath import InstallpathController # NOQA
from .installprogress import InstallProgressController # NOQA
from .filesystem import FilesystemController # NOQA
from .keyboard import KeyboardController # NOQA
from .proxy import ProxyController # NOQA
from .welcome import WelcomeController # NOQA

View File

@ -0,0 +1,45 @@
# 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.proxy import ProxyView
log = logging.getLogger('subiquity.controllers.proxy')
class ProxyController(BaseController):
def __init__(self, common):
super().__init__(common)
self.model = self.base_model.proxy
self.answers = self.all_answers.get('Proxy', {})
def default(self):
title = _("Configure proxy")
excerpt = _("If this system requires a proxy to connect to the internet, enter its details here.")
self.ui.set_header(title, excerpt)
self.ui.set_body(ProxyView(self.model, self))
if 'proxy' in self.answers:
self.done(self.answers['proxy'])
def cancel(self):
self.signal.emit_signal('prev-screen')
def done(self, proxy):
self.model.proxy = proxy
self.signal.emit_signal('next-screen')

View File

@ -35,6 +35,7 @@ class Subiquity(Application):
"Keyboard",
"Installpath",
"Network",
"Proxy",
"Filesystem",
"Identity",
"InstallProgress",

24
subiquity/models/proxy.py Normal file
View File

@ -0,0 +1,24 @@
# 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.proxy')
class ProxyModel(object):
def __init__(self):
self.proxy = ""

View File

@ -25,6 +25,7 @@ from .filesystem import FilesystemModel
from .installpath import InstallpathModel
from .keyboard import KeyboardModel
from .locale import LocaleModel
from .proxy import ProxyModel
def setup_yaml():
@ -48,6 +49,7 @@ class SubiquityModel:
self.network = NetworkModel(support_wlan=False)
self.filesystem = FilesystemModel(common['prober'])
self.identity = IdentityModel()
self.proxy = ProxyModel()
def _cloud_init_config(self):
user = self.identity.user
@ -140,6 +142,12 @@ class SubiquityModel:
},
}
if self.proxy.proxy != "":
config['proxy'] = {
'http_proxy': self.proxy.proxy,
'https_proxy': self.proxy.proxy,
}
if not self.filesystem.add_swapfile():
config['swap'] = {'size': 0}

View File

@ -23,15 +23,13 @@ import re
from urwid import connect_signal, Text
from subiquitycore.ui.buttons import back_btn, forward_btn
from subiquitycore.ui.interactive import StringEditor
from subiquitycore.ui.utils import Padding, button_pile, screen
from subiquitycore.ui.utils import Padding, button_pile
from subiquitycore.ui.container import ListBox, Pile
from subiquitycore.view import BaseView
from subiquity.ui.views.identity import UsernameField, PasswordField, USERNAME_MAXLEN
from subiquitycore.ui.form import (
simple_field,
Form,
WantsToKnowFormField,
URLField,
)
@ -68,11 +66,6 @@ class InstallpathView(BaseView):
def cancel(self, button=None):
self.controller.cancel()
class URLEditor(StringEditor, WantsToKnowFormField):
pass
URLField = simple_field(URLEditor)
class RegionForm(Form):
username = UsernameField(

View File

@ -0,0 +1,60 @@
# 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/>.
""" Install Path
Provides high level options for Ubuntu install
"""
import logging
from urwid import connect_signal
from subiquitycore.view import BaseView
from subiquitycore.ui.form import (
Form,
URLField,
)
log = logging.getLogger('subiquity.installpath')
class ProxyForm(Form):
url = URLField(
_("Proxy address:"),
help=_(
"The address of the proxy."))
class ProxyView(BaseView):
def __init__(self, model, controller):
self.model = model
self.controller = controller
self.form = ProxyForm(initial={'url': self.model.proxy})
connect_signal(self.form, 'submit', self.done)
connect_signal(self.form, 'cancel', self.cancel)
super().__init__(self.form.as_screen(self))
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()

View File

@ -259,6 +259,12 @@ PasswordField = simple_field(PasswordEditor)
IntegerField = simple_field(IntegerEditor)
class URLEditor(StringEditor, WantsToKnowFormField):
pass
URLField = simple_field(URLEditor)
class ChoiceField(FormField):
def __init__(self, caption=None, help=None, choices=[]):