mirror of
https://github.com/BigfootACA/arch-image-builder.git
synced 2024-11-27 05:33:29 +08:00
builder: disk: add image file supports
Signed-off-by: BigfootACA <bigfoot@classfun.cn>
This commit is contained in:
parent
8baedd5358
commit
84d8a0c247
27
builder/disk/file.py
Normal file
27
builder/disk/file.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os
|
||||
from logging import getLogger
|
||||
from builder.disk.content import ImageContentBuilder
|
||||
from builder.lib.config import ArchBuilderConfigError
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
class ImageFileBuilder(ImageContentBuilder):
|
||||
def build(self):
|
||||
cmds = ["dd"]
|
||||
ctx = self.builder.ctx
|
||||
cfg = self.builder.config
|
||||
if "file" not in cfg:
|
||||
raise ArchBuilderConfigError("file not set")
|
||||
file: str = cfg["file"]
|
||||
if file.startswith("/"): file = file[1:]
|
||||
path = os.path.join(ctx.get_rootfs(), file)
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(f"image file {path} not found")
|
||||
cmds.append("status=progress")
|
||||
cmds.append(f"if={path}")
|
||||
cmds.append(f"of={self.builder.device}")
|
||||
cmds.append(f"bs={self.builder.sector}")
|
||||
log.info(f"start writing image file {path}")
|
||||
ret = ctx.run_external(cmds)
|
||||
if ret != 0: raise OSError("dd failed")
|
||||
log.info(f"write image file {path} done")
|
@ -2,6 +2,7 @@ from builder.disk.content import ImageContentBuilder
|
||||
from builder.disk.layout.build import DiskLayoutBuilder
|
||||
from builder.disk.filesystem.build import FileSystemBuilder
|
||||
from builder.disk.abootimg import AndroidBootBuilder
|
||||
from builder.disk.file import ImageFileBuilder
|
||||
|
||||
|
||||
types: list[tuple[str, type[ImageContentBuilder]]] = [
|
||||
@ -9,4 +10,5 @@ types: list[tuple[str, type[ImageContentBuilder]]] = [
|
||||
("filesystem", FileSystemBuilder),
|
||||
("aboot", AndroidBootBuilder),
|
||||
("avndboot", AndroidBootBuilder),
|
||||
("image", ImageFileBuilder),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user