Esempio n. 1
0
    def get_device_data(self, name):
        """Get the device data.

        :param name: a device name
        :return: an instance of DeviceData
        :raise: UnknownDeviceError if the device is not found
        """
        # Find the device.
        device = self._get_device(name)

        # Collect the device data.
        data = DeviceData()
        data.type = device.type
        data.name = device.name
        data.path = device.path
        data.size = device.size.get_bytes()
        data.parents = [d.name for d in device.parents]
        data.is_disk = device.is_disk

        # Get the device description.
        # FIXME: We should generate the description from the device data.
        data.description = getattr(device, "description", "")

        # Collect the additional attributes.
        attrs = self._get_attributes(device, DeviceData.SUPPORTED_ATTRIBUTES)
        data.attrs = attrs

        return data
Esempio n. 2
0
    def get_device_data(self, name):
        """Get the device data.

        :param name: a device name
        :return: an instance of DeviceData
        :raise: UnknownDeviceError if the device is not found
        """
        # Find the device.
        device = self._get_device(name)

        # Collect the device data.
        data = DeviceData()
        self._set_device_data(device, data)

        # Collect the specialized data.
        if device.type == "dasd":
            self._set_device_data_dasd(device, data)
        elif device.type == "fcoe":
            self._set_device_data_fcoe(device, data)
        elif device.type == "iscsi":
            self._set_device_data_iscsi(device, data)
        elif device.type == "nvdimm":
            self._set_device_data_nvdimm(device, data)
        elif device.type == "zfcp":
            self._set_device_data_zfcp(device, data)

        # Prune the attributes.
        data.attrs = self._prune_attributes(data.attrs)
        return data
Esempio n. 3
0
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 ""
    }
Esempio n. 4
0
    def set_up_device_tree(num_cdroms):
        """Set up a mock device tree with a specified amount of CD-ROMs.

        Mocks FindOpticalMedia() and GetDeviceData() suitable for testing
        SetUpCdromSourceTask.run()

        :param int num_cdroms: Amount od CD-ROMs
        :return: mock for the device tree
        :rtype: unittest.mock.Mock
        """
        devices = []

        for n in range(num_cdroms):
            device = DeviceData()
            device.name = "test{}".format(n)
            device.path = "/dev/cdrom-test{}".format(n)
            devices.append(device)

        device_tree = Mock()

        device_tree.FindOpticalMedia = Mock()
        device_tree.FindOpticalMedia.return_value = [dev.name for dev in devices]

        device_tree.GetDeviceData = Mock()
        device_tree.GetDeviceData.side_effect = [DeviceData.to_structure(dev) for dev in devices]

        return device_tree
Esempio n. 5
0
    def get_device_data(self, name):
        """Get the device data.

        :param name: a device name
        :return: an instance of DeviceData
        :raise: UnknownDeviceError if the device is not found
        """
        # Find the device.
        device = self._get_device(name)

        if not device:
            raise UnknownDeviceError(name)

        # Collect the device data.
        data = DeviceData()
        data.type = device.type
        data.name = device.name
        data.path = device.path
        data.size = device.size.get_bytes()
        data.is_disk = device.is_disk

        # Collect the additional attributes.
        attrs = self._get_device_attrs(device)
        data.attrs = attrs

        return data
Esempio n. 6
0
    def _do_mount(self):
        """Run CD-ROM installation source setup."""
        log.debug("Trying to detect CD-ROM automatically")

        device_tree = STORAGE.get_proxy(DEVICE_TREE)
        device_name = ""

        for dev_name in device_tree.FindOpticalMedia():
            try:
                device_data = DeviceData.from_structure(
                    device_tree.GetDeviceData(dev_name))
                mount(device_data.path, self._target_mount, "iso9660", "ro")
            except PayloadSetupError:
                continue

            if is_valid_install_disk(self._target_mount):
                device_name = dev_name
                log.info("using CD-ROM device %s mounted at %s", dev_name,
                         self._target_mount)
                break
            else:
                unmount(self._target_mount)

        if not device_name:
            raise SourceSetupError("Found no CD-ROM")
