Exemplo n.º 1
0
 def __init__(self, mountpoint_to_devpath_mapping):
     opts = []
     first_opt = None
     max_len = max(map(len, common_mountpoints))
     for i, mnt in enumerate(common_mountpoints):
         devpath = mountpoint_to_devpath_mapping.get(mnt)
         if devpath is None:
             if first_opt is None:
                 first_opt = i
             opts.append((mnt, True, mnt))
         else:
             opts.append(("%-*s (%s)" % (max_len, mnt, devpath), False))
     if first_opt is None:
         first_opt = len(opts)
     opts.append((_('other'), True, OTHER))
     opts.append(('---', False)),
     opts.append((_('leave unmounted'), True, LEAVE_UNMOUNTED))
     self._selector = Selector(opts, first_opt)
     connect_signal(self._selector, 'select', self._select_mount)
     self._other = _MountEditor()
     super().__init__(Pile([self._selector]))
     self._other_showing = False
     if self._selector.value is OTHER:
         # This can happen if all the common_mountpoints are in use.
         self._showhide_other(True)
Exemplo n.º 2
0
    def __init__(self, model, signal, selected_disk):
        log.debug('AddPartitionView: selected_disk=[{}]'.format(selected_disk))
        self.model = model
        self.signal = signal
        self.selected_disk = selected_disk
        self.disk_obj = self.model.get_disk(selected_disk)

        self.partnum = IntegerEditor(caption="",
                                     default=self.disk_obj.lastpartnumber + 1)
        self.size_str = _humanize_size(self.disk_obj.freespace)
        self.size = StringEditor(caption="".format(self.size_str))
        self.mountpoint = MountEditor(caption="", edit_text="/")
        self.fstype = Selector(opts=self.model.supported_filesystems)
        body = [
            Columns([
                ("weight", 0.2,
                 Text("Adding partition to {}".format(self.disk_obj.devpath),
                      align="right")), ("weight", 0.3, Text(""))
            ]),
            Padding.line_break(""),
            self._container(),
            Padding.line_break(""),
            Padding.fixed_10(self._build_buttons())
        ]
        partition_box = Padding.center_50(ListBox(body))
        super().__init__(partition_box)
Exemplo n.º 3
0
 def __init__(self, mountpoints, ok_for_slash_boot):
     opts = []
     first_opt = None
     for i, mnt in enumerate(common_mountpoints):
         if not ok_for_slash_boot and mnt == "/boot":
             opts.append((mnt, False))
         elif mnt not in mountpoints:
             if first_opt is None:
                 first_opt = i
             opts.append((mnt, True, mnt))
         else:
             opts.append((mnt, False))
     if first_opt is None:
         first_opt = len(opts)
     opts.append((_('other'), True, OTHER))
     opts.append(('---', False)),
     opts.append((_('leave unmounted'), True, LEAVE_UNMOUNTED))
     self._selector = Selector(opts, first_opt)
     connect_signal(self._selector, 'select', self._select_mount)
     self._other = _MountEditor()
     super().__init__(Pile([self._selector]))
     self._other_showing = False
     if self._selector.value is OTHER:
         # This can happen if all the common_mountpoints are in use.
         self._showhide_other(True)
Exemplo n.º 4
0
 def __init__(self, model, controller):
     self.model = model
     self.controller = controller
     self.bond_iface = None
     self.bond_mode = Selector(self.model.bonding_modes.values())
     self.selected_ifaces = []
     body = [
         Padding.center_50(self._build_iface_selection()),
         Padding.line_break(""),
         Padding.center_50(self._build_bondmode_configuration()),
         Padding.line_break(""),
         Padding.fixed_10(self._build_buttons())
     ]
     super().__init__(ListBox(body))
Exemplo n.º 5
0
    def _build_disk_selection(self, section):
        log.debug('bcache: _build_disk_selection, section:' + section)
        items = [Text(section + " DISK SELECTION")]

        avail_devs = self._get_available_devs(section)
        if len(avail_devs) == 0:
            return items.append(
                [Color.info_minor(Text("No available disks."))])

        selector = Selector(avail_devs)
        self.selected_disks[section] = selector
        items.append(Color.string_input(selector))

        return Pile(items)
Exemplo n.º 6
0
 def __init__(self, model, signal):
     self.model = model
     self.signal = signal
     self.raid_level = Selector(self.model.raid_levels)
     self.hot_spares = IntegerEditor()
     self.chunk_size = StringEditor(edit_text="4K")
     self.selected_disks = []
     body = [
         Padding.center_50(self._build_disk_selection()),
         Padding.line_break(""),
         Padding.center_50(self._build_raid_configuration()),
         Padding.line_break(""),
         Padding.fixed_10(self._build_buttons())
     ]
     super().__init__(ListBox(body))
Exemplo n.º 7
0
    def __init__(self, model, signal, selected_disk):
        self.model = model
        self.signal = signal
        self.selected_disk = selected_disk
        self.disk_obj = self.model.get_disk(selected_disk)

        self.mountpoint = MountEditor(caption="", edit_text="/")
        self.fstype = Selector(opts=self.model.supported_filesystems)
        body = [
            Padding.line_break(""),
            self._container(),
            Padding.line_break(""),
            Padding.fixed_10(self._build_buttons())
        ]
        format_box = Padding.center_50(ListBox(body))
        super().__init__(format_box)
Exemplo n.º 8
0
class MountSelector(WidgetWrap):

    signals = ['change']

    def __init__(self, mountpoints):
        opts = []
        first_opt = None
        for i, mnt in enumerate(common_mountpoints):
            if mnt not in mountpoints:
                if first_opt is None:
                    first_opt = i
                opts.append((mnt, True, mnt))
            else:
                opts.append((mnt, False))
        if first_opt is None:
            first_opt = len(opts)
        opts.append((_('Other'), True, OTHER))
        opts.append(('---', False)),
        opts.append((_('Leave unmounted'), True, LEAVE_UNMOUNTED))
        self._selector = Selector(opts, first_opt)
        connect_signal(self._selector, 'select', self._select_mount)
        self._other = _MountEditor()
        super().__init__(Pile([self._selector]))
        self._other_showing = False
        if self._selector.value is OTHER:
            # This can happen if all the common_mountpoints are in use.
            self._showhide_other(True)

    def disable_unsuitable_mountpoints_for_existing_fs(self):
        for opt in self._selector._options:
            if opt.value is not None:
                opt.enabled = opt.value in suitable_mountpoints_for_existing_fs

    def enable_common_mountpoints(self):
        for opt in self._selector._options:
            if isinstance(opt.value, str):
                opt.enabled = opt.value in common_mountpoints

    def _showhide_other(self, show):
        if show and not self._other_showing:
            self._w.contents.append(
                (Columns([(1, Text("/")),
                          Color.string_input(self._other)]),
                 self._w.options('pack')))
            self._other_showing = True
        elif not show and self._other_showing:
            del self._w.contents[-1]
            self._other_showing = False

    def _select_mount(self, sender, value):
        self._showhide_other(value == OTHER)
        if value == OTHER:
            self._w.focus_position = 1
            value = "/" + self._other.value
        self._emit('change', value)

    @property
    def value(self):
        if self._selector.value is LEAVE_UNMOUNTED:
            return None
        elif self._selector.value is OTHER:
            return "/" + self._other.value
        else:
            return self._selector.value

    @value.setter
    def value(self, val):
        opt = self._selector.option_by_value(val)
        if val is None:
            self._selector.value = LEAVE_UNMOUNTED
            self._showhide_other(False)
        elif opt is not None and opt.enabled:
            self._selector.value = val
            self._showhide_other(False)
        else:
            self._selector.value = OTHER
            self._showhide_other(True)
            if not val.startswith('/'):
                raise ValueError("%s does not start with /", val)
            self._other.value = val[1:]
Exemplo n.º 9
0
 def _make_widget(self, form):
     return Selector(opts=FilesystemModel.supported_filesystems)