From 13eaa5c9dc996812aacaa47b74ee4db8dbe55613 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 9 Apr 2018 14:59:53 +1200 Subject: [PATCH] add a bare-bones proxy model/view/controller --- examples/answers.yaml | 2 ++ subiquity/controllers/__init__.py | 1 + subiquity/controllers/proxy.py | 45 +++++++++++++++++++++++ subiquity/core.py | 1 + subiquity/models/proxy.py | 24 +++++++++++++ subiquity/models/subiquity.py | 8 +++++ subiquity/ui/views/installpath.py | 11 ++---- subiquity/ui/views/proxy.py | 60 +++++++++++++++++++++++++++++++ subiquitycore/ui/form.py | 6 ++++ 9 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 subiquity/controllers/proxy.py create mode 100644 subiquity/models/proxy.py create mode 100644 subiquity/ui/views/proxy.py diff --git a/examples/answers.yaml b/examples/answers.yaml index 82c6c4bf..e05fa2cf 100644 --- a/examples/answers.yaml +++ b/examples/answers.yaml @@ -6,6 +6,8 @@ Installpath: path: ubuntu Network: accept-default: yes +Proxy: + proxy: "" Filesystem: guided: yes guided-index: 0 diff --git a/subiquity/controllers/__init__.py b/subiquity/controllers/__init__.py index 73b1aa13..ff67cbd5 100644 --- a/subiquity/controllers/__init__.py +++ b/subiquity/controllers/__init__.py @@ -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 diff --git a/subiquity/controllers/proxy.py b/subiquity/controllers/proxy.py new file mode 100644 index 00000000..db88e9bf --- /dev/null +++ b/subiquity/controllers/proxy.py @@ -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 . + +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') diff --git a/subiquity/core.py b/subiquity/core.py index cc761fba..fe5b883c 100644 --- a/subiquity/core.py +++ b/subiquity/core.py @@ -35,6 +35,7 @@ class Subiquity(Application): "Keyboard", "Installpath", "Network", + "Proxy", "Filesystem", "Identity", "InstallProgress", diff --git a/subiquity/models/proxy.py b/subiquity/models/proxy.py new file mode 100644 index 00000000..17d08f0f --- /dev/null +++ b/subiquity/models/proxy.py @@ -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 . + +import logging + +log = logging.getLogger('subiquitycore.models.proxy') + + +class ProxyModel(object): + + def __init__(self): + self.proxy = "" diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index c97c1ac2..d1d78693 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -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} diff --git a/subiquity/ui/views/installpath.py b/subiquity/ui/views/installpath.py index 74e34988..7bd273d6 100644 --- a/subiquity/ui/views/installpath.py +++ b/subiquity/ui/views/installpath.py @@ -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( diff --git a/subiquity/ui/views/proxy.py b/subiquity/ui/views/proxy.py new file mode 100644 index 00000000..d3ff0755 --- /dev/null +++ b/subiquity/ui/views/proxy.py @@ -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 . + +""" 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() diff --git a/subiquitycore/ui/form.py b/subiquitycore/ui/form.py index 452a68d1..d46ec236 100644 --- a/subiquitycore/ui/form.py +++ b/subiquitycore/ui/form.py @@ -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=[]):