MCPcopy Create free account
hub / github.com/archlinux/archinstall / MenuHelper

Class MenuHelper

archinstall/lib/menu/menu_helper.py:5–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4
5class MenuHelper[ValueT]:
6 def __init__(
7 self,
8 data: list[ValueT],
9 additional_options: list[str] = [],
10 ) -> None:
11 self._separator = ''
12 self._data = data
13 self._additional_options = additional_options
14
15 def create_menu_group(self) -> MenuItemGroup:
16 table_data_mapping = self._table_to_data_mapping(self._data)
17
18 items = []
19 for key, value in table_data_mapping.items():
20 item = MenuItem(key, value=value)
21
22 if value is None:
23 item.read_only = True
24
25 items.append(item)
26
27 group = MenuItemGroup(items, sort_items=False)
28
29 return group
30
31 def _table_to_data_mapping(self, data: list[ValueT]) -> dict[str, ValueT | str | None]:
32 display_data: dict[str, ValueT | str | None] = {}
33
34 if data:
35 table = as_table(data)
36 rows = table.split('\n')
37
38 # these are the header rows of the table
39 display_data = {f'{rows[0]}': None, f'{rows[1]}': None}
40
41 for row, entry in zip(rows[2:], data):
42 display_data[row] = entry
43
44 if self._additional_options:
45 display_data[self._separator] = None
46
47 for option in self._additional_options:
48 display_data[option] = option
49
50 return display_data

Callers 2

_runMethod · 0.90
select_hsmFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected