class PartitionForm(Form): def __init__(self, mountpoints, max_size, initial, ok_for_slash_boot, lvm_names): self.mountpoints = mountpoints self.ok_for_slash_boot = ok_for_slash_boot self.max_size = max_size if max_size is not None: self.size_str = humanize_size(max_size) self.size.caption = _("Size (max {}):").format(self.size_str) self.lvm_names = lvm_names super().__init__(initial) if max_size is None: self.remove_field('size') connect_signal(self.fstype.widget, 'select', self.select_fstype) self.select_fstype(None, self.fstype.widget.value) def select_fstype(self, sender, fs): self.mount.enabled = fs.is_mounted name = StringField(_("Name: ")) size = SizeField() fstype = FSTypeField(_("Format:")) mount = MountField(_("Mount:")) def clean_size(self, val): if not val: return self.max_size suffixes = ''.join(HUMAN_UNITS) + ''.join(HUMAN_UNITS).lower() if val[-1] not in suffixes: val += self.size_str[-1] if val == self.size_str: return self.max_size else: return dehumanize_size(val) def clean_mount(self, val): if self.fstype.value.is_mounted: return val else: return None def validate_name(self): log.debug("validate_name %s %s", self.name.value, self.lvm_names) if self.name.value in self.lvm_names: return _("There is already a logical volume named {}.").format( self.name.value) def validate_mount(self): mount = self.mount.value if mount is None: return # /usr/include/linux/limits.h:PATH_MAX if len(mount) > 4095: return _('Path exceeds PATH_MAX') dev = self.mountpoints.get(mount) if dev is not None: return _("{} is already mounted at {}.").format( dev.label.title(), mount) if mount == "/boot" and not self.ok_for_slash_boot: return _("/boot must be on a partition of a local disk.")
class RaidForm(Form): def __init__(self, mountpoint_to_devpath_mapping, all_devices, initial, raid_names): self.mountpoint_to_devpath_mapping = mountpoint_to_devpath_mapping self.all_devices = all_devices self.raid_names = raid_names super().__init__(initial) connect_signal(self.fstype.widget, 'select', self.select_fstype) self.select_fstype(None, self.fstype.widget.value) name = StringField(_("Name:")) level = ChoiceField(_("RAID Level:"), choices=raidlevel_choices) devices = MultiDeviceField(_("Devices:")) size = ReadOnlyField(_("Size:")) def select_fstype(self, sender, fs): self.mount.enabled = fs.is_mounted fstype = FSTypeField(_("Format:")) mount = MountField(_("Mount:")) def clean_mount(self, val): if self.fstype.value.is_mounted: return val else: return None def clean_name(self, val): if not re.match('md[0-9]+', val): val = 'md/' + val return val def validate_name(self): if self.name.value in self.raid_names: return _("There is already a RAID named '{}'").format( self.name.value) def validate_devices(self): log.debug( 'validate_devices %s %s', len(self.devices.value), self.level.value) active_device_count = len(self.devices.widget.active_devices) if active_device_count < self.level.value.min_devices: return _( 'RAID Level "{}" requires at least {} active devices').format( self.level.value.name, self.level.value.min_devices) def validate_mount(self): mount = self.mount.value if mount is None: return # /usr/include/linux/limits.h:PATH_MAX if len(mount) > 4095: return _('Path exceeds PATH_MAX') dev = self.mountpoint_to_devpath_mapping.get(mount) if dev is not None: return _("{} is already mounted at {}").format(dev, mount)
class PartitionForm(Form): def __init__(self, mountpoint_to_devpath_mapping, max_size, initial={}): self.mountpoint_to_devpath_mapping = mountpoint_to_devpath_mapping self.max_size = max_size if max_size is not None: self.size_str = humanize_size(max_size) self.size.caption = "Size (max {})".format(self.size_str) super().__init__(initial) if max_size is None: self.remove_field('size') connect_signal(self.fstype.widget, 'select', self.select_fstype) self.select_fstype(None, self.fstype.widget.value) def select_fstype(self, sender, fs): self.mount.enabled = fs.is_mounted size = SizeField() fstype = FSTypeField("Format") mount = MountField("Mount") def clean_size(self, val): if not val: return self.max_size suffixes = ''.join(HUMAN_UNITS) + ''.join(HUMAN_UNITS).lower() if val[-1] not in suffixes: val += self.size_str[-1] if val == self.size_str: return self.max_size else: return dehumanize_size(val) def clean_mount(self, val): if self.fstype.value.is_mounted: return val else: return None def validate_mount(self): mount = self.mount.value if mount is None: return # /usr/include/linux/limits.h:PATH_MAX if len(mount) > 4095: return 'Path exceeds PATH_MAX' dev = self.mountpoint_to_devpath_mapping.get(mount) if dev is not None: return "%s is already mounted at %s"%(dev, mount)
class PartitionForm(Form): def __init__(self, mountpoints, max_size, initial, ok_for_slash_boot, lvm_names): self.mountpoints = mountpoints self.ok_for_slash_boot = ok_for_slash_boot self.max_size = max_size if max_size is not None: self.size_str = humanize_size(max_size) self.size.caption = _("Size (max {}):").format(self.size_str) self.lvm_names = lvm_names super().__init__(initial) if max_size is None: self.remove_field('size') connect_signal(self.fstype.widget, 'select', self.select_fstype) self.select_fstype(None, self.fstype.widget.value) def select_fstype(self, sender, fs): self.mount.enabled = fs.is_mounted name = LVNameField(_("Name: ")) size = SizeField() fstype = FSTypeField(_("Format:")) mount = MountField(_("Mount:")) def clean_size(self, val): if not val: return self.max_size suffixes = ''.join(HUMAN_UNITS) + ''.join(HUMAN_UNITS).lower() if val[-1] not in suffixes: val += self.size_str[-1] if val == self.size_str: return self.max_size else: return dehumanize_size(val) def clean_mount(self, val): if self.fstype.value.is_mounted: return val else: return None def validate_name(self): v = self.name.value if not v: return _("The name of a logical volume cannot be empty") if v.startswith('-'): return _("The name of a logical volume cannot start with a hyphen") if v in ('.', '..', 'snapshot', 'pvmove'): return _("A logical volume may not be called {}").format(v) for substring in ['_cdata', '_cmeta', '_corig', '_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta', '_tdata', '_tmeta', '_vorigin']: if substring in v: return _('The name of a logical volume may not contain ' '"{}"').format(substring) if v in self.lvm_names: return _("There is already a logical volume named {}.").format( self.name.value) def validate_mount(self): mount = self.mount.value if mount is None: return # /usr/include/linux/limits.h:PATH_MAX if len(mount) > 4095: return _('Path exceeds PATH_MAX') dev = self.mountpoints.get(mount) if dev is not None: return _("{} is already mounted at {}.").format( dev.label.title(), mount) if mount == "/boot" and not self.ok_for_slash_boot: return _("/boot must be on a partition of a local disk.")
class PartitionForm(Form): def __init__(self, model, max_size, initial, lvm_names, device): self.model = model self.device = device self.existing_fs_type = None if device: ofstype = device.original_fstype() if ofstype: self.existing_fs_type = ofstype initial_path = initial.get('mount') self.mountpoints = { m.path: m.device.volume for m in self.model.all_mounts() if m.path != initial_path} self.max_size = max_size if max_size is not None: self.size_str = humanize_size(max_size) self.size.caption = _("Size (max {}):").format(self.size_str) self.lvm_names = lvm_names super().__init__(initial) if max_size is None: self.remove_field('size') connect_signal(self.fstype.widget, 'select', self.select_fstype) self.form_pile = None self.select_fstype(None, self.fstype.widget.value) def select_fstype(self, sender, fstype): show_use = False if fstype is None and self.existing_fs_type is not None: self.mount.widget.disable_unsuitable_mountpoints_for_existing_fs() self.mount.value = self.mount.value else: self.mount.widget.enable_common_mountpoints() self.mount.value = self.mount.value if fstype is None: if self.existing_fs_type == "swap": show_use = True 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: self.form_pile.contents[i] = (self.use_swap._table, o) 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": 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() fstype = FSTypeField(_("Format:")) mount = MountField(_("Mount:")) use_swap = BooleanField( _("Use as swap"), help=_("Use this swap partition in the installed system.")) def clean_size(self, val): if not val: return self.max_size suffixes = ''.join(HUMAN_UNITS) + ''.join(HUMAN_UNITS).lower() if val[-1] not in suffixes: val += self.size_str[-1] if val == self.size_str: return self.max_size else: return dehumanize_size(val) def clean_mount(self, val): if self.model.is_mounted_filesystem(self.fstype): return val else: return None def validate_name(self): if self.lvm_names is None: return None v = self.name.value if not v: return _("The name of a logical volume cannot be empty") if v.startswith('-'): return _("The name of a logical volume cannot start with a hyphen") if v in ('.', '..', 'snapshot', 'pvmove'): return _("A logical volume may not be called {}").format(v) for substring in ['_cdata', '_cmeta', '_corig', '_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta', '_tdata', '_tmeta', '_vorigin']: if substring in v: return _('The name of a logical volume may not contain ' '"{}"').format(substring) if v in self.lvm_names: return _("There is already a logical volume named {}.").format( self.name.value) def validate_mount(self): mount = self.mount.value if mount is None: return # /usr/include/linux/limits.h:PATH_MAX if len(mount) > 4095: return _('Path exceeds PATH_MAX') dev = self.mountpoints.get(mount) 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() if self.existing_fs_type == "swap": exclude = self.mount._table else: exclude = self.use_swap._table i = r.index(exclude) del r[i-1:i+1] return r