mirror of
https://github.com/BigfootACA/arch-image-builder.git
synced 2024-11-13 17:03:24 +08:00
39 lines
1.2 KiB
Python
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()
|