refactor!: port shell scripts to Python package
Bash scripts were untestable and duplicated device/LUKS/mount logic; the lim/ package centralizes it behind one subprocess wrapper and a YAML image catalog (single point of truth). BREAKING CHANGE: scripts/*.sh removed. Use `lim --type <cmd>`; new types mount/umount/single-boot/raid1-boot/lock/unlock/import/export replace direct script calls. --extra is deprecated and ignored. - distributions.yml + lim/catalog.py hold the image catalog (PyYAML) - pytest suite: 102 tests with mocked subprocess (tests/unit) and a 250-line max file-length guard (tests/lint) - ruff strict (select ALL), GitHub Actions CI, Dependabot; Travis gone - Makefile: install (symlink ~/.local/bin/lim) and test targets - fixes over bash: SUDO_USER-aware chown, mmcblk/nvme partition paths, sha512 checksum support, whole-pipeline failure detection, blkid UUID fallback for pre-mounted images, conditional fstab seeding for PARTUUID/LABEL images, clean errors for missing binaries
This commit is contained in:
38
lim/storage/common.py
Normal file
38
lim/storage/common.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Shared path derivation for encrypted storage setups."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from lim import device as device_module
|
||||
from lim import ui
|
||||
from lim.device import Device
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class StorageTarget:
|
||||
"""An encrypted drive plus all derived mapper/mount/partition paths."""
|
||||
|
||||
device: Device
|
||||
|
||||
@property
|
||||
def mapper_name(self) -> str:
|
||||
return f"encrypteddrive-{self.device.name}"
|
||||
|
||||
@property
|
||||
def mapper_path(self) -> str:
|
||||
return f"/dev/mapper/{self.mapper_name}"
|
||||
|
||||
@property
|
||||
def mount_path(self) -> str:
|
||||
return f"/media/{self.mapper_name}"
|
||||
|
||||
@property
|
||||
def partition_path(self) -> str:
|
||||
return self.device.partition(1)
|
||||
|
||||
|
||||
def select_storage_target() -> StorageTarget:
|
||||
target = StorageTarget(device_module.select_device())
|
||||
ui.info(f"mapper name set to : {target.mapper_name}")
|
||||
ui.info(f"mapper path set to : {target.mapper_path}")
|
||||
ui.info(f"mount path set to : {target.mount_path}")
|
||||
return target
|
||||
Reference in New Issue
Block a user