Fix 3534 (#3537)
This commit is contained in:
parent
3359779594
commit
d4b16cb406
|
|
@ -464,7 +464,10 @@ class PartitioningList(ListManager[DiskSegment]):
|
||||||
return size
|
return size
|
||||||
|
|
||||||
def _prompt_size(self, free_space: FreeSpace) -> Size:
|
def _prompt_size(self, free_space: FreeSpace) -> Size:
|
||||||
def validate(value: str) -> str | None:
|
def validate(value: str | None) -> str | None:
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
|
||||||
size = self._validate_value(sector_size, max_size, value)
|
size = self._validate_value(sector_size, max_size, value)
|
||||||
if not size:
|
if not size:
|
||||||
return tr('Invalid size')
|
return tr('Invalid size')
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,17 @@ class SubvolumeMenu(ListManager[SubvolumeModification]):
|
||||||
return str(selection.name)
|
return str(selection.name)
|
||||||
|
|
||||||
def _add_subvolume(self, preset: SubvolumeModification | None = None) -> SubvolumeModification | None:
|
def _add_subvolume(self, preset: SubvolumeModification | None = None) -> SubvolumeModification | None:
|
||||||
|
def validate(value: str | None) -> str | None:
|
||||||
|
if value:
|
||||||
|
return None
|
||||||
|
return tr('Value cannot be empty')
|
||||||
|
|
||||||
result = EditMenu(
|
result = EditMenu(
|
||||||
tr('Subvolume name'),
|
tr('Subvolume name'),
|
||||||
alignment=Alignment.CENTER,
|
alignment=Alignment.CENTER,
|
||||||
allow_skip=True,
|
allow_skip=True,
|
||||||
default_text=str(preset.name) if preset else None,
|
default_text=str(preset.name) if preset else None,
|
||||||
|
validator=validate,
|
||||||
).input()
|
).input()
|
||||||
|
|
||||||
match result.type_:
|
match result.type_:
|
||||||
|
|
@ -58,11 +64,12 @@ class SubvolumeMenu(ListManager[SubvolumeModification]):
|
||||||
tr('Subvolume mountpoint'),
|
tr('Subvolume mountpoint'),
|
||||||
header=header,
|
header=header,
|
||||||
allow_skip=True,
|
allow_skip=True,
|
||||||
validate=False,
|
validate=True,
|
||||||
|
must_exist=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
return None
|
return preset
|
||||||
|
|
||||||
return SubvolumeModification(Path(name), path)
|
return SubvolumeModification(Path(name), path)
|
||||||
|
|
||||||
|
|
@ -81,7 +88,7 @@ class SubvolumeMenu(ListManager[SubvolumeModification]):
|
||||||
# was created we'll replace the existing one
|
# was created we'll replace the existing one
|
||||||
data = [d for d in data if d.name != new_subvolume.name]
|
data = [d for d in data if d.name != new_subvolume.name]
|
||||||
data += [new_subvolume]
|
data += [new_subvolume]
|
||||||
elif entry is not None:
|
elif entry is not None: # edit
|
||||||
if action == self._actions[1]: # edit subvolume
|
if action == self._actions[1]: # edit subvolume
|
||||||
new_subvolume = self._add_subvolume(entry)
|
new_subvolume = self._add_subvolume(entry)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -247,13 +247,14 @@ def add_number_of_parallel_downloads(preset: int | None = None) -> int | None:
|
||||||
header += tr(' - Maximum recommended value : {} ( Allows {} parallel downloads at a time )').format(max_recommended, max_recommended) + '\n'
|
header += tr(' - Maximum recommended value : {} ( Allows {} parallel downloads at a time )').format(max_recommended, max_recommended) + '\n'
|
||||||
header += tr(' - Disable/Default : 0 ( Disables parallel downloading, allows only 1 download at a time )\n')
|
header += tr(' - Disable/Default : 0 ( Disables parallel downloading, allows only 1 download at a time )\n')
|
||||||
|
|
||||||
def validator(s: str) -> str | None:
|
def validator(s: str | None) -> str | None:
|
||||||
try:
|
if s is not None:
|
||||||
value = int(s)
|
try:
|
||||||
if value >= 0:
|
value = int(s)
|
||||||
return None
|
if value >= 0:
|
||||||
except Exception:
|
return None
|
||||||
pass
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
return tr('Invalid download number')
|
return tr('Invalid download number')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,10 @@ class UserList(ListManager[User]):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _check_for_correct_username(self, username: str) -> str | None:
|
def _check_for_correct_username(self, username: str | None) -> str | None:
|
||||||
if re.match(r'^[a-z_][a-z0-9_-]*\$?$', username) and len(username) <= 32:
|
if username is not None:
|
||||||
return None
|
if re.match(r'^[a-z_][a-z0-9_-]*\$?$', username) and len(username) <= 32:
|
||||||
|
return None
|
||||||
return tr('The username you entered is invalid')
|
return tr('The username you entered is invalid')
|
||||||
|
|
||||||
def _add_user(self) -> User | None:
|
def _add_user(self) -> User | None:
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,12 @@ class ManualNetworkConfig(ListManager[Nic]):
|
||||||
multi: bool,
|
multi: bool,
|
||||||
preset: str | None = None,
|
preset: str | None = None,
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
def validator(ip: str) -> str | None:
|
def validator(ip: str | None) -> str | None:
|
||||||
|
failure = tr('You need to enter a valid IP in IP-config mode')
|
||||||
|
|
||||||
|
if not ip:
|
||||||
|
return failure
|
||||||
|
|
||||||
if multi:
|
if multi:
|
||||||
ips = ip.split(' ')
|
ips = ip.split(' ')
|
||||||
else:
|
else:
|
||||||
|
|
@ -98,7 +103,7 @@ class ManualNetworkConfig(ListManager[Nic]):
|
||||||
ipaddress.ip_interface(ip)
|
ipaddress.ip_interface(ip)
|
||||||
return None
|
return None
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return tr('You need to enter a valid IP in IP-config mode')
|
return failure
|
||||||
|
|
||||||
result = EditMenu(
|
result = EditMenu(
|
||||||
title,
|
title,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from archinstall.lib.translationhandler import tr
|
from archinstall.lib.translationhandler import tr
|
||||||
from archinstall.tui.curses_menu import EditMenu
|
from archinstall.tui.curses_menu import EditMenu
|
||||||
|
from archinstall.tui.result import ResultType
|
||||||
from archinstall.tui.types import Alignment
|
from archinstall.tui.types import Alignment
|
||||||
|
|
||||||
from ..models.users import Password
|
from ..models.users import Password
|
||||||
|
|
@ -65,14 +66,19 @@ def prompt_dir(
|
||||||
text: str,
|
text: str,
|
||||||
header: str | None = None,
|
header: str | None = None,
|
||||||
validate: bool = True,
|
validate: bool = True,
|
||||||
|
must_exist: bool = True,
|
||||||
allow_skip: bool = False,
|
allow_skip: bool = False,
|
||||||
preset: str | None = None,
|
preset: str | None = None,
|
||||||
) -> Path | None:
|
) -> Path | None:
|
||||||
def validate_path(path: str) -> str | None:
|
def validate_path(path: str | None) -> str | None:
|
||||||
dest_path = Path(path)
|
if path:
|
||||||
|
dest_path = Path(path)
|
||||||
|
|
||||||
if dest_path.exists() and dest_path.is_dir():
|
if must_exist:
|
||||||
return None
|
if dest_path.exists() and dest_path.is_dir():
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
return tr('Not a valid directory')
|
return tr('Not a valid directory')
|
||||||
|
|
||||||
|
|
@ -90,10 +96,15 @@ def prompt_dir(
|
||||||
default_text=preset,
|
default_text=preset,
|
||||||
).input()
|
).input()
|
||||||
|
|
||||||
if allow_skip and not result.has_item():
|
match result.type_:
|
||||||
return None
|
case ResultType.Skip:
|
||||||
|
return None
|
||||||
|
case ResultType.Selection:
|
||||||
|
if not result.text():
|
||||||
|
return None
|
||||||
|
return Path(result.text())
|
||||||
|
|
||||||
return Path(result.text())
|
return None
|
||||||
|
|
||||||
|
|
||||||
def is_subpath(first: Path, second: Path) -> bool:
|
def is_subpath(first: Path, second: Path) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -451,7 +451,7 @@ class EditMenu(AbstractCurses[str]):
|
||||||
title: str,
|
title: str,
|
||||||
edit_width: int = 50,
|
edit_width: int = 50,
|
||||||
header: str | None = None,
|
header: str | None = None,
|
||||||
validator: Callable[[str], str | None] | None = None,
|
validator: Callable[[str | None], str | None] | None = None,
|
||||||
allow_skip: bool = False,
|
allow_skip: bool = False,
|
||||||
allow_reset: bool = False,
|
allow_reset: bool = False,
|
||||||
reset_warning_msg: str | None = None,
|
reset_warning_msg: str | None = None,
|
||||||
|
|
@ -554,7 +554,7 @@ class EditMenu(AbstractCurses[str]):
|
||||||
|
|
||||||
self.clear_all()
|
self.clear_all()
|
||||||
|
|
||||||
if text and self._validator:
|
if self._validator:
|
||||||
if (err := self._validator(text)) is not None:
|
if (err := self._validator(text)) is not None:
|
||||||
self.clear_all()
|
self.clear_all()
|
||||||
entry = ViewportEntry(err, 0, 0, STYLE.ERROR)
|
entry = ViewportEntry(err, 0, 0, STYLE.ERROR)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue