mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 03:19:47 +03:00
pmb: Properly type Bootimg (MR 2464)
This could be done better with a real class instead of a TypedDict, but it's better than a regular dict.
This commit is contained in:
parent
f2c7fa1107
commit
826bb4f2dd
3 changed files with 53 additions and 16 deletions
|
@ -3,6 +3,7 @@
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
from pmb.core.arch import Arch
|
from pmb.core.arch import Arch
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
|
from pmb.types import Bootimg
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
import pmb.helpers.cli
|
import pmb.helpers.cli
|
||||||
|
@ -119,21 +120,24 @@ def ask_for_bootimg():
|
||||||
logging.fatal("ERROR: " + str(e) + ". Please try again.")
|
logging.fatal("ERROR: " + str(e) + ". Please try again.")
|
||||||
|
|
||||||
|
|
||||||
def generate_deviceinfo_fastboot_content(bootimg=None):
|
def generate_deviceinfo_fastboot_content(bootimg: Bootimg | None = None) -> str:
|
||||||
if bootimg is None:
|
if bootimg is None:
|
||||||
bootimg = {
|
bootimg = Bootimg(
|
||||||
"cmdline": "",
|
cmdline="",
|
||||||
"qcdt": "false",
|
qcdt="false",
|
||||||
"dtb_second": "false",
|
qcdt_type=None,
|
||||||
"base": "",
|
dtb_offset=None,
|
||||||
"kernel_offset": "",
|
dtb_second="false",
|
||||||
"ramdisk_offset": "",
|
base="",
|
||||||
"second_offset": "",
|
kernel_offset="",
|
||||||
"tags_offset": "",
|
ramdisk_offset="",
|
||||||
"pagesize": "2048",
|
second_offset="",
|
||||||
"mtk_label_kernel": "",
|
tags_offset="",
|
||||||
"mtk_label_ramdisk": "",
|
pagesize="2048",
|
||||||
}
|
header_version=None,
|
||||||
|
mtk_label_kernel="",
|
||||||
|
mtk_label_ramdisk="",
|
||||||
|
)
|
||||||
|
|
||||||
content = f"""\
|
content = f"""\
|
||||||
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
|
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pmb.chroot
|
||||||
import pmb.chroot.other
|
import pmb.chroot.other
|
||||||
import pmb.chroot.apk
|
import pmb.chroot.apk
|
||||||
from pmb.core import Chroot
|
from pmb.core import Chroot
|
||||||
|
from pmb.types import Bootimg
|
||||||
|
|
||||||
|
|
||||||
def is_dtb(path) -> bool:
|
def is_dtb(path) -> bool:
|
||||||
|
@ -73,7 +74,7 @@ def get_qcdt_type(path) -> str | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def bootimg(path: Path) -> dict[str, str]:
|
def bootimg(path: Path) -> Bootimg:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
raise RuntimeError(f"Could not find file '{path}'")
|
raise RuntimeError(f"Could not find file '{path}'")
|
||||||
|
|
||||||
|
@ -176,7 +177,22 @@ def bootimg(path: Path) -> dict[str, str]:
|
||||||
# Cleanup
|
# Cleanup
|
||||||
pmb.chroot.user(["rm", "-r", temp_path])
|
pmb.chroot.user(["rm", "-r", temp_path])
|
||||||
|
|
||||||
return output
|
return Bootimg(
|
||||||
|
cmdline=output["cmdline"],
|
||||||
|
qcdt=output["qcdt"],
|
||||||
|
qcdt_type=output.get("qcdt_type"),
|
||||||
|
dtb_offset=output.get("dtb_offset"),
|
||||||
|
dtb_second=output["dtb_second"],
|
||||||
|
base=output["base"],
|
||||||
|
kernel_offset=output["kernel_offset"],
|
||||||
|
ramdisk_offset=output["ramdisk_offset"],
|
||||||
|
second_offset=output["second_offset"],
|
||||||
|
tags_offset=output["tags_offset"],
|
||||||
|
pagesize=output["pagesize"],
|
||||||
|
header_version=output.get("header_version"),
|
||||||
|
mtk_label_kernel=output["mtk_label_kernel"],
|
||||||
|
mtk_label_ramdisk=output["mtk_label_ramdisk"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def trim_input(f) -> str:
|
def trim_input(f) -> str:
|
||||||
|
|
17
pmb/types.py
17
pmb/types.py
|
@ -29,6 +29,23 @@ class AportGenEntry(TypedDict):
|
||||||
confirm_overwrite: bool
|
confirm_overwrite: bool
|
||||||
|
|
||||||
|
|
||||||
|
class Bootimg(TypedDict):
|
||||||
|
cmdline: str
|
||||||
|
qcdt: str
|
||||||
|
qcdt_type: str | None
|
||||||
|
dtb_offset: str | None
|
||||||
|
dtb_second: str
|
||||||
|
base: str
|
||||||
|
kernel_offset: str
|
||||||
|
ramdisk_offset: str
|
||||||
|
second_offset: str
|
||||||
|
tags_offset: str
|
||||||
|
pagesize: str
|
||||||
|
header_version: str | None
|
||||||
|
mtk_label_kernel: str
|
||||||
|
mtk_label_ramdisk: str
|
||||||
|
|
||||||
|
|
||||||
# Property list generated with:
|
# Property list generated with:
|
||||||
# $ rg --vimgrep "((^|\s)args\.\w+)" --only-matching | cut -d"." -f3 | sort | uniq
|
# $ rg --vimgrep "((^|\s)args\.\w+)" --only-matching | cut -d"." -f3 | sort | uniq
|
||||||
class PmbArgs(Namespace):
|
class PmbArgs(Namespace):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue