def _get_label_text(self): device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(self._device_name)) format_data = DeviceFormatData.from_structure( self._device_tree.GetFormatData(self._device_name)) device_name = self._device_name mount_point = format_data.attrs.get("mount-point", "") if mount_point: device_name = "{} ({})".format(mount_point, self._device_name) if format_data.type in self._protected_types: return _( "{} may be a system boot partition! Deleting it may break " "other operating systems. Are you sure you want to delete it?" ).format(device_name) if device_data.type == "btrfs" and device_data.children: return _( "Are you sure you want to delete all of the data on {}, including subvolumes?" ).format(device_name) if device_data.type == "lvmthinlv" and device_data.children: return _( "Are you sure you want to delete all of the data on {}, including snapshots?" ).format(device_name) return _("Are you sure you want to delete all of the data on {}?" ).format(device_name)
def _add_mount_point_widget(self): """Add a widget for mount point assignment.""" title = _("Mount point") fmt = DeviceFormatData.from_structure( self._device_tree.GetFormatTypeData(self._request.format_type) ) if fmt.mountable: # mount point can be set value = self._request.mount_point or _("none") callback = self._assign_mount_point elif not fmt.type: # mount point cannot be set for no format # (fmt.name = "Unknown" in this case which would look weird) value = _("none") callback = None else: # mount point cannot be set for format that is not mountable, just # show the format's name in square brackets instead value = fmt.description callback = None dialog = Dialog(title, conditions=[self._check_assign_mount_point]) widget = EntryWidget(dialog.title, value) self._container.add(widget, callback, dialog)
def get_hdiso_source_info(device_tree, device_name): """Get info about a potential HDISO source. :param device_tree: a proxy of a device tree :param device_name: a device name :return: a dictionary with a device info """ device_data = DeviceData.from_structure( device_tree.GetDeviceData(device_name)) format_data = DeviceFormatData.from_structure( device_tree.GetFormatData(device_name)) disk_data = DeviceData.from_structure( device_tree.GetDeviceData(device_data.parents[0])) return { "model": disk_data.attrs.get("model", "").replace("_", " "), "path": device_data.path, "size": Size(device_data.size), "format": format_data.description, "label": format_data.attrs.get("label") or format_data.attrs.get("uuid") or "" }
def _add_partition(self, itr, device_name): # Get the device data. device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name) ) format_data = DeviceFormatData.from_structure( self._device_tree.GetFormatData(device_name) ) # Calculate the free size. # Devices that are not resizable are still deletable. is_shrinkable = self._device_tree.IsDeviceShrinkable(device_name) size_limits = self._device_tree.GetDeviceSizeLimits(device_name) min_size = Size(size_limits[0]) device_size = Size(device_data.size) if is_shrinkable: free_size = device_size - min_size resize_string = _("%(freeSize)s of %(devSize)s") % { "freeSize": free_size.human_readable(max_places=1), "devSize": device_size.human_readable(max_places=1) } if not device_data.protected: self._can_shrink_something = True else: free_size = device_size resize_string = "<span foreground='grey'>%s</span>" % \ escape_markup(_("Not resizeable")) # Choose the type. if device_data.protected: ty = TY_PROTECTED else: ty = TY_NORMAL # Generate the description. description = self._get_partition_description(device_data, format_data) # Add a new row. self._disk_store.append(itr, [ device_name, description, format_data.description, resize_string, _(PRESERVE), not device_data.protected, ty, self._get_tooltip(device_data), int(device_size), ]) return free_size
def _add_disk(self, device_name): # Get the device data. device_data = DeviceData.from_structure( self._device_tree.GetDeviceData(device_name) ) format_data = DeviceFormatData.from_structure( self._device_tree.GetFormatData(device_name) ) # First add the disk itself. is_partitioned = self._device_tree.IsDevicePartitioned(device_name) if is_partitioned: fs_type = "" disk_reclaimable_space = Size(0) else: fs_type = format_data.description disk_reclaimable_space = Size(device_data.size) description = "{} {}".format( Size(device_data.size).human_readable(max_places=1), device_data.description ) itr = self._disk_store.append(None, [ device_name, description, fs_type, "<span foreground='grey' style='italic'>%s total</span>", _(PRESERVE), not device_data.protected, TY_NORMAL, self._get_tooltip(device_data), int(device_data.size), ]) # Then add all its partitions. partitions = self._device_tree.GetDevicePartitions(device_name) for child_name in partitions: free_size = self._add_partition(itr, child_name) disk_reclaimable_space += free_size # And then add another uneditable line that lists how much space is # already free in the disk. self._add_free_space(itr, device_name) # And then go back and fill in the total reclaimable space for the # disk, now that we know what each partition has reclaimable. self._disk_store[itr][RECLAIMABLE_COL] = \ self._disk_store[itr][RECLAIMABLE_COL] % disk_reclaimable_space return disk_reclaimable_space
def _switch_reformat(self, data): """Change value of reformat.""" device_name = self._device_tree.ResolveDevice( self._request.device_spec) format_data = DeviceFormatData.from_structure( self._device_tree.GetFormatData(device_name)) device_format = format_data.type if device_format and device_format != self._request.format_type: reformat = True elif self._request.mount_point == "/": reformat = True else: reformat = not self._request.reformat self._request.reformat = reformat
def get_locked_device_names(self): """Get a list of names of locked LUKS devices. All LUKS devices are considered locked. """ device_names = [] for device_name in self._device_tree_proxy.GetDevices(): format_data = DeviceFormatData.from_structure( self._device_tree_proxy.GetFormatData(device_name)) if not format_data.type == "luks": continue device_names.append(device_name) return device_names
def test_get_all_format_type_data(self): """Test GetFormatTypeData for all format types.""" for format_type in device_formats: data = DeviceFormatData.from_structure( self.interface.GetFormatTypeData(format_type)) assert (format_type or "") == data.type