Introduce the idea of filesystem action annotations

This generalizes the way we display if a VG is encrypted and the way we
display the bootloader partitions, and will be how new/existing is
displayed when reusing existing partitions happens.
This commit is contained in:
Michael Hudson-Doyle 2019-05-02 15:16:22 +12:00
parent 5ba1357207
commit 6041f138ed
2 changed files with 37 additions and 9 deletions

View File

@ -320,6 +320,15 @@ class _Formattable(ABC):
# Base class for anything that can be formatted and mounted,
# e.g. a disk or a RAID or a partition.
@property
@abstractmethod
def label(self):
pass
@property
def annotations(self):
return []
# Filesystem
_fs = attr.ib(default=None, repr=False)
# Raid or LVM_VolGroup for now, but one day ZPool, BCache...
@ -564,6 +573,17 @@ class Partition(_Formattable):
flag = attr.ib(default=None)
preserve = attr.ib(default=False)
@property
def annotations(self):
r = super().annotations
if self.flag == "prep":
r.append("PReP")
elif self.flag == "boot":
r.append("ESP")
elif self.flag == "bios_grub":
r.append("bios_grub")
return r
def desc(self):
return _("partition of {}").format(self.device.desc())
@ -701,6 +721,14 @@ class LVM_VolGroup(_Device):
def free_for_partitions(self):
return self.size - self.used
@property
def annotations(self):
r = super().annotations
member = next(iter(self.devices))
if member.type == "dm_crypt":
r.append("encrypted")
return r
@property
def label(self):
return self.name

View File

@ -407,10 +407,8 @@ class DeviceList(WidgetWrap):
for device in devices:
menu = self._action_menu_for_device(device)
label = device.label
if device.type == "lvm_volgroup":
member = next(iter(device.devices))
if member.type == "dm_crypt":
label += _(" (encrypted)")
if device.annotations:
label = "{} ({})".format(label, ", ".join(device.annotations))
cells = [
Text("["),
Text(label),
@ -437,9 +435,13 @@ class DeviceList(WidgetWrap):
part_size = "{:>9} ({}%)".format(
humanize_size(part.size),
int(100 * part.size / device.size))
part_label = part.short_label
if part.annotations:
part_label = "{} ({})".format(
part_label, ", ".join(part.annotations))
cells = [
Text("["),
Text(" " + part.short_label),
Text(" " + part_label),
(2, Text(part_size)),
menu,
Text("]"),
@ -447,12 +449,10 @@ class DeviceList(WidgetWrap):
row = make_action_menu_row(cells, menu, cursor_x=4)
rows.append(row)
if part.flag in ["bios_grub", "prep"]:
label = part.flag
else:
label = _usage_label(part)
continue
rows.append(TableRow([
Text(""),
(3, Text(" " + label)),
(3, Text(" " + _usage_label(part))),
Text(""),
Text(""),
]))