pmbootstrap/pmb/parse/binfmt_info.py

34 lines
1006 B
Python
Raw Normal View History

2022-01-02 21:38:21 +00:00
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
2017-05-26 20:08:45 +00:00
import logging
import pmb.config
2017-05-26 20:08:45 +00:00
# Get magic and mask from binfmt info file
# Return: {magic: ..., mask: ...}
2021-10-16 16:15:54 +00:00
def binfmt_info(arch_qemu):
2017-05-26 20:08:45 +00:00
# Parse the info file
full = {}
info = pmb.config.pmb_src + "/pmb/data/qemu-user-binfmt.txt"
logging.verbose("parsing: " + info)
2017-05-26 20:08:45 +00:00
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]
2017-05-26 20:08:45 +00:00
full[key] = value[1:-2]
ret = {}
logging.verbose("filtering by architecture: " + arch_qemu)
2017-05-26 20:08:45 +00:00
for type in ["mask", "magic"]:
key = arch_qemu + "_" + type
2017-05-26 20:08:45 +00:00
if key not in full:
raise RuntimeError(
f"Could not find key {key} in binfmt info file: {info}")
2017-05-26 20:08:45 +00:00
ret[type] = full[key]
logging.verbose("=> " + str(ret))
2017-05-26 20:08:45 +00:00
return ret