display information about partitions in delete confirmation

For a while subiquity only allowed you to delete RAIDs/VGs with no
partitions. Now that we do, include information about the doomed
partitions in the confirmation dialog.
This commit is contained in:
Michael Hudson-Doyle 2019-05-28 12:49:39 +12:00
parent 97d5248aef
commit 35b16acee1
1 changed files with 39 additions and 12 deletions

View File

@ -17,9 +17,15 @@ import logging
from urwid import Text
from subiquitycore.ui.buttons import danger_btn, other_btn
from subiquitycore.ui.table import (
TablePile,
TableRow,
)
from subiquitycore.ui.utils import button_pile
from subiquitycore.ui.stretchy import Stretchy
from .helpers import summarize_device
log = logging.getLogger('subiquity.ui.filesystem.disk_info')
@ -30,37 +36,58 @@ class ConfirmDeleteStretchy(Stretchy):
self.parent = parent
self.obj = obj
title = _("Confirm deletion of {}").format(obj.desc())
lines = [
_("Do you really want to delete {}?").format(obj.label),
"",
Text(_("Do you really want to delete the {desc} {label}?").format(
desc=obj.desc(), label=obj.label)),
Text(""),
]
stretchy_index = 0
fs = obj.fs()
if fs is not None:
m = fs.mount()
if m is not None:
lines.append(_(
lines.append(Text(_(
"It is formatted as {fstype} and mounted at "
"{path}").format(
fstype=fs.fstype,
path=m.path))
path=m.path)))
else:
lines.append(_(
lines.append(Text(_(
"It is formatted as {fstype} and not mounted.").format(
fstype=fs.fstype))
fstype=fs.fstype)))
elif hasattr(obj, 'partitions') and len(obj.partitions()) > 0:
n = len(obj.partitions())
if obj.type == "lvm_volgroup":
if n == 1:
things = _("logical volume")
else:
lines.append(_("It is not formatted or mounted."))
things = _("logical volumes")
else:
if n == 1:
things = _("partition")
else:
things = _("partitions")
lines.append(Text(_("It contains {n} {things}:").format(
n=n, things=things)))
lines.append(Text(""))
stretchy_index = len(lines)
rows = []
for p, cells in summarize_device(obj):
if p not in [None, obj]:
rows.append(TableRow(cells))
lines.append(TablePile(rows))
else:
lines.append(Text(_("It is not formatted or mounted.")))
delete_btn = danger_btn(label=_("Delete"), on_press=self.confirm)
widgets = [
Text("\n".join(lines)),
widgets = lines + [
Text(""),
button_pile([
delete_btn,
other_btn(label=_("Cancel"), on_press=self.cancel),
]),
]
super().__init__(title, widgets, 0, 2)
super().__init__("", widgets, stretchy_index, len(lines)+1)
def confirm(self, sender=None):
self.parent.controller.delete(self.obj)