track confinement of snaps and seed classic snaps appropriately

This commit is contained in:
Michael Hudson-Doyle 2018-05-22 13:39:01 +12:00
parent 4f0ec36a97
commit 18ba5cbac3
3 changed files with 15 additions and 10 deletions

View File

@ -127,8 +127,10 @@ class UpdateSnapSeed(BackgroundTask):
seedinfo = {
'name': snap_name,
'file': snap_file,
'channel': self.controller.base_model.snaplist.to_install[snap_name],
'channel': self.controller.base_model.snaplist.to_install[snap_name][0],
}
if self.controller.base_model.snaplist.to_install[snap_name][1]:
seedinfo['classic'] = True
seed['snaps'].append(seedinfo)
os.rmdir(self._tmp_dir)
@ -346,7 +348,7 @@ class InstallProgressController(BaseController):
tasks = [
('drain', WaitForCurtinEventsTask(self)),
]
for snap_name, channel in sorted(self.base_model.snaplist.to_install.items()):
for snap_name, (channel, is_classic) in sorted(self.base_model.snaplist.to_install.items()):
tasks.append(("snapdownload", DownloadSnapTask(self, tmp_dir, snap_name, channel)))
tasks.append(("snapseed", UpdateSnapSeed(self, root)))
ts = TaskSequence(self.run_in_bg, tasks, w(self))

View File

@ -28,6 +28,7 @@ class SnapInfo:
summary = attr.ib()
publisher = attr.ib()
description = attr.ib()
confinement = attr.ib()
channels = attr.ib(default=attr.Factory(list))
@ -46,6 +47,7 @@ class SnapListModel:
def __init__(self, common):
self._snap_info = []
self._snaps_by_name = {}
self.to_install = {} # snap_name -> (channel, is_classic)
def _from_snapd_info(self, name):
sock = "/run/snapd.socket"
@ -62,6 +64,7 @@ class SnapListModel:
summary=s['summary'],
publisher=s['developer'],
description=s['description'],
confinement=s['confinement'],
)
self._snap_info.append(snap)
self._snaps_by_name[s['name']] = snap

View File

@ -66,7 +66,7 @@ class SnapInfoView(Widget):
_sizing = frozenset([BOX])
description_index = 5
channels_index = 7
def __init__(self, parent, snap, cur_risk):
def __init__(self, parent, snap, cur_channel):
self.parent = parent
self.snap = snap
self.channels = []
@ -84,9 +84,9 @@ class SnapInfoView(Widget):
btn = StarRadioButton(
radio_group,
"{}:".format(csi.channel_name),
state=csi.channel_name == cur_risk,
state=csi.channel_name == cur_channel,
on_state_change=self.state_change,
user_data=csi.channel_name)
user_data=(csi.channel_name, csi.confinement == "classic"))
self.channels.append(Color.menu_button(Columns([
(channel_width, btn),
(max_version, Text(csi.version)),
@ -112,10 +112,10 @@ class SnapInfoView(Widget):
])
def close(self, sender=None):
self.parent._w = self.parent.main_screen
def state_change(self, sender, state, risk):
def state_change(self, sender, state, user_data):
if state:
self.parent.snap_rows[self.snap.name].box.set_state(True)
self.parent.to_install[self.snap.name] = risk
self.parent.to_install[self.snap.name] = user_data
def keypress(self, size, key):
return self.pile.keypress(size, key)
def render(self, size, focus):
@ -197,7 +197,7 @@ class SnapListRow(WidgetWrap):
fi.close()
if len(self.snap.channels) == 0: # or other indication of failure
pass # XXX show a 'failed' message, allow retrying
self.parent._w = SnapInfoView(self.parent, self.snap, self.parent.to_install.get(self.snap.name))
self.parent._w = SnapInfoView(self.parent, self.snap, self.parent.to_install.get(self.snap.name, (None,))[0])
self.parent.controller.get_snap_info(self.snap, callback)
# If we didn't get callback synchronously, display a dialog while the info loads.
if not called:
@ -207,7 +207,7 @@ class SnapListRow(WidgetWrap):
return super().keypress(size, key)
def state_change(self, sender, new_state):
if new_state:
self.parent.to_install[self.snap.name] = 'stable'
self.parent.to_install[self.snap.name] = ('stable', self.snap.confinement == "classic")
else:
self.parent.to_install.pop(self.snap.name, None)
def render(self, size, focus):
@ -222,7 +222,7 @@ class SnapListView(BaseView):
def __init__(self, model, controller):
self.model = model
self.controller = controller
self.to_install = {} # {snap_name: risk}
self.to_install = {} # {snap_name: (channel, is_classic)}
called = False
spinner = None
def callback(snap_list):