handle in use partitions in server ui a bit

This commit is contained in:
Michael Hudson-Doyle 2023-07-10 16:07:18 +12:00
parent 9d050d4049
commit c147945e10
4 changed files with 18 additions and 4 deletions

View File

@ -168,7 +168,13 @@ def _can_edit_generic(device):
cdname=labels.label(cd))
_can_edit.register(Partition, _can_edit_generic)
@_can_edit.register(Partition)
def _can_edit_partition(partition):
if partition._is_in_use:
return False
return _can_edit_generic(partition)
_can_edit.register(LVM_LogicalVolume, _can_edit_generic)
@ -203,6 +209,8 @@ _can_reformat = make_checker(DeviceAction.REFORMAT)
@_can_reformat.register(Disk)
@_can_reformat.register(Raid)
def _can_reformat_device(device):
if device._has_in_use_partition:
return False
if len(device._partitions) == 0:
return False
for p in device._partitions:
@ -288,6 +296,8 @@ def _can_delete_generic(device):
@_can_delete.register(Partition)
def _can_delete_partition(partition):
if partition._is_in_use:
return False
if partition.device._has_preexisting_partition():
return _("Cannot delete a single partition from a device that "
"already has partitions.")

View File

@ -233,6 +233,8 @@ def _usage_labels_generic(device, *, exclude_final_unused=False):
if m:
# A filesytem
r.append(_("mounted at {path}").format(path=m.path))
elif device._is_in_use:
r.append(_("in use"))
elif not boot.is_esp(device):
# A filesytem
r.append(_("not mounted"))

View File

@ -580,6 +580,8 @@ class _Device(_Formattable, ABC):
# with a fs that needs to be mounted and is not mounted
if self._constructed_device is not None:
return False
if self._is_in_use:
return False
if self._fs is not None:
return self._fs._available()
from subiquity.common.filesystem.gaps import (
@ -762,6 +764,8 @@ class Partition(_Formattable):
def available(self):
if self.flag in ['bios_grub', 'prep'] or self.grub_device:
return False
if self._is_in_use:
return False
if self._constructed_device is not None:
return False
if self._fs is None:

View File

@ -66,7 +66,6 @@ from subiquity.common.filesystem.actions import (
from subiquity.common.filesystem import boot, gaps, labels
from subiquity.models.filesystem import (
humanize_size,
Disk,
)
from .delete import ConfirmDeleteStretchy, ConfirmReformatStretchy
@ -377,9 +376,8 @@ class DeviceList(WidgetWrap):
def refresh_model_inputs(self):
devices = [
d for d in self.parent.model.all_devices()
if ((d.available() == self.show_available
if (d.available() == self.show_available
or (not self.show_available and d.has_unavailable_partition()))
and (not isinstance(d, Disk) or not d._has_in_use_partition))
]
if len(devices) == 0:
self._w = Padding.push_2(self._no_devices_content)