예제 #1
0
 def _action_menu_for_device(self, device):
     device_actions = []
     for action in device.supported_actions:
         label = _(action.value)
         if action == DeviceAction.REMOVE and device.constructed_device():
             cd = device.constructed_device()
             label = _("Remove from {}").format(cd.desc())
         enabled, whynot = device.action_possible(action)
         if whynot:
             assert not enabled
             enabled = True
             label += " *"
             meth = _whynot_shower(self.parent, action, whynot)
         else:
             meth_name = '_{}_{}'.format(device.type, action.name)
             meth = getattr(self, meth_name)
         if not whynot and action == DeviceAction.DELETE:
             label = Color.danger_button(ActionMenuOpenButton(label))
         device_actions.append(Action(
             label=label,
             enabled=enabled,
             value=(action, meth),
             opens_dialog=getattr(meth, 'opens_dialog', False)))
     menu = ActionMenu(device_actions)
     connect_signal(menu, 'action', self._action, device)
     return menu
예제 #2
0
 def _action_menu_for_device(self, device):
     device_actions = []
     for action in DeviceAction.supported(device):
         label_meth = getattr(self, '_label_{}'.format(action.name),
                              lambda a, d: a.str())
         label = label_meth(action, device)
         enabled, whynot = action.can(device)
         if whynot:
             assert not enabled
             enabled = True
             label += " *"
             meth = _whynot_shower(self.parent, action, whynot)
         else:
             meth_name = '_{}_{}'.format(device.type, action.name)
             meth = getattr(self, meth_name)
         if not whynot and action in [
                 DeviceAction.DELETE, DeviceAction.REFORMAT
         ]:
             label = Color.danger_button(ActionMenuOpenButton(label))
         device_actions.append(
             Action(label=label,
                    enabled=enabled,
                    value=(action, meth),
                    opens_dialog=getattr(meth, 'opens_dialog', False)))
     menu = ActionMenu(device_actions)
     connect_signal(menu, 'action', self._action, device)
     return menu
예제 #3
0
    def refresh_model_inputs(self):
        mountinfos = [
            MountInfo(mount=m)
            for m in sorted(self.parent.model.all_mounts(),
                            key=lambda m: (m.path == "", m.path))
        ]
        if len(mountinfos) == 0:
            self.table.set_contents([])
            self._w = self._no_mounts_content
            return
        self._w = self.table
        log.debug('FileSystemView: building mount list')

        rows = [
            TableRow([
                Text(_("MOUNT POINT")),
                Text(_("SIZE"), align='center'),
                Text(_("TYPE")),
                Text(_("DEVICE TYPE")),
            ])
        ]

        for i, mi in enumerate(mountinfos):
            path_markup = mi.path
            if path_markup == "":
                path_markup = ('info_minor', "SWAP")
            else:
                for j in range(i - 1, -1, -1):
                    mi2 = mountinfos[j]
                    if mi.startswith(mi2):
                        part1 = "/".join(mi.split_path[:len(mi2.split_path)])
                        part2 = "/".join([''] +
                                         mi.split_path[len(mi2.split_path):])
                        path_markup = [('info_minor', part1), part2]
                        break
                    if j == 0 and mi2.split_path == ['', '']:
                        path_markup = [
                            ('info_minor', "/"),
                            "/".join(mi.split_path[1:]),
                        ]
            actions = [(_("Unmount"), mi.mount.can_delete(), 'unmount')]
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._mount_action, mi.mount)
            row = TableRow([
                Text(path_markup),
                Text(mi.size, align='right'),
                Text(mi.fstype),
                Text(mi.desc),
                menu,
            ])
            row = add_menu_row_focus_behaviour(
                menu, row, 'menu_button', {
                    None: 'menu_button focus',
                    'info_minor': 'menu_button focus'
                })
            rows.append(row)
        self.table.set_contents(rows)
        if self.table._w.focus_position >= len(rows):
            self.table._w.focus_position = len(rows) - 1
