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