Ejemplo n.º 1
0
def summarize_device(device, part_filter=lambda p: True):
    """Return content for a table summarizing device.

    This (obj, cells) where obj is either device itself, a partition of
    device or None and cells is part of an argument to TableRow that
    will span 4 columns that describes device or a partition of
    device. This sounds a bit strange but hopefully you can figure it
    out by looking at the uses of this function.
    """
    label = labels.label(device)
    anns = labels.annotations(device)
    if anns:
        label = "{} ({})".format(label, ", ".join(anns))
    rows = [(device, [
        (2, Text(label)),
        Text(labels.desc(device)),
        Text(humanize_size(device.size), align="right"),
    ])]
    partitions = device.partitions()
    if partitions:
        for part in device.partitions():
            if not part_filter(part):
                continue
            details = ", ".join(
                labels.annotations(part) + labels.usage_labels(part))
            rows.append((part, [
                Text(labels.label(part, short=True)),
                (2, Text(details)),
                Text(humanize_size(part.size), align="right"),
            ]))
    else:
        rows.append((None, [
            (4, Color.info_minor(Text(", ".join(labels.usage_labels(device)))))
        ]))
    return rows
Ejemplo n.º 2
0
    def __init__(self, parent, obj):
        self.parent = parent
        self.obj = obj

        fs = obj.fs()
        if fs is not None:
            title = _("Remove filesystem from {device}").format(
                device=labels.desc(obj))
            lines = [
                _("Do you really want to remove the existing filesystem "
                  "from {device}?").format(device=labels.label(obj)),
                "",
            ]
            m = fs.mount()
            if m is not None:
                lines.append(
                    _("It is formatted as {fstype} and mounted at "
                      "{path}").format(fstype=fs.fstype, path=m.path))
            else:
                lines.append(
                    _("It is formatted as {fstype} and not mounted.").format(
                        fstype=fs.fstype))
        else:
            if obj.type == "lvm_volgroup":
                things = _("logical volumes")
            else:
                things = _("partitions")
            # things is either "logical volumes" or "partitions"
            title = _("Remove all {things} from {obj}").format(
                things=things, obj=labels.desc(obj))
            lines = [
                _("Do you really want to remove all {things} from "
                  "{obj}?").format(things=things, obj=labels.label(obj)),
                "",
            ]
            # XXX summarize partitions here?

        delete_btn = danger_btn(label=_("Reformat"), on_press=self.confirm)
        widgets = [
            Text("\n".join(lines)),
            Text(""),
            button_pile([
                delete_btn,
                other_btn(label=_("Cancel"), on_press=self.cancel),
            ]),
        ]
        super().__init__(title, widgets, 0, 2)
Ejemplo n.º 3
0
 def for_client(self, min_size):
     from subiquity.common.filesystem import labels
     from subiquity.common.types import Disk
     return Disk(
         id=self.id,
         label=labels.label(self),
         type=labels.desc(self),
         size=self.size,
         usage_labels=labels.usage_labels(self),
         partitions=[p.for_client() for p in self._partitions],
         ok_for_guided=self.size >= min_size)
Ejemplo n.º 4
0
 def _summarize(self, prefix, device):
     if device.fs() is not None:
         fs = device.fs()
         text = prefix + _("formatted as {fstype}").format(fstype=fs.fstype)
         if fs.mount():
             text += _(", mounted at {path}").format(path=fs.mount().path)
         else:
             text += _(", not mounted")
     else:
         text = prefix + _("unused {device}").format(
             device=labels.desc(device))
     return TableRow([(2, Color.info_minor(Text(text)))])
Ejemplo n.º 5
0
    def __init__(self, parent, obj):
        self.parent = parent
        self.obj = obj

        lines = [
            Text(
                _("Do you really want to delete the {desc} {label}?").format(
                    desc=labels.desc(obj), label=labels.label(obj))),
            Text(""),
        ]
        stretchy_index = 0
        fs = obj.fs()
        if fs is not None:
            m = fs.mount()
            if m is not None:
                lines.append(
                    Text(
                        _("It is formatted as {fstype} and mounted at "
                          "{path}").format(fstype=fs.fstype, path=m.path)))
            else:
                lines.append(
                    Text(
                        _("It is formatted as {fstype} and not mounted.").
                        format(fstype=fs.fstype)))
        elif hasattr(obj, 'partitions') and len(obj.partitions()) > 0:
            n = len(obj.partitions())
            if obj.type == "lvm_volgroup":
                line = ngettext("It contains 1 logical volume",
                                "It contains {n} logical volumes", n)
            else:
                line = ngettext("It contains 1 partition",
                                "It contains {n} partitions", n)
            lines.append(Text(line.format(n=n)))
            lines.append(Text(""))
            stretchy_index = len(lines)
            rows = []
            for p, cells in summarize_device(obj):
                if p not in [None, obj]:
                    rows.append(TableRow(cells))
            lines.append(TablePile(rows))
        else:
            lines.append(Text(_("It is not formatted or mounted.")))

        delete_btn = danger_btn(label=_("Delete"), on_press=self.confirm)
        widgets = lines + [
            Text(""),
            button_pile([
                delete_btn,
                other_btn(label=_("Cancel"), on_press=self.cancel),
            ]),
        ]
        super().__init__("", widgets, stretchy_index, len(lines) + 1)
Ejemplo n.º 6
0
    def __init__(self, parent, obj, action, whynot):
        self.parent = parent
        self.obj = obj

        title = "Cannot {action} {type}".format(action=_(action.value).lower(),
                                                type=labels.desc(obj))
        widgets = [
            Text(whynot),
            Text(""),
            button_pile([
                other_btn(label=_("Close"), on_press=self.close),
            ]),
        ]
        super().__init__(title, widgets, 0, 2)
Ejemplo n.º 7
0
 def set_bound_form_field(self, bff):
     super().set_bound_form_field(bff)
     self.all_rows = []
     for kind, device in bff.form.possible_components:
         if kind == LABEL:
             self.all_rows.append(TableRow([
                 Text("    " + labels.label(device)),
                 Text(humanize_size(device.size), align='right')
             ]))
             self.no_selector_rows.append(self.all_rows[-1])
             self.all_rows.append(TableRow([
                 (2, Color.info_minor(Text("      " + labels.desc(device))))
             ]))
             self.no_selector_rows.append(self.all_rows[-1])
         else:
             label = labels.label(device, short=True)
             if kind == DEVICE:
                 prefix = "    "
             elif kind == PART:
                 label = "  " + label
                 prefix = "      "
             else:
                 raise Exception("unexpected kind {}".format(kind))
             box = CheckBox(
                 label,
                 on_state_change=self._state_change_device,
                 user_data=device)
             self.device_to_checkbox[device] = box
             size = Text(humanize_size(device.size), align='right')
             self.all_rows.append(Color.menu_button(TableRow([box, size])))
             self.no_selector_rows.append(self.all_rows[-1])
             selector = Selector(['active', 'spare'])
             connect_signal(
                 selector, 'select', self._select_active_spare, device)
             selector = Toggleable(
                 UrwidPadding(
                     Color.menu_button(selector),
                     left=len(prefix)))
             selector.enabled = False
             self.device_to_selector[device] = selector
             self.all_rows.append(TableRow([(2, selector)]))
             # Do not append that one to no_selector_rows!
             self.all_rows.append(self._summarize(prefix, device))
             self.no_selector_rows.append(self.all_rows[-1])
     self.table.set_contents(self.all_rows)
Ejemplo n.º 8
0
 def _label_REMOVE(self, action, device):
     cd = device.constructed_device()
     if cd:
         return _("Remove from {device}").format(device=labels.desc(cd))
     else:
         return action.str()
Ejemplo n.º 9
0
 def desc(self):
     anns = labels.annotations(self.mount.device.volume)
     desc = labels.desc(self.mount.device.volume)
     if anns:
         desc = anns[0] + " " + desc
     return desc