move "usage labels" from filesystem view to model objects
So the logic can be reused.
This commit is contained in:
parent
f45880944e
commit
3bad9e408a
|
@ -386,6 +386,28 @@ class _Formattable(ABC):
|
|||
# Raid or LVM_VolGroup for now, but one day ZPool, BCache...
|
||||
_constructed_device = attributes.backlink()
|
||||
|
||||
def usage_labels(self):
|
||||
cd = self.constructed_device()
|
||||
if cd is not None:
|
||||
return [
|
||||
_("{component_name} of {desc} {name}").format(
|
||||
component_name=cd.component_name,
|
||||
desc=cd.desc(),
|
||||
name=cd.name),
|
||||
]
|
||||
fs = self.fs()
|
||||
if fs is not None:
|
||||
r = [_("formatted as {fstype}").format(fstype=fs.fstype)]
|
||||
if self._m.is_mounted_filesystem(fs.fstype):
|
||||
m = fs.mount()
|
||||
if m:
|
||||
r.append(_("mounted at {path}").format(path=m.path))
|
||||
else:
|
||||
r.append(_("not mounted"))
|
||||
return r
|
||||
else:
|
||||
return [_("unused")]
|
||||
|
||||
def _is_entirely_used(self):
|
||||
return self._fs is not None or self._constructed_device is not None
|
||||
|
||||
|
@ -657,6 +679,11 @@ class Partition(_Formattable):
|
|||
r.append("bios_grub")
|
||||
return r
|
||||
|
||||
def usage_labels(self):
|
||||
if self.flag == "prep" or self.flag == "bios_grub":
|
||||
return []
|
||||
return super().usage_labels()
|
||||
|
||||
def desc(self):
|
||||
return _("partition of {}").format(self.device.desc())
|
||||
|
||||
|
|
|
@ -246,6 +246,16 @@ class TestFilesystemModel(unittest.TestCase):
|
|||
self.assertFalse(lv.ok_for_raid)
|
||||
self.assertFalse(lv.ok_for_lvm_vg)
|
||||
|
||||
def test_partition_usage_labels(self):
|
||||
model, partition = make_model_and_partition()
|
||||
self.assertEqual(partition.usage_labels(), ["unused"])
|
||||
fs = model.add_filesystem(partition, 'ext4')
|
||||
self.assertEqual(
|
||||
partition.usage_labels(), ["formatted as ext4", "not mounted"])
|
||||
model.add_mount(fs, '/')
|
||||
self.assertEqual(
|
||||
partition.usage_labels(), ["formatted as ext4", "mounted at /"])
|
||||
|
||||
def assertActionNotSupported(self, obj, action):
|
||||
self.assertNotIn(action, obj.supported_actions)
|
||||
|
||||
|
|
|
@ -378,27 +378,15 @@ class DeviceList(WidgetWrap):
|
|||
log.debug('FileSystemView: building device list')
|
||||
rows = []
|
||||
|
||||
def _usage_label(obj):
|
||||
cd = obj.constructed_device()
|
||||
if cd is not None:
|
||||
return _("{component_name} of {name}").format(
|
||||
component_name=cd.component_name, name=cd.name)
|
||||
fs = obj.fs()
|
||||
if fs is not None:
|
||||
if not self.parent.model.is_mounted_filesystem(fs.fstype):
|
||||
return _("formatted as {fstype}").format(
|
||||
fstype=fs.fstype)
|
||||
else:
|
||||
m = fs.mount()
|
||||
if m:
|
||||
return _(
|
||||
"formatted as {fstype}, mounted at {path}").format(
|
||||
fstype=fs.fstype, path=m.path)
|
||||
else:
|
||||
return _("formatted as {fstype}, not mounted").format(
|
||||
fstype=fs.fstype)
|
||||
else:
|
||||
return _("unused")
|
||||
def _append_usage_labels(obj, indent):
|
||||
label = ", ".join(obj.usage_labels())
|
||||
if label:
|
||||
rows.append(TableRow([
|
||||
Text(""),
|
||||
(3, Text(indent + label)),
|
||||
Text(""),
|
||||
Text(""),
|
||||
]))
|
||||
|
||||
rows.append(TableRow([Color.info_minor(heading) for heading in [
|
||||
Text(" "),
|
||||
|
@ -425,12 +413,7 @@ class DeviceList(WidgetWrap):
|
|||
rows.append(row)
|
||||
|
||||
if not device.partitions():
|
||||
rows.append(TableRow([
|
||||
Text(""),
|
||||
(3, Text(" " + _usage_label(device))),
|
||||
Text(""),
|
||||
Text(""),
|
||||
]))
|
||||
_append_usage_labels(device, " ")
|
||||
else:
|
||||
for part in device.partitions():
|
||||
if part.available() != self.show_available:
|
||||
|
@ -452,14 +435,7 @@ class DeviceList(WidgetWrap):
|
|||
]
|
||||
row = make_action_menu_row(cells, menu, cursor_x=4)
|
||||
rows.append(row)
|
||||
if part.flag in ["bios_grub", "prep"]:
|
||||
continue
|
||||
rows.append(TableRow([
|
||||
Text(""),
|
||||
(3, Text(" " + _usage_label(part))),
|
||||
Text(""),
|
||||
Text(""),
|
||||
]))
|
||||
_append_usage_labels(part, " ")
|
||||
if (self.show_available
|
||||
and device.used > 0
|
||||
and device.free_for_partitions > 0):
|
||||
|
|
Loading…
Reference in New Issue