Esempio n. 7
0
    def _set_kargs(self):
        """Set kernel arguments via OSTree-specific utils.

        OSTree owns the bootloader configuration, so here we give it an argument list computed
        from storage, architecture and such.
        """

        # Skip kernel args setup for dirinstall, there is no bootloader or rootDevice setup.
        if conf.target.is_directory:
            return

        bootloader = STORAGE.get_proxy(BOOTLOADER)
        device_tree = STORAGE.get_proxy(DEVICE_TREE)

        root_name = device_tree.GetRootDevice()
        root_data = DeviceData.from_structure(
            device_tree.GetDeviceData(root_name))

        set_kargs_args = ["admin", "instutil", "set-kargs"]
        set_kargs_args.extend(bootloader.GetArguments())
        set_kargs_args.append("root=" + device_tree.GetFstabSpec(root_name))

        if root_data.type == "btrfs subvolume":
            set_kargs_args.append("rootflags=subvol=" + root_name)

        safe_exec_with_redirect("ostree", set_kargs_args, root=self._sysroot)
Esempio n. 8
0
    def refresh(self):
        super().refresh()

        # Reset the scheduled partitioning if any to make sure that we
        # are working with the current system’s storage configuration.
        # FIXME: Change modules and UI to work with the right device tree.
        self._storage_module.ResetPartitioning()

        self._disks = self._disk_selection.GetUsableDisks()
        self._selected_disks = self._disk_selection.SelectedDisks
        self._protected_disks = self._disk_selection.ProtectedDevices
        self._ancestors = self._device_tree.GetAncestors(self._disks)

        # Now all all the non-local disks to the store.  Everything has been set up
        # ahead of time, so there's no need to configure anything.  We first make
        # these lists of disks, then call setup on each individual page.  This is
        # because there could be page-specific setup to do that requires a complete
        # view of all the disks on that page.
        self._store.clear()

        disks_data = DeviceData.from_structure_list([
            self._device_tree.GetDeviceData(device_name)
            for device_name in self._disks
        ])

        for page in self._pages.values():
            disks = [d for d in disks_data if page.is_member(d.type)]

            page.setup(self._store, disks, self._selected_disks,
                       self._protected_disks)

        self._update_summary()
Esempio n. 9
0
    def refresh(self):
        super().refresh()
        self._disks = self._disk_selection.GetUsableDisks()
        self._selected_disks = self._disk_selection.SelectedDisks
        self._protected_disks = self._disk_selection.ProtectedDevices
        self._ancestors = self._device_tree.GetAncestors(self._disks)

        # Now all all the non-local disks to the store.  Everything has been set up
        # ahead of time, so there's no need to configure anything.  We first make
        # these lists of disks, then call setup on each individual page.  This is
        # because there could be page-specific setup to do that requires a complete
        # view of all the disks on that page.
        self._store.clear()

        disks_data = DeviceData.from_structure_list([
            self._device_tree.GetDeviceData(device_name)
            for device_name in self._disks
        ])

        for page in self._pages.values():
            disks = [d for d in disks_data if page.is_member(d.type)]

            page.setup(self._store, disks, self._selected_disks,
                       self._protected_disks)

        self._update_summary()
Esempio n. 10
0
    def _format_disk_info(self, disk):
        """ Some specialized disks are difficult to identify in the storage
            spoke, so add and return extra identifying information about them.

            Since this is going to be ugly to do within the confines of the
            CheckboxWidget, pre-format the display string right here.
        """
        data = DeviceData.from_structure(
            self._device_tree.GetDeviceData(disk)
        )

        # show this info for all disks
        format_str = "{}: {} ({})".format(
            data.attrs.get("model", "DISK"),
            Size(data.size),
            data.name
        )

        # now append all additional attributes to our string
        disk_attrs = filter(None, map(data.attrs.get, (
            "wwn", "bus-id", "fcp-lun", "wwpn", "hba-id"
        )))

        for attr in disk_attrs:
            format_str += ", %s" % attr

        return format_str
    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 PROTECTED_FORMAT_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)
Esempio n. 12
0
    def GetDeviceData(self, name: Str) -> Structure:
        """Get the device data.

        :param name: a device name
        :return: a structure with device data
        :raise: UnknownDeviceError if the device is not found
        """
        return DeviceData.to_structure(self.implementation.get_device_data(name))
Esempio n. 13
0
    def GetDeviceData(self, name: Str) -> Structure:
        """Get the device data.

        :param name: a device name
        :return: a structure with device data
        :raise: UnknownDeviceError if the device is not found
        """
        return DeviceData.to_structure(self.implementation.get_device_data(name))
Esempio n. 14
0
    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
Esempio n. 15
0
    def setup_install_source_task_failed_to_mount_test(self, proxy_getter, os_stat, stat, mount):
        """Test Live OS setup installation source task mount error."""
        device_tree = Mock()
        proxy_getter.return_value = device_tree
        device_tree.ResolveDevice = Mock()
        device_tree.ResolveDevice.return_value = "resolvedDeviceName"

        device = DeviceData()
        device.path = "/resolved/path/to/base/image"

        device_tree.GetDeviceData = Mock()
        device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device))

        mount.return_value = -20

        with self.assertRaises(SourceSetupError):
            SetupInstallationSourceTask(
                "/path/to/base/image",
                "/path/to/mount/source/image"
            ).run()
Esempio n. 16
0
def get_device_path(device_name):
    """Return a device path.

    :param device_name: a device name
    :return: a device path
    """
    if device_name is None:
        return None

    device_tree = STORAGE.get_proxy(DEVICE_TREE)
    device_data = DeviceData.from_structure(device_tree.GetDeviceData(device_name))
    return device_data.path
Esempio n. 17
0
    def test_setup_install_source_task_invalid_block_dev(
            self, proxy_getter, os_stat, stat_mock):
        """Test Live OS Source setup installation source task with invalid block device error."""
        device_tree = Mock()
        proxy_getter.return_value = device_tree
        device_tree.ResolveDevice = Mock()
        device_tree.ResolveDevice.return_value = "resolvedDeviceName"

        device = DeviceData()
        device.path = "/resolved/path/to/base/image"

        device_tree.GetDeviceData = Mock()
        device_tree.GetDeviceData.return_value = DeviceData.to_structure(
            device)

        stat_mock.S_ISBLK = Mock()
        stat_mock.S_ISBLK.return_value = False

        with pytest.raises(SourceSetupError):
            SetUpLiveOSSourceTask("/path/to/base/image",
                                  "/path/to/mount/source/image").run()
 def _populate_disks(self):
     for device_name in self._disks:
         device_data = DeviceData.from_structure(
             self._device_tree.GetDeviceData(device_name))
         device_free_space = self._device_tree.GetDiskFreeSpace(
             [device_name])
         self._store.append([
             "{} ({})".format(device_data.description,
                              device_data.attrs.get("serial", "")),
             str(Size(device_data.size)),
             str(Size(device_free_space)), device_name
         ])
Esempio n. 19
0
    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 test_setup_install_source_task_failed_to_mount(self, proxy_getter,
                                                       os_stat, stat, mount):
        """Test Live OS Source setup installation source task mount error."""
        device_tree = Mock()
        proxy_getter.return_value = device_tree
        device_tree.ResolveDevice = Mock()
        device_tree.ResolveDevice.return_value = "dev1"

        device = DeviceData()
        device.path = "/dev/dev1"

        device_tree.GetDeviceData = Mock()
        device_tree.GetDeviceData.return_value = DeviceData.to_structure(
            device)

        mount.return_value = -20

        with pytest.raises(SourceSetupError) as cm:
            SetUpLiveOSSourceTask("/path/to/base/image",
                                  "/path/to/mount/source/image").run()

        assert str(cm.value) == "Failed to mount the Live OS image."
Esempio n. 21
0
    def setup_install_source_task_test(self, proxy_getter, os_stat, stat, mount):
        """Test Live OS setup installation source task."""
        device_tree = Mock()
        proxy_getter.return_value = device_tree
        device_tree.ResolveDevice = Mock()
        device_tree.ResolveDevice.return_value = "resolvedDeviceName"

        device = DeviceData()
        device.path = "/resolved/path/to/base/image"

        device_tree.GetDeviceData = Mock()
        device_tree.GetDeviceData.return_value = get_native(DeviceData.to_structure(device))

        mount.return_value = 0

        SetupInstallationSourceTask(
            "/path/to/base/image",
            "/path/to/mount/source/image"
        ).run()

        device_tree.ResolveDevice.assert_called_once_with("/path/to/base/image")
        os_stat.assert_called_once_with("/resolved/path/to/base/image")
Esempio n. 22
0
    def _on_action_changed(self, itr, new_action):
        if not itr:
            return

        # Handle the row selected when a button was pressed.
        selected_row = self._disk_store[itr]
        selected_row[ACTION_COL] = _(new_action)

        # If that row is a disk header, we need to process all the partitions
        # it contains.
        device_name = selected_row[DEVICE_NAME_COL]
        is_partitioned = self._device_tree.IsDevicePartitioned(device_name)

        if is_partitioned:
            part_itr = self._disk_store.iter_children(itr)

            while part_itr:
                # Immutable entries are those that we can't do anything to - like
                # the free space lines.  We just want to leave them in the display
                # for information, but you can't choose to preserve/delete/shrink
                # them.
                if self._disk_store[part_itr][TYPE_COL] in [
                        TY_FREE_SPACE, TY_PROTECTED
                ]:
                    part_itr = self._disk_store.iter_next(part_itr)
                    continue

                self._disk_store[part_itr][ACTION_COL] = _(new_action)

                # If the user marked a whole disk for deletion, they can't go in and
                # un-delete partitions under it.
                if new_action == DELETE:
                    self._disk_store[part_itr][EDITABLE_COL] = False
                elif new_action == PRESERVE:
                    part_name = self._disk_store[part_itr][DEVICE_NAME_COL]
                    part_data = DeviceData.from_structure(
                        self._device_tree.GetDeviceData(part_name))
                    self._disk_store[part_itr][
                        EDITABLE_COL] = not part_data.protected

                part_itr = self._disk_store.iter_next(part_itr)

        # And then we're keeping a running tally of how much space the user
        # has selected to reclaim, so reflect that in the UI.
        self._selected_reclaimable_space = Size(0)
        self._disk_store.foreach(self._sum_reclaimable_space, None)
        self._update_labels(
            selected_reclaimable=self._selected_reclaimable_space)
        self._update_reclaim_button(self._selected_reclaimable_space)
        self._update_action_buttons()
Esempio n. 23
0
    def run(self):
        """Run live installation source setup."""
        # Mount the live device and copy from it instead of the overlay at /
        device_tree = STORAGE.get_proxy(DEVICE_TREE)
        device_name = device_tree.ResolveDevice(self._live_partition)
        if not device_name:
            raise SourceSetupError("Failed to find liveOS image!")

        device_data = DeviceData.from_structure(device_tree.GetDeviceData(device_name))

        if not stat.S_ISBLK(os.stat(device_data.path)[stat.ST_MODE]):
            raise SourceSetupError("{} is not a valid block device".format(
                self._live_partition))
        rc = mount(device_data.path, self._target_mount, fstype="auto", options="ro")
        if rc != 0:
            raise SourceSetupError("Failed to mount the install tree")
Esempio n. 24
0
    def refresh(self):
        self._back_clicked = False

        self._available_disks = self._disk_select_module.GetUsableDisks()
        self._selected_disks = self._disk_select_module.SelectedDisks

        # Get the available selected disks.
        self._selected_disks = filter_disks_by_names(self._available_disks,
                                                     self._selected_disks)

        # First, remove all non-button children.
        for child in self.local_overviews + self.advanced_overviews:
            child.destroy()

        # Then deal with local disks, which are really easy.  They need to be
        # handled here instead of refresh to take into account the user pressing
        # the rescan button on custom partitioning.
        # Advanced disks are different.  Because there can potentially be a lot
        # of them, we do not display them in the box by default.  Instead, only
        # those selected in the filter UI are displayed.  This means refresh
        # needs to know to create and destroy overviews as appropriate.
        for device_name in self._available_disks:

            # Get the device data.
            device_data = DeviceData.from_structure(
                self._device_tree.GetDeviceData(device_name))

            if is_local_disk(device_data.type):
                # Add all available local disks.
                self._add_disk_overview(device_data, self._local_disks_box)

            elif device_name in self._selected_disks:
                # Add only selected advanced disks.
                self._add_disk_overview(device_data,
                                        self._specialized_disks_box)

        # update the selections in the ui
        for overview in self.local_overviews + self.advanced_overviews:
            name = overview.get_property("name")
            overview.set_chosen(name in self._selected_disks)

        # Update the encryption checkbox.
        if self._partitioning_request.encrypted:
            self._encrypted_checkbox.set_active(True)

        self._update_summary()
        self._check_problems()
Esempio n. 25
0
    def _calculate_deficit(self, needed):
        """Calculate the deficit.

        Return None if the deficit cannot be calculated.

        :param needed: a needed space
        :return: a deficit size or None
        """
        root_name = self.device_tree.GetRootDevice()

        if not root_name:
            return None

        root_data = DeviceData.from_structure(
            self.device_tree.GetDeviceData(root_name)
        )

        current = root_data.size
        required = self.device_tree.GetRequiredDeviceSize(needed.get_bytes())
        return Size(required - current)
