Fix - Handle cancel from list manger properly (#4160)
This commit is contained in:
parent
7a0b4c2a30
commit
9bd16e998c
|
|
@ -58,7 +58,7 @@ class AuthenticationMenu(AbstractSubMenu[AuthenticationConfiguration]):
|
|||
|
||||
def _create_user_account(self, preset: list[User] | None = None) -> list[User]:
|
||||
preset = [] if preset is None else preset
|
||||
users = ask_for_additional_users(defined_users=preset)
|
||||
users = ask_for_additional_users(preset=preset)
|
||||
return users
|
||||
|
||||
def _prev_users(self, item: MenuItem) -> str | None:
|
||||
|
|
|
|||
|
|
@ -190,8 +190,12 @@ class PartitioningList(ListManager[DiskSegment]):
|
|||
def get_part_mods(disk_segments: list[DiskSegment]) -> list[PartitionModification]:
|
||||
return [s.segment for s in disk_segments if isinstance(s.segment, PartitionModification)]
|
||||
|
||||
def get_device_mod(self) -> DeviceModification:
|
||||
def show(self) -> DeviceModification | None:
|
||||
disk_segments = super().run()
|
||||
|
||||
if not disk_segments:
|
||||
return None
|
||||
|
||||
partitions = self.get_part_mods(disk_segments)
|
||||
return DeviceModification(self._device, self._wipe, partitions)
|
||||
|
||||
|
|
@ -376,10 +380,13 @@ class PartitioningList(ListManager[DiskSegment]):
|
|||
partition.mount_options = [o for o in partition.mount_options if o != option.value]
|
||||
|
||||
def _set_btrfs_subvolumes(self, partition: PartitionModification) -> None:
|
||||
partition.btrfs_subvols = SubvolumeMenu(
|
||||
subvols = SubvolumeMenu(
|
||||
partition.btrfs_subvols,
|
||||
None,
|
||||
).run()
|
||||
).show()
|
||||
|
||||
if subvols is not None:
|
||||
partition.btrfs_subvols = subvols
|
||||
|
||||
def _prompt_formatting(self, partition: PartitionModification) -> None:
|
||||
# an existing partition can toggle between Exist or Modify
|
||||
|
|
@ -569,7 +576,10 @@ def manual_partitioning(
|
|||
partition_table: PartitionTable,
|
||||
) -> DeviceModification | None:
|
||||
menu_list = PartitioningList(device_mod, partition_table)
|
||||
mod = menu_list.get_device_mod()
|
||||
mod = menu_list.show()
|
||||
|
||||
if not mod:
|
||||
return None
|
||||
|
||||
if menu_list.is_last_choice_cancel():
|
||||
return device_mod
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ class SubvolumeMenu(ListManager[SubvolumeModification]):
|
|||
prompt,
|
||||
)
|
||||
|
||||
def show(self) -> list[SubvolumeModification] | None:
|
||||
return super().run()
|
||||
|
||||
@override
|
||||
def selected_action_display(self, selection: SubvolumeModification) -> str:
|
||||
return str(selection.name)
|
||||
|
|
|
|||
|
|
@ -109,15 +109,20 @@ def get_default_partition_layout(
|
|||
def _manual_partitioning(
|
||||
preset: list[DeviceModification],
|
||||
devices: list[BDevice],
|
||||
) -> list[DeviceModification]:
|
||||
modifications = []
|
||||
) -> list[DeviceModification] | None:
|
||||
modifications: list[DeviceModification] = []
|
||||
|
||||
for device in devices:
|
||||
mod = next(filter(lambda x: x.device == device, preset), None)
|
||||
if not mod:
|
||||
mod = DeviceModification(device, wipe=False)
|
||||
|
||||
if device_mod := manual_partitioning(mod, device_handler.partition_table):
|
||||
modifications.append(device_mod)
|
||||
device_mod = manual_partitioning(mod, device_handler.partition_table)
|
||||
|
||||
if not device_mod:
|
||||
return None
|
||||
|
||||
modifications.append(device_mod)
|
||||
|
||||
return modifications
|
||||
|
||||
|
|
@ -185,13 +190,15 @@ def select_disk_config(preset: DiskLayoutConfiguration | None = None) -> DiskLay
|
|||
)
|
||||
elif result.get_value() == manual_mode:
|
||||
preset_mods = preset.device_modifications if preset else []
|
||||
modifications = _manual_partitioning(preset_mods, devices)
|
||||
partitions = _manual_partitioning(preset_mods, devices)
|
||||
|
||||
if modifications:
|
||||
return DiskLayoutConfiguration(
|
||||
config_type=DiskLayoutType.Manual,
|
||||
device_modifications=modifications,
|
||||
)
|
||||
if not partitions:
|
||||
return preset
|
||||
|
||||
return DiskLayoutConfiguration(
|
||||
config_type=DiskLayoutType.Manual,
|
||||
device_modifications=partitions,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ class UserList(ListManager[User]):
|
|||
prompt,
|
||||
)
|
||||
|
||||
def show(self) -> list[User] | None:
|
||||
return super().run()
|
||||
|
||||
@override
|
||||
def selected_action_display(self, selection: User) -> str:
|
||||
return selection.username
|
||||
|
|
@ -106,6 +109,10 @@ class UserList(ListManager[User]):
|
|||
return User(username, password, sudo)
|
||||
|
||||
|
||||
def ask_for_additional_users(prompt: str = '', defined_users: list[User] = []) -> list[User]:
|
||||
users = UserList(prompt, defined_users).run()
|
||||
def ask_for_additional_users(prompt: str = '', preset: list[User] = []) -> list[User]:
|
||||
users = UserList(prompt, preset).show()
|
||||
|
||||
if users is None:
|
||||
return preset
|
||||
|
||||
return users
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ class ManualNetworkConfig(ListManager[Nic]):
|
|||
prompt,
|
||||
)
|
||||
|
||||
def show(self) -> list[Nic] | None:
|
||||
return super().run()
|
||||
|
||||
@override
|
||||
def selected_action_display(self, selection: Nic) -> str:
|
||||
return selection.iface if selection.iface else ''
|
||||
|
|
@ -198,7 +201,7 @@ def ask_to_configure_network(preset: NetworkConfiguration | None) -> NetworkConf
|
|||
return NetworkConfiguration(NicType.NM_IWD)
|
||||
case NicType.MANUAL:
|
||||
preset_nics = preset.nics if preset else []
|
||||
nics = ManualNetworkConfig(tr('Configure interfaces'), preset_nics).run()
|
||||
nics = ManualNetworkConfig(tr('Configure interfaces'), preset_nics).show()
|
||||
|
||||
if nics:
|
||||
return NetworkConfiguration(NicType.MANUAL, nics)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ class ListManager[ValueT]:
|
|||
:param sub_menu_actions: list of actions available for a chosen entry
|
||||
type param: list
|
||||
"""
|
||||
self._original_data = copy.deepcopy(entries)
|
||||
self._data = copy.deepcopy(entries)
|
||||
|
||||
self._prompt = prompt
|
||||
|
|
@ -54,7 +53,7 @@ class ListManager[ValueT]:
|
|||
return self._last_choice == self._cancel_action
|
||||
return False
|
||||
|
||||
def run(self) -> list[ValueT]:
|
||||
def run(self) -> list[ValueT] | None:
|
||||
additional_options = self._base_actions + self._terminate_actions
|
||||
|
||||
while True:
|
||||
|
|
@ -94,7 +93,7 @@ class ListManager[ValueT]:
|
|||
self._last_choice = value
|
||||
|
||||
if result.get_value() == self._cancel_action:
|
||||
return self._original_data # return the original list
|
||||
return None
|
||||
else:
|
||||
return self._data
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class CustomMirrorRepositoriesList(ListManager[CustomRepository]):
|
|||
'',
|
||||
)
|
||||
|
||||
def show(self) -> list[CustomRepository] | None:
|
||||
return super().run()
|
||||
|
||||
@override
|
||||
def selected_action_display(self, selection: CustomRepository) -> str:
|
||||
return selection.name
|
||||
|
|
@ -158,6 +161,9 @@ class CustomMirrorServersList(ListManager[CustomServer]):
|
|||
'',
|
||||
)
|
||||
|
||||
def show(self) -> list[CustomServer] | None:
|
||||
return super().run()
|
||||
|
||||
@override
|
||||
def selected_action_display(self, selection: CustomServer) -> str:
|
||||
return selection.url
|
||||
|
|
@ -332,12 +338,20 @@ def select_mirror_regions(preset: list[MirrorRegion]) -> list[MirrorRegion]:
|
|||
|
||||
|
||||
def add_custom_mirror_servers(preset: list[CustomServer] = []) -> list[CustomServer]:
|
||||
custom_mirrors = CustomMirrorServersList(preset).run()
|
||||
custom_mirrors = CustomMirrorServersList(preset).show()
|
||||
|
||||
if not custom_mirrors:
|
||||
return preset
|
||||
|
||||
return custom_mirrors
|
||||
|
||||
|
||||
def select_custom_mirror(preset: list[CustomRepository] = []) -> list[CustomRepository]:
|
||||
custom_mirrors = CustomMirrorRepositoriesList(preset).run()
|
||||
custom_mirrors = CustomMirrorRepositoriesList(preset).show()
|
||||
|
||||
if not custom_mirrors:
|
||||
return preset
|
||||
|
||||
return custom_mirrors
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue