arch-image-builder/builder/disk/layout/build.py
BigfootACA e6c6ab6bf7 Initial commit
Signed-off-by: BigfootACA <bigfoot@classfun.cn>
2024-05-17 23:04:34 +08:00

39 lines
1.2 KiB
Python

from builder.disk.content import ImageContentBuilder
from builder.disk.layout.disk import Disk
from builder.disk.image import ImageBuilder
from builder.lib.config import ArchBuilderConfigError
from builder.lib.context import ArchBuilderContext
class DiskLayoutBuilder(ImageContentBuilder):
ctx: ArchBuilderContext
def build(self):
self.ctx = self.builder.ctx
cfg = self.builder.config
if "layout" not in cfg:
raise ArchBuilderConfigError("layout not set")
if "partitions" not in cfg:
raise ArchBuilderConfigError("partitions not set")
layout = Disk.find_layout(cfg["layout"])
if layout is None:
raise ArchBuilderConfigError(f"layout {layout} not found")
disk = layout(
path=self.builder.device,
sector=self.builder.sector
)
disk.create()
disk.set_from(cfg)
builders: list[ImageBuilder] = []
for part in cfg["partitions"]:
p = disk.add_partition_from(part)
if "type" in part:
b = ImageBuilder(self.ctx, part, self.builder)
if p.partlabel: b.properties["PARTLABEL"] = p.partlabel
if p.partuuid: b.properties["PARTUUID"] = p.partuuid
b.sector, b.offset, b.size = disk.sector, p.start, p.size
builders.append(b)
disk.save()
for builder in builders:
builder.build()