Esempio n. 26
0
    def _update_action_buttons(self):
        # Update buttons for the selected row.
        itr = self._selection.get_selected()[1]

        if not itr:
            return

        row = self._disk_store[itr]
        obj = PartStoreRow(*row)

        self._preserve_button.set_sensitive(obj.editable)
        self._shrink_button.set_sensitive(obj.editable)
        self._delete_button.set_sensitive(obj.editable)
        self._resize_slider.set_visible(False)

        if not obj.editable:
            return

        device_name = obj.name
        device_data = DeviceData.from_structure(
            self._device_tree.GetDeviceData(device_name)
        )

        # If the selected filesystem does not support shrinking, make that
        # button insensitive.
        is_shrinkable = self._device_tree.IsDeviceShrinkable(device_name)
        self._shrink_button.set_sensitive(is_shrinkable)

        if is_shrinkable:
            min_size = self._device_tree.GetDeviceSizeLimits(device_name)[0]
            self._setup_slider(min_size, device_data.size, Size(obj.target))

        # Then, disable the button for whatever action is currently selected.
        # It doesn't make a lot of sense to allow clicking that.
        if obj.action == _(PRESERVE):
            self._preserve_button.set_sensitive(False)
        elif obj.action == _(SHRINK):
            self._shrink_button.set_sensitive(False)
            self._resize_slider.set_visible(True)
        elif obj.action == _(DELETE):
            self._delete_button.set_sensitive(False)
Esempio n. 27
0
    def _choose_installation_device(self, device_tree, devices_candidates):
        device_name = ""

        for dev_name in devices_candidates:
            try:
                device_data = DeviceData.from_structure(
                    device_tree.GetDeviceData(dev_name))
                mount(device_data.path, self._target_mount, "iso9660", "ro")
            except OSError as e:
                log.debug("Failed to mount %s: %s", dev_name, str(e))
                continue

            if is_valid_install_disk(self._target_mount):
                device_name = dev_name
                log.info("using CD-ROM device %s mounted at %s", dev_name,
                         self._target_mount)
                break
            else:
                unmount(self._target_mount)

        return device_name
Esempio n. 28
0
    def _get_device_path(self):
        """Get a device path of the block device."""
        log.debug("Resolving %s.", self._image_path)
        device_tree = STORAGE.get_proxy(DEVICE_TREE)

        # Get the device name.
        device_name = device_tree.ResolveDevice(self._image_path)

        if not device_name:
            raise SourceSetupError("Failed to resolve the Live OS image.")

        # Get the device path.
        device_data = DeviceData.from_structure(
            device_tree.GetDeviceData(device_name)
        )
        device_path = device_data.path

        if not stat.S_ISBLK(os.stat(device_path)[stat.ST_MODE]):
            raise SourceSetupError("{} is not a valid block device.".format(device_path))

        return device_path
Esempio n. 29
0
    def _get_request_description(self, request):
        """Get description of the given mount info."""
        # Get the device data.
        device_name = self._device_tree.ResolveDevice(request.device_spec)
        device_data = DeviceData.from_structure(
            self._device_tree.GetDeviceData(device_name))

        # Generate the description.
        description = "{} ({})".format(request.device_spec,
                                       Size(device_data.size))

        if request.format_type:
            description += "\n {}".format(request.format_type)

            if request.reformat:
                description += "*"

            if request.mount_point:
                description += ", {}".format(request.mount_point)

        return description
Esempio n. 30
0
    def on_delete_all_clicked(self, button, *args):
        if button.get_label() == C_("GUI|Reclaim Dialog", "Delete _all"):
            action = DELETE
            button.set_label(C_("GUI|Reclaim Dialog", "Preserve _all"))
        else:
            action = PRESERVE
            button.set_label(C_("GUI|Reclaim Dialog", "Delete _all"))

        itr = self._disk_store.get_iter_first()
        while itr:
            obj = PartStoreRow(*self._disk_store[itr])
            if not obj.editable:
                itr = self._disk_store.iter_next(itr)
                continue

            device_name = obj.name
            device_data = DeviceData.from_structure(
                self._device_tree.GetDeviceData(device_name))

            if device_data.is_disk:
                self._on_action_changed(itr, action)

            itr = self._disk_store.iter_next(itr)
Esempio n. 31
0
    def _sum_reclaimable_space(self, model, path, itr, *args):
        obj = PartStoreRow(*model[itr])

        if not obj.name:
            return False

        device_name = obj.name
        is_partitioned = self._device_tree.IsDevicePartitioned(device_name)

        if is_partitioned:
            return False

        device_data = DeviceData.from_structure(
            self._device_tree.GetDeviceData(device_name))

        if obj.action == _(PRESERVE):
            return False
        elif obj.action == _(SHRINK):
            self._selected_reclaimable_space += Size(device_data.size) - Size(
                obj.target)
        elif obj.action == _(DELETE):
            self._selected_reclaimable_space += Size(device_data.size)

        return False