Exclude archiso devices from selectable blockdevices (#1481)
* Exclude liveusb from disk selection * Exclude arch iso from being an option * Update * Update * Update * Mypy Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
parent
5959cde5cb
commit
40e4046633
|
|
@ -15,4 +15,4 @@ jobs:
|
||||||
# one day this will be enabled
|
# one day this will be enabled
|
||||||
# run: mypy --strict --module archinstall || exit 0
|
# run: mypy --strict --module archinstall || exit 0
|
||||||
- name: run mypy
|
- name: run mypy
|
||||||
run: mypy --follow-imports=silent archinstall/lib/menu/selection_menu.py archinstall/lib/menu/global_menu.py archinstall/lib/models/network_configuration.py archinstall/lib/menu/list_manager.py archinstall/lib/user_interaction/network_conf.py archinstall/lib/models/users.py archinstall/lib/disk/blockdevice.py archinstall/lib/user_interaction/subvolume_config.py archinstall/lib/disk/btrfs/btrfs_helpers.py archinstall/lib/translationhandler.py
|
run: mypy --follow-imports=silent archinstall/lib/menu/selection_menu.py archinstall/lib/menu/global_menu.py archinstall/lib/models/network_configuration.py archinstall/lib/menu/list_manager.py archinstall/lib/user_interaction/network_conf.py archinstall/lib/models/users.py archinstall/lib/disk/blockdevice.py archinstall/lib/user_interaction/subvolume_config.py archinstall/lib/disk/btrfs/btrfs_helpers.py archinstall/lib/translationhandler.py archinstall/lib/disk/diskinfo.py
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import dataclasses
|
||||||
|
import json
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
from ..general import SysCommand
|
||||||
|
from ..exceptions import DiskError
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LsblkInfo:
|
||||||
|
size: int = 0
|
||||||
|
log_sec: int = 0
|
||||||
|
pttype: Optional[str] = None
|
||||||
|
rota: bool = False
|
||||||
|
tran: Optional[str] = None
|
||||||
|
ptuuid: Optional[str] = None
|
||||||
|
partuuid: Optional[str] = None
|
||||||
|
uuid: Optional[str] = None
|
||||||
|
fstype: Optional[str] = None
|
||||||
|
type: Optional[str] = None
|
||||||
|
mountpoints: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
def get_lsblk_info(dev_path: str) -> LsblkInfo:
|
||||||
|
fields = [f.name for f in dataclasses.fields(LsblkInfo)]
|
||||||
|
lsblk_fields = ','.join([f.upper().replace('_', '-') for f in fields])
|
||||||
|
|
||||||
|
output = SysCommand(f'lsblk --json -b -o+{lsblk_fields} {dev_path}').decode('UTF-8')
|
||||||
|
|
||||||
|
if output:
|
||||||
|
block_devices = json.loads(output)
|
||||||
|
info = block_devices['blockdevices'][0]
|
||||||
|
lsblk_info = LsblkInfo()
|
||||||
|
|
||||||
|
for f in fields:
|
||||||
|
setattr(lsblk_info, f, info[f.replace('_', '-')])
|
||||||
|
|
||||||
|
return lsblk_info
|
||||||
|
|
||||||
|
raise DiskError(f'Failed to read disk "{dev_path}" with lsblk')
|
||||||
|
|
@ -6,13 +6,12 @@ import pathlib
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from typing import Union, List, Iterator, Dict, Optional, Any, TYPE_CHECKING
|
from typing import Union, List, Iterator, Dict, Optional, Any, TYPE_CHECKING
|
||||||
# https://stackoverflow.com/a/39757388/929999
|
# https://stackoverflow.com/a/39757388/929999
|
||||||
|
from .diskinfo import get_lsblk_info
|
||||||
from ..models.subvolume import Subvolume
|
from ..models.subvolume import Subvolume
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from .partition import Partition
|
|
||||||
|
|
||||||
from .blockdevice import BlockDevice
|
from .blockdevice import BlockDevice
|
||||||
from .dmcryptdev import DMCryptDev
|
from .dmcryptdev import DMCryptDev
|
||||||
from .mapperdev import MapperDev
|
from .mapperdev import MapperDev
|
||||||
|
|
@ -21,6 +20,10 @@ from ..general import SysCommand
|
||||||
from ..output import log
|
from ..output import log
|
||||||
from ..storage import storage
|
from ..storage import storage
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .partition import Partition
|
||||||
|
|
||||||
|
|
||||||
ROOT_DIR_PATTERN = re.compile('^.*?/devices')
|
ROOT_DIR_PATTERN = re.compile('^.*?/devices')
|
||||||
GIGA = 2 ** 30
|
GIGA = 2 ** 30
|
||||||
|
|
||||||
|
|
@ -204,11 +207,18 @@ def get_blockdevice_uevent(dev_name :str) -> Dict[str, Any]:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def all_disks() -> List[BlockDevice]:
|
def all_disks() -> List[BlockDevice]:
|
||||||
log(f"[Deprecated] archinstall.all_disks() is deprecated. Use archinstall.all_blockdevices() with the appropriate filters instead.", level=logging.WARNING, fg="yellow")
|
log(f"[Deprecated] archinstall.all_disks() is deprecated. Use archinstall.all_blockdevices() with the appropriate filters instead.", level=logging.WARNING, fg="yellow")
|
||||||
return all_blockdevices(partitions=False, mappers=False)
|
return all_blockdevices(partitions=False, mappers=False)
|
||||||
|
|
||||||
def all_blockdevices(mappers=False, partitions=False, error=False) -> Dict[str, Any]:
|
|
||||||
|
def all_blockdevices(
|
||||||
|
mappers: bool = False,
|
||||||
|
partitions: bool = False,
|
||||||
|
error: bool = False,
|
||||||
|
exclude_iso_dev: bool = True
|
||||||
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Returns BlockDevice() and Partition() objects for all available devices.
|
Returns BlockDevice() and Partition() objects for all available devices.
|
||||||
"""
|
"""
|
||||||
|
|
@ -227,6 +237,13 @@ def all_blockdevices(mappers=False, partitions=False, error=False) -> Dict[str,
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if exclude_iso_dev:
|
||||||
|
# exclude all devices associated with the iso boot locations
|
||||||
|
iso_devs = ['/run/archiso/airootfs', '/run/archiso/bootmnt']
|
||||||
|
lsblk_info = get_lsblk_info(device_path)
|
||||||
|
if any([dev in lsblk_info.mountpoints for dev in iso_devs]):
|
||||||
|
continue
|
||||||
|
|
||||||
information = blkid(f'blkid -p -o export {device_path}')
|
information = blkid(f'blkid -p -o export {device_path}')
|
||||||
except SysCallError as ex:
|
except SysCallError as ex:
|
||||||
if ex.exit_code in (512, 2):
|
if ex.exit_code in (512, 2):
|
||||||
|
|
@ -416,7 +433,7 @@ def get_partitions_in_use(mountpoint :str) -> Dict[str, Any]:
|
||||||
# Since all_blockdevices() returns PosixPath objects, we need to convert
|
# Since all_blockdevices() returns PosixPath objects, we need to convert
|
||||||
# findmnt paths to pathlib.Path() first:
|
# findmnt paths to pathlib.Path() first:
|
||||||
mountpoint = pathlib.Path(mountpoint)
|
mountpoint = pathlib.Path(mountpoint)
|
||||||
|
|
||||||
if mountpoint in block_devices_mountpoints:
|
if mountpoint in block_devices_mountpoints:
|
||||||
if mountpoint not in mounts:
|
if mountpoint not in mounts:
|
||||||
mounts[mountpoint] = block_devices_mountpoints[mountpoint]
|
mounts[mountpoint] = block_devices_mountpoints[mountpoint]
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ class GlobalMenu(GeneralMenu):
|
||||||
|
|
||||||
return ntp
|
return ntp
|
||||||
|
|
||||||
def _select_harddrives(self, old_harddrives : list) -> List:
|
def _select_harddrives(self, old_harddrives: List[str] = []) -> List:
|
||||||
harddrives = select_harddrives(old_harddrives)
|
harddrives = select_harddrives(old_harddrives)
|
||||||
|
|
||||||
if harddrives is not None:
|
if harddrives is not None:
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,6 @@ def select_harddrives(preset: List[str] = []) -> List[str]:
|
||||||
hard_drives = all_blockdevices(partitions=False).values()
|
hard_drives = all_blockdevices(partitions=False).values()
|
||||||
options = {f'{option}': option for option in hard_drives}
|
options = {f'{option}': option for option in hard_drives}
|
||||||
|
|
||||||
if preset:
|
|
||||||
preset_disks = {f'{option}': option for option in preset}
|
|
||||||
else:
|
|
||||||
preset_disks = {}
|
|
||||||
|
|
||||||
title = str(_('Select one or more hard drives to use and configure\n'))
|
title = str(_('Select one or more hard drives to use and configure\n'))
|
||||||
title += str(_('Any modifications to the existing setting will reset the disk layout!'))
|
title += str(_('Any modifications to the existing setting will reset the disk layout!'))
|
||||||
|
|
||||||
|
|
@ -65,7 +60,7 @@ def select_harddrives(preset: List[str] = []) -> List[str]:
|
||||||
selected_harddrive = Menu(
|
selected_harddrive = Menu(
|
||||||
title,
|
title,
|
||||||
list(options.keys()),
|
list(options.keys()),
|
||||||
preset_values=list(preset_disks.keys()),
|
preset_values=preset,
|
||||||
multi=True,
|
multi=True,
|
||||||
raise_error_on_interrupt=True,
|
raise_error_on_interrupt=True,
|
||||||
raise_error_warning_msg=warning
|
raise_error_warning_msg=warning
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue