Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/user_interaction/partitioning_conf.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/user_interaction/partitioning_conf.py')
-rw-r--r--archinstall/lib/user_interaction/partitioning_conf.py74
1 files changed, 41 insertions, 33 deletions
diff --git a/archinstall/lib/user_interaction/partitioning_conf.py b/archinstall/lib/user_interaction/partitioning_conf.py
index bfff5705..f2e6b881 100644
--- a/archinstall/lib/user_interaction/partitioning_conf.py
+++ b/archinstall/lib/user_interaction/partitioning_conf.py
@@ -5,7 +5,7 @@ from typing import List, Any, Dict, Union, TYPE_CHECKING, Callable, Optional
from ..menu import Menu
from ..menu.menu import MenuSelectionType
-from ..output import log
+from ..output import log, FormattedOutput
from ..disk.validators import fs_types
@@ -28,16 +28,31 @@ def current_partition_layout(partitions: List[Dict[str, Any]], with_idx: bool =
pad_right = spaces - pad_left
return f'{pad_right * " "}{name}{pad_left * " "}|'
+ def flatten_data(data: Dict[str, Any]) -> Dict[str, Any]:
+ flattened = {}
+ for k, v in data.items():
+ if k == 'filesystem':
+ flat = flatten_data(v)
+ flattened.update(flat)
+ elif k == 'btrfs':
+ # we're going to create a separate table for the btrfs subvolumes
+ pass
+ else:
+ flattened[k] = v
+ return flattened
+
+ display_data: List[Dict[str, Any]] = [flatten_data(entry) for entry in partitions]
+
column_names = {}
# this will add an initial index to the table for each partition
if with_idx:
- column_names['index'] = max([len(str(len(partitions))), len('index')])
+ column_names['index'] = max([len(str(len(display_data))), len('index')])
# determine all attribute names and the max length
- # of the value among all partitions to know the width
+ # of the value among all display_data to know the width
# of the table cells
- for p in partitions:
+ for p in display_data:
for attribute, value in p.items():
if attribute in column_names.keys():
column_names[attribute] = max([column_names[attribute], len(str(value)), len(attribute)])
@@ -50,7 +65,7 @@ def current_partition_layout(partitions: List[Dict[str, Any]], with_idx: bool =
current_layout = f'{current_layout[:-1]}\n{"-" * len(current_layout)}\n'
- for idx, p in enumerate(partitions):
+ for idx, p in enumerate(display_data):
row = ''
for name, max_len in column_names.items():
if name == 'index':
@@ -62,6 +77,13 @@ def current_partition_layout(partitions: List[Dict[str, Any]], with_idx: bool =
current_layout += f'{row[:-1]}\n'
+ # we'll create a separate table for the btrfs subvolumes
+ btrfs_subvolumes = [partition['btrfs']['subvolumes'] for partition in partitions if partition.get('btrfs', None)]
+ if len(btrfs_subvolumes) > 0:
+ for subvolumes in btrfs_subvolumes:
+ output = FormattedOutput.as_table(subvolumes)
+ current_layout += f'\n{output}'
+
if with_title:
title = str(_('Current partition layout'))
return f'\n\n{title}:\n\n{current_layout}'
@@ -118,23 +140,10 @@ def get_default_partition_layout(
return suggest_multi_disk_layout(block_devices, advanced_options=advanced_options)
-def select_individual_blockdevice_usage(block_devices: list) -> Dict[str, Any]:
- result = {}
-
- for device in block_devices:
- layout = manage_new_and_existing_partitions(device)
- result[device.path] = layout
-
- return result
-
-
def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str, Any]: # noqa: max-complexity: 50
block_device_struct = {"partitions": [partition.__dump__() for partition in block_device.partitions.values()]}
original_layout = copy.deepcopy(block_device_struct)
- # Test code: [part.__dump__() for part in block_device.partitions.values()]
- # TODO: Squeeze in BTRFS subvolumes here
-
new_partition = str(_('Create a new partition'))
suggest_partition_layout = str(_('Suggest partition layout'))
delete_partition = str(_('Delete a partition'))
@@ -187,6 +196,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
return original_layout
elif task == save_and_exit:
break
+
if task == new_partition:
from ..disk import valid_parted_position
@@ -200,8 +210,9 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
if fs_choice.type_ == MenuSelectionType.Esc:
continue
- prompt = _('Enter the start sector (percentage or block number, default: {}): ').format(
- block_device.first_free_sector)
+ prompt = str(_('Enter the start sector (percentage or block number, default: {}): ')).format(
+ block_device.first_free_sector
+ )
start = input(prompt).strip()
if not start.strip():
@@ -210,8 +221,9 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
else:
end_suggested = '100%'
- prompt = _('Enter the end sector of the partition (percentage or block number, ex: {}): ').format(
- end_suggested)
+ prompt = str(_('Enter the end sector of the partition (percentage or block number, ex: {}): ')).format(
+ end_suggested
+ )
end = input(prompt).strip()
if not end.strip():
@@ -224,7 +236,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
continue
block_device_struct["partitions"].append({
- "type": "primary", # Strictly only allowed under MSDOS, but GPT accepts it so it's "safe" to inject
+ "type": "primary", # Strictly only allowed under MS-DOS, but GPT accepts it so it's "safe" to inject
"start": start,
"size": end,
"mountpoint": None,
@@ -351,18 +363,16 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
if partition is not None:
if not block_device_struct["partitions"][partition].get('btrfs', {}):
block_device_struct["partitions"][partition]['btrfs'] = {}
- if not block_device_struct["partitions"][partition]['btrfs'].get('subvolumes', {}):
- block_device_struct["partitions"][partition]['btrfs']['subvolumes'] = {}
+ if not block_device_struct["partitions"][partition]['btrfs'].get('subvolumes', []):
+ block_device_struct["partitions"][partition]['btrfs']['subvolumes'] = []
prev = block_device_struct["partitions"][partition]['btrfs']['subvolumes']
- result = SubvolumeList(_("Manage btrfs subvolumes for current partition"),prev).run()
- if result:
- block_device_struct["partitions"][partition]['btrfs']['subvolumes'] = result
- else:
- del block_device_struct["partitions"][partition]['btrfs']
+ result = SubvolumeList(_("Manage btrfs subvolumes for current partition"), prev).run()
+ block_device_struct["partitions"][partition]['btrfs']['subvolumes'] = result
return block_device_struct
+
def select_encrypted_partitions(
title :str,
partitions :List[Partition],
@@ -374,11 +384,9 @@ def select_encrypted_partitions(
if len(partition_indexes) == 0:
return None
- title = _('Select which partitions to mark for formatting:')
-
# show current partition layout:
if len(partitions):
- title += current_partition_layout(partitions) + '\n'
+ title += current_partition_layout(partitions, with_idx=True) + '\n'
choice = Menu(title, partition_indexes, multi=multiple).run()