Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- dnutc [do not use this code]
- Trying to get the same information without lsblk
- got the idea from https://github.com/archlinux/archinstall/blob/master/archinstall/lib/disk.py#L583
- """
- def all_disks():
- for block in Path("/sys/class/block").glob("*"):
- data = dict.fromkeys("path size type mountpoint label name model".split())
- for line in (block / "uevent").read_text().splitlines():
- if not (line := line.strip()):
- continue
- key, value = line.split("=", maxsplit=1)
- key = key.lower().removeprefix("dev")
- if key in ("major", "minor", "partn"):
- continue
- data[key] = value
- data["size"] = int((block / "size").read_bytes()) * 512
- model_file = block / "device/model"
- if model_file.exists():
- data["model"] = model_file.read_text().strip()
- data["path"] = str(Path("/dev", data["name"]))
- with open("/proc/mounts") as fd:
- for line in fd:
- dev, mountpoint, fstype, *_ = line.split()
- if dev == data["path"]:
- _, data["mountpoint"], data["fstype"], *_ = line.split()
- # what if more than on mount?
- continue
- yield data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement