コード例 #1
0
    def _get_format_type_data(self, fmt):
        """Get the format type data.

        Retrieve data about a format type from
        the given format instance.

        :param fmt: an instance of DeviceFormat
        :return: an instance of DeviceFormatData
        """
        data = DeviceFormatData()
        data.type = fmt.type or ""
        data.mountable = fmt.mountable
        data.description = fmt.name or ""
        return data
コード例 #2
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 ""
    }
コード例 #3
0
ファイル: viewer_interface.py プロジェクト: rvykydal/anaconda
    def GetFormatData(self, name: Str) -> Structure:
        """Get the device format.

        :param name: a name of the device
        :return: an instance of DeviceFormatData
        """
        return DeviceFormatData.to_structure(self.implementation.get_format_data(name))
コード例 #4
0
 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)
         )
         self.assertEqual(format_type or "", data.type)
コード例 #5
0
ファイル: storage.py プロジェクト: yugart/anaconda
    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)
コード例 #6
0
    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)
コード例 #7
0
    def GetFormatData(self, name: Str) -> Structure:
        """Get the device format data.

        :param name: a name of the device
        :return: a structure with format data
        """
        return DeviceFormatData.to_structure(self.implementation.get_format_data(name))
コード例 #8
0
    def GetFormatTypeData(self, name: Str) -> Structure:
        """Get the format type data.

        For example: ext4

        :param name: a name of the format type
        :return: a structure with format data
        """
        return DeviceFormatData.to_structure(self.implementation.get_format_type_data(name))
コード例 #9
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
コード例 #10
0
    def get_format_data(self, device_name):
        """Get the device format.

        :param device_name: a name of the device
        :return: an instance of DeviceFormatData
        """
        # Find the device.
        device = self._get_device(device_name)

        # Collect the format data.
        data = DeviceFormatData()
        data.type = device.format.type or ""
        data.description = device.format.name or ""

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

        return data
コード例 #11
0
    def GetFormatData(self, name: Str) -> Structure:
        """Get the device format data.

        Return data about a format of the specified device.

        For example: sda1

        :param name: a name of the device
        :return: a structure with format data
        """
        return DeviceFormatData.to_structure(
            self.implementation.get_format_data(name))
コード例 #12
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
コード例 #13
0
    def _get_format_data(self, fmt):
        """Get the format data.

        :param fmt: an instance of DeviceFormat
        :return: an instance of DeviceFormatData
        """
        # Collect the format data.
        data = DeviceFormatData()
        data.type = fmt.type or ""
        data.mountable = fmt.mountable
        data.description = fmt.name or ""

        # Collect the additional attributes.
        data.attrs["uuid"] = self._get_attribute(fmt, "uuid")
        data.attrs["label"] = self._get_attribute(fmt, "label")
        data.attrs["mount-point"] = self._get_attribute(fmt, "mountpoint")

        # Prune the attributes.
        data.attrs = self._prune_attributes(data.attrs)
        return data
コード例 #14
0
ファイル: storage.py プロジェクト: jstodola/anaconda
    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
コード例 #15
0
ファイル: rescue.py プロジェクト: yubihong/anaconda
    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
コード例 #16
0
ファイル: viewer.py プロジェクト: sun363587351/anaconda
    def _get_format_data(self, fmt):
        """Get the format data.

        :param fmt: an instance of DeviceFormat
        :return: an instance of DeviceFormatData
        """
        # Collect the format data.
        data = DeviceFormatData()
        data.type = fmt.type or ""
        data.mountable = fmt.mountable
        data.description = fmt.name or ""

        # Collect the additional attributes.
        attrs = self._get_attributes(fmt, DeviceFormatData.SUPPORTED_ATTRIBUTES)
        data.attrs = attrs

        return data