first cut at snaplist view

This commit is contained in:
Michael Hudson-Doyle 2018-05-11 16:30:41 +12:00
parent e2ec77d475
commit f4f5d58026
6 changed files with 87 additions and 6 deletions

View File

@ -22,4 +22,5 @@ from .installprogress import InstallProgressController # NOQA
from .filesystem import FilesystemController # NOQA
from .keyboard import KeyboardController # NOQA
from .proxy import ProxyController # NOQA
from .snaplist import SnapListController
from .welcome import WelcomeController # NOQA

View File

@ -17,7 +17,7 @@ import logging
from subiquitycore.controller import BaseController
from subiquity.ui.views import SnapListView
from subiquity.ui.views.snaplist import SnapListView
log = logging.getLogger('subiquity.controllers.snaplist')
@ -26,8 +26,17 @@ class SnapListController(BaseController):
def __init__(self, common):
super().__init__(common)
self.model = self.all_model.SnapList
self.model = self.base_model.snaplist
def default(self):
self.ui.set_header(
_("Featured Server Snaps"),
_("These are popular snaps in server environments. Select or deselect with SPACE, press ENTER to see more details of the package, publisher and versions available."),
)
self.ui.set_body(SnapListView(self.model, self))
def done(self, snaps_to_install):
self.signal.emit_signal("next-screen")
def cancel(self, sender=None):
self.signal.emit_signal("prev-screen")

View File

@ -38,6 +38,7 @@ class Subiquity(Application):
"Proxy",
"Filesystem",
"Identity",
"SnapList",
"InstallProgress",
]

View File

@ -13,6 +13,9 @@
# 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 json
import os
import attr
@attr.s(cmp=False)
@ -40,10 +43,21 @@ class SnapListModel:
pass
def get_snap_list(self):
return [
Snap("etcd", "Resilient key-value store by CoreOS", "tvansteenburgh", "Etcd is a high availability key-value store, implementing the RAFT algorithm to deal with failover within the etcd cluster. Popular in the Docker community as a shared store of small but important data in a distributed application."),
]
opd = os.path.dirname
opj = os.path.join
snap_data_dir = opj(opd(opd(opd(__file__))), 'examples', 'snaps')
snap_find_output = opj(snap_data_dir, 'find-output.json')
with open(snap_find_output) as fp:
data = json.load(fp)
r = []
for s in data['result']:
kw = {}
kw['name'] = s['name']
kw['summary'] = s['summary']
kw['publisher'] = s['developer']
kw['description'] = s['description']
r.append(SnapInfo(**kw))
return r
def set_installed_list(self, to_install):
self.to_install = to_install

View File

@ -26,6 +26,7 @@ from .installpath import InstallpathModel
from .keyboard import KeyboardModel
from .locale import LocaleModel
from .proxy import ProxyModel
from .snaplist import SnapListModel
def setup_yaml():
@ -50,6 +51,7 @@ class SubiquityModel:
self.filesystem = FilesystemModel(common['prober'])
self.identity = IdentityModel()
self.proxy = ProxyModel()
self.snaplist = SnapListModel(common)
def _cloud_init_config(self):
user = self.identity.user

View File

@ -0,0 +1,54 @@
# Copyright 2015 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 urwid import (
CheckBox,
Text,
)
from subiquitycore.ui.buttons import ok_btn, cancel_btn
from subiquitycore.ui.container import Columns
from subiquitycore.ui.utils import button_pile, Color, screen
from subiquitycore.view import BaseView
log = logging.getLogger("subiquity.views.welcome")
class SnapListView(BaseView):
def __init__(self, model, controller):
self.model = model
self.controller = controller
self.to_install = []
body = []
snaps = self.model.get_snap_list()
name_len = max([len(snap.name) for snap in snaps])
for snap in snaps:
body.append(Color.menu_button(Columns([
(name_len+4, CheckBox(snap.name)),
Text(snap.summary, wrap='clip'),
], dividechars=1)))
ok = ok_btn(label=_("OK"), on_press=self.done)
cancel = cancel_btn(label=_("Cancel"), on_press=self.done)
super().__init__(screen(body, button_pile([ok, cancel])))
def done(self, sender=None):
self.controller.done(self.to_install)
def cancel(self, sender=None):
self.controller.cancel()