def merge(cls, all_boot_options: Iterable[BootOptions]) -> BootOptions: all_boot_options_str = [ strip_quotes(str(boot_options)) for boot_options in all_boot_options ] return cls(constants.SPACE.join(all_boot_options_str).strip())
def is_matched_with(self, block_device: BlockDevice) -> bool: if block_device.has_root(): root_location = self.root_location if root_location is not None: root_partition = none_throws(block_device.root) filesystem = none_throws(root_partition.filesystem) normalized_root_location = last( strip_quotes(root_location).split( constants.PARAMETERIZED_OPTION_SEPARATOR)) root_location_comparers = [ root_partition.label, root_partition.uuid, filesystem.label, filesystem.uuid, ] if (normalized_root_location in root_location_comparers or block_device.is_matched_with( normalized_root_location)): root_mount_options = self.root_mount_options subvolume = none_throws(filesystem.subvolume) return (root_mount_options.is_matched_with(subvolume) if root_mount_options is not None else False) return False
def normalized_volume(self) -> Optional[str]: volume = self.volume if not is_none_or_whitespace(volume): whitespace_pattern = re.compile(constants.WHITESPACE_PATTERN) stripped_volume = strip_quotes(volume) return whitespace_pattern.sub("_", stripped_volume) return None
def __init__(self, raw_options: Optional[str]) -> None: root_location: Optional[tuple[int, str]] = None root_mount_options: Optional[tuple[int, MountOptions]] = None initrd_options: list[tuple[int, str]] = [] other_options: list[tuple[int, str]] = [] if not is_none_or_whitespace(raw_options): split_options = strip_quotes(raw_options).split() for position, option in enumerate(split_options): if not is_none_or_whitespace(option): if option.startswith(constants.ROOT_PREFIX): normalized_option = option.removeprefix( constants.ROOT_PREFIX) if root_location is not None: root_option = constants.ROOT_PREFIX.rstrip( constants.PARAMETERIZED_OPTION_SEPARATOR) raise RefindConfigError( f"The '{root_option}' boot option " f"cannot be defined multiple times!") root_location = (position, normalized_option) elif option.startswith(constants.ROOTFLAGS_PREFIX): normalized_option = option.removeprefix( constants.ROOTFLAGS_PREFIX) if root_mount_options is not None: rootflags_option = constants.ROOTFLAGS_PREFIX.rstrip( constants.PARAMETERIZED_OPTION_SEPARATOR) raise RefindConfigError( f"The '{rootflags_option}' boot option " f"cannot be defined multiple times!") root_mount_options = (position, MountOptions(normalized_option)) elif option.startswith(constants.INITRD_PREFIX): normalized_option = option.removeprefix( constants.INITRD_PREFIX) initrd_options.append((position, normalized_option)) else: other_options.append((position, option)) self._root_location = root_location self._root_mount_options = root_mount_options self._initrd_options = initrd_options self._other_options = other_options
def normalized_name(self) -> str: return strip_quotes(self.name)