add ok_for_raid property, enable/disable create raid button as appropriate
This commit is contained in:
parent
e0eeeadd28
commit
bb939b5be7
|
@ -199,6 +199,11 @@ class _Formattable(ABC):
|
|||
assert action in self.supported_actions
|
||||
return getattr(self, "_can_" + action.name)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def ok_for_raid(self):
|
||||
pass
|
||||
|
||||
|
||||
# Nothing is put in the first and last megabytes of the disk to allow
|
||||
# space for the GPT data.
|
||||
|
@ -360,6 +365,8 @@ class Disk(_Device):
|
|||
not self.grub_device and self._fs is None
|
||||
and self._constructed_device is None)
|
||||
|
||||
ok_for_raid = _can_FORMAT
|
||||
|
||||
|
||||
@attr.s(cmp=False)
|
||||
class Partition(_Formattable):
|
||||
|
@ -405,6 +412,16 @@ class Partition(_Formattable):
|
|||
_can_DELETE = property(
|
||||
lambda self: self.flag not in ('boot', 'bios_grub'))
|
||||
|
||||
@property
|
||||
def ok_for_raid(self):
|
||||
if self.flag:
|
||||
return False
|
||||
if self._fs is not None:
|
||||
return False
|
||||
if self._constructed_device is not None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@attr.s(cmp=False)
|
||||
class Raid(_Device):
|
||||
|
@ -445,6 +462,14 @@ class Raid(_Device):
|
|||
def path(self):
|
||||
return "/dev/{}".format(self.name)
|
||||
|
||||
@property
|
||||
def ok_for_raid(self):
|
||||
if self._fs is not None:
|
||||
return False
|
||||
if self._constructed_device is not None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@attr.s(cmp=False)
|
||||
class Filesystem:
|
||||
|
|
|
@ -176,7 +176,6 @@ class MountList(WidgetWrap):
|
|||
self._no_mounts_content = Color.info_minor(
|
||||
Text(_("No disks or partitions mounted.")))
|
||||
super().__init__(self.table)
|
||||
self.refresh_model_inputs()
|
||||
|
||||
def _mount_action(self, sender, action, mount):
|
||||
log.debug('_mount_action %s %s', action, mount)
|
||||
|
@ -276,9 +275,6 @@ class DeviceList(WidgetWrap):
|
|||
text = _("No used devices")
|
||||
self._no_devices_content = Color.info_minor(Text(text))
|
||||
super().__init__(self.table)
|
||||
self.refresh_model_inputs()
|
||||
# I don't really know why this is required:
|
||||
self.table._select_first_selectable()
|
||||
|
||||
_disk_INFO = _stretchy_shower(DiskInfoStretchy)
|
||||
_disk_PARTITION = _stretchy_shower(PartitionStretchy)
|
||||
|
@ -462,9 +458,9 @@ class FilesystemView(BaseView):
|
|||
self.avail_list = DeviceList(self, True)
|
||||
self.used_list = DeviceList(self, False)
|
||||
self.avail_list.table.bind(self.used_list.table)
|
||||
self._create_raid_btn = menu_btn(
|
||||
self._create_raid_btn = Toggleable(menu_btn(
|
||||
label=_("Create software RAID (md)"),
|
||||
on_press=self.create_raid)
|
||||
on_press=self.create_raid))
|
||||
|
||||
bp = button_pile([self._create_raid_btn])
|
||||
bp.align = 'left'
|
||||
|
@ -494,12 +490,12 @@ class FilesystemView(BaseView):
|
|||
focus_buttons=self.model.can_install())
|
||||
frame.width = ('relative', 95)
|
||||
super().__init__(frame)
|
||||
self.refresh_model_inputs()
|
||||
log.debug('FileSystemView init complete()')
|
||||
|
||||
def _build_buttons(self):
|
||||
log.debug('FileSystemView: building buttons')
|
||||
self.done = Toggleable(done_btn(_("Done"), on_press=self.done))
|
||||
self.done.enabled = self.model.can_install()
|
||||
|
||||
return [
|
||||
self.done,
|
||||
|
@ -508,14 +504,19 @@ class FilesystemView(BaseView):
|
|||
]
|
||||
|
||||
def refresh_model_inputs(self):
|
||||
raid_devices = set()
|
||||
for d in self.model.all_devices():
|
||||
if d.ok_for_raid:
|
||||
raid_devices.add(d)
|
||||
for p in d.partitions():
|
||||
if p.ok_for_raid:
|
||||
raid_devices.add(p)
|
||||
self._create_raid_btn.enabled = len(raid_devices) > 1
|
||||
self.mount_list.refresh_model_inputs()
|
||||
self.avail_list.refresh_model_inputs()
|
||||
self.used_list.refresh_model_inputs()
|
||||
# If refreshing the view has left the focus widget with no
|
||||
# selectable widgets, simulate a tab to move to the next
|
||||
# selectable widget.
|
||||
while not self.lb.base_widget.focus.selectable():
|
||||
self.lb.base_widget.keypress((10, 10), 'tab')
|
||||
# This is an awful hack, actual thinking required:
|
||||
self.lb.base_widget._select_first_selectable()
|
||||
self.done.enabled = self.model.can_install()
|
||||
|
||||
def create_raid(self, button=None):
|
||||
|
|
|
@ -54,10 +54,8 @@ from subiquitycore.ui.utils import (
|
|||
from .partition import FSTypeField
|
||||
from subiquity.ui.mount import MountField
|
||||
from subiquity.models.filesystem import (
|
||||
DeviceAction,
|
||||
get_raid_size,
|
||||
humanize_size,
|
||||
Partition,
|
||||
raidlevels,
|
||||
raidlevels_by_value,
|
||||
)
|
||||
|
@ -346,15 +344,7 @@ class RaidStretchy(Stretchy):
|
|||
return False
|
||||
if dev in cur_devices:
|
||||
return True
|
||||
if dev.fs():
|
||||
return False
|
||||
if dev in cur_devices:
|
||||
return True
|
||||
if dev.constructed_device() is not None:
|
||||
return False
|
||||
if isinstance(dev, Partition):
|
||||
return not dev.flag
|
||||
return dev.action_possible(DeviceAction.FORMAT)
|
||||
return dev.ok_for_raid
|
||||
|
||||
for dev in self.parent.model.all_devices():
|
||||
if device_ok(dev):
|
||||
|
|
Loading…
Reference in New Issue