osbuild: refactor stage information
For all currently supported modules, i.e. stages and assemblers,
convert the STAGE_DESC and STAGE_INFO into a proper doc-string.
Rename the STAGE_OPTS into SCHEMA.
Refactor meta.ModuleInfo loading accordingly.
The script to be used for the conversion is:
--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---
import os
import sys
import osbuild
import osbuild.meta
from osbuild.meta import ModuleInfo
def find_line(lines, start):
for i, l in enumerate(lines):
if l.startswith(start):
return i
return None
def del_block(lines, prefix):
start = find_line(lines, prefix)
end = find_line(lines[start:], '"""')
print(start, end)
del lines[start:start+end+1]
def main():
index = osbuild.meta.Index(os.curdir)
modules = []
for klass in ("Stage", "Assembler"):
mods = index.list_modules_for_class(klass)
modules += [(klass, module) for module in mods]
for m in modules:
print(m)
klass, name = m
info = ModuleInfo.load(os.curdir, klass, name)
module_path = ModuleInfo.module_class_to_directory(klass)
path = os.path.join(os.curdir, module_path, name)
with open(path, "r") as f:
data = list(f.readlines())
i = find_line(data, "STAGE_DESC")
print(i)
del data[i]
del_block(data, "STAGE_INFO")
i = find_line(data, "STAGE_OPTS")
data[i] = 'SCHEMA = """\n'
docstr = '"""\n' + info.desc + "\n" + info.info + '"""\n'
doclst = docstr.split("\n")
doclst = [l + "\n" for l in doclst]
data = [data[0]] + doclst + data[1:]
with open(path, "w") as f:
f.writelines(data)
if __name__ == "__main__":
main()
This commit is contained in:
parent
131d0264a8
commit
2a9cdde5ec
32 changed files with 340 additions and 269 deletions
|
|
@ -1,14 +1,16 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
No-op assembler
|
||||
|
||||
No-op assembler. Produces no output, just prints a JSON dump of its options
|
||||
and then exits.
|
||||
"""
|
||||
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
STAGE_DESC = "No-op assembler"
|
||||
STAGE_INFO = """
|
||||
No-op assembler. Produces no output, just prints a JSON dump of its options
|
||||
and then exits.
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
SCHEMA = """
|
||||
"additionalProperties": false
|
||||
"""
|
||||
def main(_tree, _output_dir, options):
|
||||
|
|
|
|||
|
|
@ -1,18 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Assemble an OCI image archive
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
|
||||
STAGE_DESC = "Assemble an OCI image archive"
|
||||
STAGE_INFO = """
|
||||
Assemble an Open Container Initiative[1] image[2] archive, i.e. a
|
||||
tarball whose contents is in the OCI image layout.
|
||||
|
||||
|
|
@ -30,7 +19,20 @@ podman[3] with `podman pull oci-archive:<archive>`.
|
|||
[2] https://github.com/opencontainers/image-spec/
|
||||
[3] https://podman.io/
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["architecture", "filename"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Assemble a file system tree into a ostree commit
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from osbuild.util import ostree
|
||||
|
||||
|
||||
STAGE_DESC = "Assemble a file system tree into a ostree commit"
|
||||
STAGE_INFO = """
|
||||
Takes a file system tree that is already conforming to the ostree
|
||||
system layout[1] and commits it to an archive repository.
|
||||
|
||||
|
|
@ -26,7 +17,18 @@ in the build root.
|
|||
|
||||
[1] https://ostree.readthedocs.io/en/stable/manual/adapting-existing/
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from osbuild.util import ostree
|
||||
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["ref"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Assemble a bootable partitioned disk image with qemu-img
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from typing import List, BinaryIO
|
||||
import osbuild.remoteloop as remoteloop
|
||||
|
||||
STAGE_DESC = "Assemble a bootable partitioned disk image with qemu-img"
|
||||
STAGE_INFO = """
|
||||
Assemble a bootable partitioned disk image using `qemu-img`.
|
||||
|
||||
Creates a sparse partitioned disk image of type `pttype` of a given `size`,
|
||||
|
|
@ -29,7 +18,20 @@ sparse image into the format requested with the `fmt` option.
|
|||
Buildhost commands used: `truncate`, `mount`, `umount`, `sfdisk`,
|
||||
`grub2-mkimage`, `mkfs.ext4` or `mkfs.xfs`, `qemu-img`.
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from typing import List, BinaryIO
|
||||
import osbuild.remoteloop as remoteloop
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["format", "filename", "ptuuid", "size"],
|
||||
"oneOf": [{
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Assemble tree into a raw filesystem image
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import osbuild.remoteloop as remoteloop
|
||||
|
||||
STAGE_DESC = "Assemble tree into a raw filesystem image"
|
||||
STAGE_INFO = """
|
||||
Assemble the tree into a raw filesystem image named `filename`, with the UUID
|
||||
`root_fs_uuid`.
|
||||
|
||||
|
|
@ -25,7 +18,16 @@ The filesystem UUID should be a standard (RFC4122) UUID, which you can
|
|||
generate with uuid.uuid4() in Python, `uuidgen(1)` in a shell script, or
|
||||
read from `/proc/sys/kernel/random/uuid` if your kernel provides it.
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import osbuild.remoteloop as remoteloop
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["filename", "root_fs_uuid", "size"],
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Assemble a tar archive
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
STAGE_DESC = "Assemble a tar archive"
|
||||
STAGE_INFO = """
|
||||
Assembles the tree into a tar archive named `filename`.
|
||||
|
||||
Uses the buildhost's `tar` command, like: `tar -cf $FILENAME -C $TREE`
|
||||
|
|
@ -21,7 +17,13 @@ caller is responsible for making sure that `compression` and `filename` match.
|
|||
|
||||
Buildhost commands used: `tar` and any named `compression` program.
|
||||
"""
|
||||
STAGE_OPTS = """
|
||||
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
SCHEMA = """
|
||||
"additionalProperties": false,
|
||||
"required": ["filename"],
|
||||
"properties": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue