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
def refresh_model_inputs(self): devices = [ d for d in self.parent.model.all_devices() if (d.available() == self.show_available or ( not self.show_available and d.has_unavailable_partition())) ] if len(devices) == 0: self._w = Padding.push_2(self._no_devices_content) self.table.table_rows = [] return self._w = self.table log.debug('FileSystemView: building device list') rows = [] rows.append( Color.info_minor( TableRow([ Text(""), (2, Text(_("DEVICE"))), Text(_("TYPE")), Text(_("SIZE"), align="center"), Text(""), Text(""), ]))) for device in devices: for obj, cells in summarize_device( device, lambda part: part.available() == self.show_available): if obj is not None: menu = self._action_menu_for_device(obj) else: menu = Text("") if obj is device: start, end = '[', ']' else: start, end = '', '' cells = [Text(start)] + cells + [menu, Text(end)] if obj is not None: rows.append(make_action_menu_row(cells, menu)) else: rows.append(TableRow(cells)) if (self.show_available and device.used > 0 and device.free_for_partitions > 0): free = humanize_size(device.free_for_partitions) rows.append( TableRow([ Text(""), (3, Color.info_minor(Text(_("free space")))), Text(free, align="right"), Text(""), Text(""), ])) rows.append(TableRow([Text("")])) self.table.set_contents(rows[:-1]) if self.table._w.focus_position >= len(rows): self.table._w.focus_position = len(rows) - 1 while not self.table._w.focus.selectable(): self.table._w.focus_position -= 1
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("")), ])
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("")), ])
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))
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
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
def refresh_model_inputs(self): devices = [ d for d in self.parent.model.all_devices() if (d.available() == self.show_available or (not self.show_available and d.has_unavailable_partition())) ] if len(devices) == 0: self._w = self._no_devices_content self.table.table_rows = [] return self._w = self.table log.debug('FileSystemView: building device list') rows = [] def _usage_label(obj): cd = obj.constructed_device() if cd is not None: return _("{component_name} of {name}").format( component_name=cd.component_name, name=cd.name) fs = obj.fs() if fs is not None: m = fs.mount() if m: return _( "formatted as {fstype}, mounted at {path}").format( fstype=fs.fstype, path=m.path) else: return _("formatted as {fstype}, not mounted").format( fstype=fs.fstype) else: return _("unused") rows.append(TableRow([Color.info_minor(heading) for heading in [ Text(" "), Text(_("DEVICE")), Text(_("SIZE"), align="center"), Text(_("TYPE")), Text(" "), Text(" "), ]])) for device in devices: menu = self._action_menu_for_device(device) cells = [ Text("["), Text(device.label), Text("{:>9}".format(humanize_size(device.size))), Text(device.desc()), menu, Text("]"), ] row = make_action_menu_row(cells, menu) rows.append(row) if not device.partitions(): rows.append(TableRow([ Text(""), (3, Text(" " + _usage_label(device))), Text(""), Text(""), ])) else: for part in device.partitions(): if part.available() != self.show_available: continue menu = self._action_menu_for_device(part) part_size = "{:>9} ({}%)".format( humanize_size(part.size), int(100 * part.size / device.size)) cells = [ Text("["), Text(" " + part.short_label), (2, Text(part_size)), menu, Text("]"), ] row = make_action_menu_row(cells, menu, cursor_x=4) rows.append(row) if part.flag == "bios_grub": label = "bios_grub" else: label = _usage_label(part) rows.append(TableRow([ Text(""), (3, Text(" " + label)), Text(""), Text(""), ])) if (self.show_available and device.used > 0 and device.free_for_partitions > 0): size = device.size free = device.free_for_partitions percent = str(int(100 * free / size)) if percent == "0": percent = "%.2f" % (100 * free / size,) size_text = "{:>9} ({}%)".format( humanize_size(free), percent) rows.append(TableRow([ Text(""), Text(" " + _("free space")), (2, Text(size_text)), Text(""), Text(""), ])) self.table.set_contents(rows) if self.table._w.focus_position >= len(rows): self.table._w.focus_position = len(rows) - 1 while not self.table._w.focus.selectable(): self.table._w.focus_position -= 1