Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk/partitioning_menu.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/disk/partitioning_menu.py')
-rw-r--r--archinstall/lib/disk/partitioning_menu.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/archinstall/lib/disk/partitioning_menu.py b/archinstall/lib/disk/partitioning_menu.py
index 549c7f34..c5263b82 100644
--- a/archinstall/lib/disk/partitioning_menu.py
+++ b/archinstall/lib/disk/partitioning_menu.py
@@ -5,7 +5,7 @@ from pathlib import Path
from typing import Any, Dict, TYPE_CHECKING, List, Optional, Tuple
from .device_model import PartitionModification, FilesystemType, BDevice, Size, Unit, PartitionType, PartitionFlag, \
- ModificationStatus, DeviceGeometry
+ ModificationStatus, DeviceGeometry, SectorSize
from ..menu import Menu, ListManager, MenuSelection, TextInput
from ..output import FormattedOutput, warn
from .subvolume_menu import SubvolumeMenu
@@ -194,42 +194,47 @@ class PartitioningList(ListManager):
def _validate_value(
self,
- sector_size: Size,
+ sector_size: SectorSize,
total_size: Size,
- value: str
+ text: str,
+ start: Optional[Size]
) -> Optional[Size]:
- match = re.match(r'([0-9]+)([a-zA-Z|%]*)', value, re.I)
+ match = re.match(r'([0-9]+)([a-zA-Z|%]*)', text, re.I)
if match:
- value, unit = match.groups()
+ str_value, unit = match.groups()
- if unit == '%':
- unit = Unit.Percent.name
+ if unit == '%' and start:
+ available = total_size - start
+ value = int(available.value * (int(str_value) / 100))
+ unit = available.unit.name
+ else:
+ value = int(str_value)
if unit and unit not in Unit.get_all_units():
return None
unit = Unit[unit] if unit else Unit.sectors
- return Size(int(value), unit, sector_size, total_size)
+ return Size(value, unit, sector_size)
return None
def _enter_size(
self,
- sector_size: Size,
+ sector_size: SectorSize,
total_size: Size,
prompt: str,
- default: Size
+ default: Size,
+ start: Optional[Size],
) -> Size:
while True:
value = TextInput(prompt).run().strip()
-
size: Optional[Size] = None
if not value:
size = default
else:
- size = self._validate_value(sector_size, total_size, value)
+ size = self._validate_value(sector_size, total_size, value, start)
if size:
return size
@@ -247,7 +252,7 @@ class PartitioningList(ListManager):
total_bytes = device_info.total_size.format_size(Unit.B)
prompt += str(_('Total: {} / {}')).format(total_sectors, total_bytes) + '\n\n'
- prompt += str(_('All entered values can be suffixed with a unit: B, KB, KiB, MB, MiB...')) + '\n'
+ prompt += str(_('All entered values can be suffixed with a unit: %, B, KB, KiB, MB, MiB...')) + '\n'
prompt += str(_('If no unit is provided, the value is interpreted as sectors')) + '\n'
print(prompt)
@@ -260,13 +265,14 @@ class PartitioningList(ListManager):
device_info.sector_size,
device_info.total_size,
start_prompt,
- default_start
+ default_start,
+ None
)
if start_size.value == largest_free_area.start:
end_size = Size(largest_free_area.end, Unit.sectors, device_info.sector_size)
else:
- end_size = Size(100, Unit.Percent, total_size=device_info.total_size)
+ end_size = device_info.total_size
# prompt until valid end sector was entered
end_prompt = str(_('Enter end (default: {}): ')).format(end_size.as_text())
@@ -274,7 +280,8 @@ class PartitioningList(ListManager):
device_info.sector_size,
device_info.total_size,
end_prompt,
- end_size
+ end_size,
+ start_size
)
return start_size, end_size