index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Andreas Baumann <mail@andreasbaumann.cc> | 2024-05-10 15:56:28 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2024-05-10 15:56:28 +0200 |
commit | 683da22298abbd90f51d4dd38a7ec4b0dfb04555 (patch) | |
tree | ec2ac04967f9277df038edc362201937b331abe5 /archinstall/lib/utils/util.py | |
parent | af7ab9833c9f9944874f0162ae0975175ddc628d (diff) | |
parent | 3381cd55673e5105697d354cf4a1be9a7bcef062 (diff) |
-rw-r--r-- | archinstall/lib/utils/util.py | 51 |
diff --git a/archinstall/lib/utils/util.py b/archinstall/lib/utils/util.py new file mode 100644 index 00000000..2e42b3cf --- /dev/null +++ b/archinstall/lib/utils/util.py @@ -0,0 +1,51 @@ +from pathlib import Path +from typing import Any, TYPE_CHECKING, Optional, List + +from ..output import FormattedOutput +from ..output import info + +if TYPE_CHECKING: + _: Any + + +def prompt_dir(text: str, header: Optional[str] = None) -> Path: + if header: + print(header) + + while True: + path = input(text).strip(' ') + dest_path = Path(path) + if dest_path.exists() and dest_path.is_dir(): + return dest_path + info(_('Not a valid directory: {}').format(dest_path)) + + +def is_subpath(first: Path, second: Path): + """ + Check if _first_ a subpath of _second_ + """ + try: + first.relative_to(second) + return True + except ValueError: + return False + + +def format_cols(items: List[str], header: Optional[str] = None) -> str: + if header: + text = f'{header}:\n' + else: + text = '' + + nr_items = len(items) + if nr_items <= 4: + col = 1 + elif nr_items <= 8: + col = 2 + elif nr_items <= 12: + col = 3 + else: + col = 4 + + text += FormattedOutput.as_columns(items, col) + return text |