pmbootstrap-meow/pmb/parse/binfmt_info.py
Caleb Connolly 71e7af57e6
pmb.helpers.logging: wrap logging module (MR 2252)
We use a custom verbose log level in pmbootstrap, unfortunately it isn't
possible to correctly type this due to some limitations in the logging
library [1], [2].

Given that our usecase is fairly simple, we can just wrap the module
with our own so we only have to tell mypy to ignore the error once
instead of at every callsite.

[1]: https://github.com/cryptax/droidlysis/issues/15
[2]: https://github.com/python/typing/discussions/980

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00

33 lines
1,023 B
Python

# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb.helpers import logging
import pmb.config
# Get magic and mask from binfmt info file
# Return: {magic: ..., mask: ...}
def binfmt_info(arch_qemu):
# Parse the info file
full = {}
info = pmb.config.pmb_src + "/pmb/data/qemu-user-binfmt.txt"
logging.verbose("parsing: " + info)
with open(info, "r") as handle:
for line in handle:
if line.startswith('#') or "=" not in line:
continue
split = line.split("=")
key = split[0].strip()
value = split[1]
full[key] = value[1:-2]
ret = {}
logging.verbose("filtering by architecture: " + arch_qemu)
for type in ["mask", "magic"]:
key = arch_qemu + "_" + type
if key not in full:
raise RuntimeError(
f"Could not find key {key} in binfmt info file: {info}")
ret[type] = full[key]
logging.verbose("=> " + str(ret))
return ret