예제 #4
0
    def refresh_model_inputs(self):
        zdevinfos = self.parent.controller.get_zdevinfos()

        rows = [
            TableRow([
                Color.info_minor(heading) for heading in [
                    Text(_("ID")),
                    Text(_("ONLINE")),
                    Text(_("NAMES")),
                ]
            ])
        ]

        typeclass = ''
        for i, zdevinfo in enumerate(zdevinfos):
            if zdevinfo.typeclass != typeclass:
                rows.append(TableRow([
                    Text(""),
                ]))
                rows.append(
                    TableRow([
                        Color.info_minor(Text(zdevinfo.type)),
                        Text(""),
                        Text("")
                    ]))
                typeclass = zdevinfo.typeclass

            if zdevinfo.type == 'zfcp-lun':
                rows.append(
                    TableRow([
                        Color.info_minor(Text(zdevinfo.id[9:])),
                        zdevinfo.status,
                        Text(zdevinfo.names),
                    ]))
                continue

            actions = [(_("Enable"), not zdevinfo.on, 'enable'),
                       (_("Disable"), zdevinfo.on, 'disable')]
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._zdev_action, zdevinfo)
            cells = [
                Text(zdevinfo.id),
                zdevinfo.status,
                Text(zdevinfo.names),
                menu,
            ]
            row = make_action_menu_row(cells,
                                       menu,
                                       attr_map='menu_button',
                                       focus_map={
                                           None: 'menu_button focus',
                                           'info_minor': 'menu_button focus',
                                       },
                                       cursor_x=0)
            rows.append(row)
        self.table.set_contents(rows)
        if self.table._w.base_widget.focus_position >= len(rows):
            self.table._w.base_widget.focus_position = len(rows) - 1
예제 #5
0
    def _create(self):
        # Create the widget for a nic. This consists of a Pile containing a
        # table, an info line and a blank line. The first row of the table is
        # the one that can be focused and has a menu for manipulating the nic,
        # the other rows summarize its address config.
        #   [ name type notes   ▸ ]   \
        #     address info            | <- table
        #     more address info       /
        #   mac / vendor info / model info
        #   <blank line>

        actions = []
        for action in NetDevAction:
            meth = getattr(self.parent, '_action_' + action.name)
            opens_dialog = getattr(meth, 'opens_dialog', False)
            if action in self.dev_info.enabled_actions:
                actions.append(
                    (action.str(), True, (action, meth), opens_dialog))

        menu = ActionMenu(actions)
        connect_signal(menu, 'action', self.parent._action, self)

        trows = [
            make_action_menu_row([
                Text("["),
                Text(self.dev_info.name),
                Text(self.dev_info.type),
                Text(self._notes(), wrap='clip'),
                menu,
                Text("]"),
            ], menu)
        ] + self._address_rows()

        self.table = TablePile(trows,
                               colspecs=self.parent.device_colspecs,
                               spacing=2)
        self.table.bind(self.parent.heading_table)

        if self.dev_info.type == "vlan":
            info = _("VLAN {id} on interface {link}").format(
                id=self.dev_info.vlan.id, link=self.dev_info.vlan.link)
        elif self.dev_info.type == "bond":
            info = _("bond master for {interfaces}").format(
                interfaces=', '.join(self.dev_info.bond.interfaces))
        else:
            info = " / ".join([
                self.dev_info.hwaddr,
                self.dev_info.vendor,
                self.dev_info.model,
            ])

        return Pile([
            ('pack', self.table),
            ('pack', Color.info_minor(Text("  " + info))),
            ('pack', Text("")),
        ])
예제 #6
0
    def _device_widget(self, dev, netdev_i=None):
        # Create the widget for a nic. This consists of a Pile containing a
        # table, an info line and a blank line. The first row of the table is
        # the one that can be focused and has a menu for manipulating the nic,
        # the other rows summarize its address config.
        #   [ name type notes   ▸ ]   \
        #     address info            | <- table
        #     more address info       /
        #   mac / vendor info / model info
        #   <blank line>
        if netdev_i is None:
            netdev_i = len(self.cur_netdevs)
        self.cur_netdevs[netdev_i:netdev_i] = [dev]

        actions = []
        for action in NetDevAction:
            meth = getattr(self, '_action_' + action.name)
            opens_dialog = getattr(meth, 'opens_dialog', False)
            if dev.supports_action(action):
                actions.append(
                    (_(action.value), True, (action, meth), opens_dialog))

        menu = ActionMenu(actions)
        connect_signal(menu, 'action', self._action, dev)

        trows = [
            make_action_menu_row([
                Text("["),
                Text(dev.name),
                Text(dev.type),
                Text(self._notes_for_device(dev), wrap='clip'),
                menu,
                Text("]"),
            ], menu)
        ] + self._address_rows_for_device(dev)

        table = TablePile(trows, colspecs=self.device_colspecs, spacing=2)
        self.dev_to_table[dev] = table
        table.bind(self.heading_table)

        if dev.type == "vlan":
            info = _("VLAN {id} on interface {link}").format(**dev.config)
        elif dev.type == "bond":
            info = _("bond master for {interfaces}").format(
                interfaces=', '.join(dev.config['interfaces']))
        else:
            info = " / ".join(
                [dev.info.hwaddr, dev.info.vendor, dev.info.model])

        return Pile([
            ('pack', table),
            ('pack', Color.info_minor(Text("  " + info))),
            ('pack', Text("")),
        ])
예제 #7
0
    def __init__(self, controller, systems):
        self.controller = controller

        heading_table = TablePile([
            TableRow([
                Color.info_minor(Text(header))
                for header in ["LABEL", "MODEL", "PUBLISHER", ""]
            ])
        ],
                                  spacing=2)

        trows = []
        systems = sorted(
            systems,
            key=lambda s:
            (s.brand.display_name, s.model.display_name, s.current, s.label))
        for s in systems:
            actions = []
            log.debug('actions: %s', s.actions)
            for act in sorted(s.actions, key=by_preferred_action_type):
                actions.append(
                    Action(label=act.title.capitalize(),
                           value=act,
                           enabled=True))
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._system_action, s)
            srow = make_action_menu_row([
                Text(s.label),
                Text(s.model.display_name),
                Text(s.brand.display_name),
                Text("(installed)" if s.current else ""),
                menu,
            ], menu)
            trows.append(srow)

        systems_table = TablePile(trows, spacing=2)
        systems_table.bind(heading_table)
        rows = [
            Pile([heading_table, systems_table]),
        ]

        buttons = []
        if controller.model.current is not None:
            # back to options of current system
            buttons.append(back_btn("BACK", on_press=self.back))

        super().__init__(
            controller.model.current,
            screen(rows=rows,
                   buttons=button_pile(buttons),
                   focus_buttons=False,
                   excerpt=self.excerpt))
예제 #8
0
 def _action_menu_for_device(self, device):
     delete_btn = Color.danger_button(ActionMenuButton(_("Delete")))
     device_actions = [
         (_("Information"), DeviceAction.INFO),
         (_("Edit"), DeviceAction.EDIT),
         (_("Add Partition"), DeviceAction.PARTITION),
         (_("Format / Mount"), DeviceAction.FORMAT),
         (delete_btn, DeviceAction.DELETE),
         (_("Make boot device"), DeviceAction.MAKE_BOOT),
     ]
     menu = ActionMenu([(label, device.supports_action(action), action)
                        for label, action in device_actions])
     connect_signal(menu, 'action', self._action, device)
     return menu
예제 #9
0
 def _rows_for_device(self, dev, netdev_i=None):
     if netdev_i is None:
         netdev_i = len(self.cur_netdevs)
     rows = []
     name, typ, addresses = self._cells_for_device(dev)
     actions = []
     for action in NetDevAction:
         meth = getattr(self, '_action_' + action.name)
         opens_dialog = getattr(meth, 'opens_dialog', False)
         if dev.supports_action(action):
             actions.append(
                 (_(action.value), True, (action, meth), opens_dialog))
     menu = ActionMenu(actions)
     connect_signal(menu, 'action', self._action, dev)
     row = make_action_menu_row([
         Text("["),
         Text(name),
         Text(typ),
         Text(addresses, wrap='clip'),
         menu,
         Text("]"),
         ], menu)
     self.dev_to_row[dev] = row.base_widget
     self.cur_netdevs[netdev_i:netdev_i] = [dev]
     rows.append(row)
     if dev.type == "vlan":
         info = _("VLAN {id} on interface {link}").format(
             **dev.config)
     elif dev.type == "bond":
         info = _("bond master for {}").format(
             ', '.join(dev.config['interfaces']))
     else:
         info = " / ".join([
             dev.info.hwaddr, dev.info.vendor, dev.info.model])
     rows.append(Color.info_minor(TableRow([
         Text(""),
         (4, Text(info)),
         Text("")])))
     rows.append(Color.info_minor(TableRow([(4, Text(""))])))
     return rows
예제 #10
0
 def _action_menu_for_device(self, device):
     if can_delete(device)[0]:
         delete_btn = Color.danger_button(ActionMenuButton(_("Delete")))
     else:
         delete_btn = _("Delete *")
     device_actions = [
         (_("Information"), DeviceAction.INFO),
         (_("Edit"), DeviceAction.EDIT),
         (_("Add Partition"), DeviceAction.PARTITION),
         (_("Format / Mount"), DeviceAction.FORMAT),
         (delete_btn, DeviceAction.DELETE),
         (_("Make boot device"), DeviceAction.MAKE_BOOT),
     ]
     actions = []
     for label, action in device_actions:
         actions.append(
             Action(label=label,
                    enabled=device.supports_action(action),
                    value=action,
                    opens_dialog=action != DeviceAction.MAKE_BOOT))
     menu = ActionMenu(actions, "\N{BLACK RIGHT-POINTING SMALL TRIANGLE}")
     connect_signal(menu, 'action', self._action, device)
     return menu
예제 #11
0
    def refresh_model_inputs(self):
        mountinfos = [
            MountInfo(mount=m)
            for m in sorted(self.parent.model.all_mounts(),
                            key=lambda m: (m.path == "", m.path))
        ]
        if len(mountinfos) == 0:
            self.table.set_contents([])
            self._w = Padding.push_2(self._no_mounts_content)
            return
        self._w = self.table

        rows = [
            TableRow([
                Color.info_minor(heading) for heading in [
                    Text(" "),
                    Text(_("MOUNT POINT")),
                    Text(_("SIZE"), align='center'),
                    Text(_("TYPE")),
                    Text(_("DEVICE TYPE")),
                    Text(" "),
                    Text(" "),
                ]
            ])
        ]

        for i, mi in enumerate(mountinfos):
            path_markup = mi.path
            if path_markup == "":
                path_markup = "SWAP"
            else:
                for j in range(i - 1, -1, -1):
                    mi2 = mountinfos[j]
                    if mi.startswith(mi2):
                        part1 = "/".join(mi.split_path[:len(mi2.split_path)])
                        part2 = "/".join([''] +
                                         mi.split_path[len(mi2.split_path):])
                        path_markup = [('info_minor', part1), part2]
                        break
                    if j == 0 and mi2.split_path == ['', '']:
                        path_markup = [
                            ('info_minor', "/"),
                            "/".join(mi.split_path[1:]),
                        ]
            actions = [(_("Unmount"), mi.mount.can_delete(), 'unmount')]
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._mount_action, mi.mount)
            cells = [
                Text("["),
                Text(path_markup),
                Text(mi.size, align='right'),
                Text(mi.fstype),
                Text(mi.desc),
                menu,
                Text("]"),
            ]
            row = make_action_menu_row(cells,
                                       menu,
                                       attr_map='menu_button',
                                       focus_map={
                                           None: 'menu_button focus',
                                           'info_minor': 'menu_button focus',
                                       })
            rows.append(row)
        self.table.set_contents(rows)
        if self.table._w.focus_position >= len(rows):
            self.table._w.focus_position = len(rows) - 1