display a message when the user obstinately types in an unsuitable mount point
This commit is contained in:
parent
e79a71fdea
commit
94df386a6c
|
@ -53,6 +53,9 @@ suitable_mountpoints_for_existing_fs = [
|
|||
|
||||
|
||||
class MountSelector(WidgetWrap):
|
||||
|
||||
signals = ['change']
|
||||
|
||||
def __init__(self, mountpoints):
|
||||
opts = []
|
||||
first_opt = None
|
||||
|
@ -101,6 +104,8 @@ class MountSelector(WidgetWrap):
|
|||
self._showhide_other(value == OTHER)
|
||||
if value == OTHER:
|
||||
self._w.focus_position = 1
|
||||
value = "/" + self._other.value
|
||||
self._emit('change', value)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
|
|
|
@ -44,7 +44,11 @@ from subiquity.models.filesystem import (
|
|||
humanize_size,
|
||||
LVM_VolGroup,
|
||||
)
|
||||
from subiquity.ui.mount import MountField
|
||||
from subiquity.ui.mount import (
|
||||
common_mountpoints,
|
||||
MountField,
|
||||
suitable_mountpoints_for_existing_fs,
|
||||
)
|
||||
|
||||
|
||||
log = logging.getLogger('subiquity.ui.filesystem.add_partition')
|
||||
|
@ -99,16 +103,16 @@ class SizeWidget(StringEditor):
|
|||
except ValueError:
|
||||
return
|
||||
if sz > self.form.max_size:
|
||||
self.value = self.form.size_str
|
||||
self.form.size.show_extra(
|
||||
('info_minor',
|
||||
_("Capped partition size at {}").format(self.form.size_str)))
|
||||
self.value = self.form.size_str
|
||||
elif (align_up(sz) != sz and
|
||||
humanize_size(align_up(sz)) != self.form.size.value):
|
||||
sz_str = humanize_size(align_up(sz))
|
||||
self.value = sz_str
|
||||
self.form.size.show_extra(
|
||||
('info_minor', _("Rounded size up to {}").format(sz_str)))
|
||||
self.value = sz_str
|
||||
|
||||
|
||||
class SizeField(FormField):
|
||||
|
@ -173,7 +177,6 @@ class PartitionForm(Form):
|
|||
if fstype is None:
|
||||
if self.existing_fs_type == "swap":
|
||||
show_use = True
|
||||
fstype = self.existing_fs_type
|
||||
if self.form_pile is not None:
|
||||
for i, (w, o) in enumerate(self.form_pile.contents):
|
||||
if w is self.mount._table and show_use:
|
||||
|
@ -181,7 +184,14 @@ class PartitionForm(Form):
|
|||
elif w is self.use_swap._table and not show_use:
|
||||
self.form_pile.contents[i] = (self.mount._table, o)
|
||||
if getattr(self.device, 'flag', None) != "boot":
|
||||
self.mount.enabled = self.model.is_mounted_filesystem(fstype)
|
||||
fstype_for_check = fstype
|
||||
if fstype_for_check is None:
|
||||
fstype_for_check = self.existing_fs_type
|
||||
self.mount.enabled = self.model.is_mounted_filesystem(
|
||||
fstype_for_check)
|
||||
self.fstype.value = fstype
|
||||
self.mount.showing_extra = False
|
||||
self.mount.validate()
|
||||
|
||||
name = LVNameField(_("Name: "))
|
||||
size = SizeField()
|
||||
|
@ -239,6 +249,15 @@ class PartitionForm(Form):
|
|||
if dev is not None:
|
||||
return _("{} is already mounted at {}.").format(
|
||||
dev.label.title(), mount)
|
||||
if self.existing_fs_type is not None:
|
||||
if self.fstype.value is None:
|
||||
if mount in common_mountpoints:
|
||||
if mount not in suitable_mountpoints_for_existing_fs:
|
||||
self.mount.show_extra(
|
||||
('info_error',
|
||||
_("Mounting an existing filesystem at {} is "
|
||||
"usually a bad idea, proceed only with "
|
||||
"caution.").format(mount)))
|
||||
|
||||
def as_rows(self):
|
||||
r = super().as_rows()
|
||||
|
|
|
@ -182,7 +182,7 @@ class BoundFormField(object):
|
|||
return value
|
||||
|
||||
def _change(self, sender, new_val):
|
||||
if self.in_error:
|
||||
if self.in_error or self.showing_extra:
|
||||
self.showing_extra = False
|
||||
# the validator will likely inspect self.value to decide
|
||||
# if the new input is valid. So self.value had better
|
||||
|
|
Loading…
Reference in New Issue